Package: pyaw-reporting
Google Ads Reporting in PythonAnAdWords APIlarge scale reporting tool written in
Python. Reports are downloaded as plaintext files but connectivity with a database engine such as MySQL, PostgreSQL, or
MongoDB can be implementedupon request.Overviewpyaw-reportingis an open-source Python package suitable for large scale
Google Ads reports. Output reports are comma-separated values (CSV) plaintext files. By default, the package uses 10
threads to download reports simultaneously from different accounts. The number of threads used can be modified using
the-nparameter. It has been successfully tested using +100 threads making it useful for heavy load AdWords Manager
Accounts.Supported AdWords API versionThe latest API version supported by this package isv201809withgoogleads 28.0.0. Older versions of the API are not supported, nor the newerGoogle Ads API.Quick StartPrerequisitesYou will need Python 3.6+; this package installsgoogleadsas a dependency.
Note that that support for Python 2.7ended in 2019. Using a
virtual environment is recommended to avoid running the package withsudo.An access tokenYAML filewith the corresponding AdWords credentials is also necessary. By
default, the package will look for~/googleads.yamlunless a different path is passed. The optional parameterclient_customer_idmust be included in thisYAMLfile, you should enter yourAdWords Manager Account id(formerly known asMCC id). This way, all accounts linked to the Manager Account will be retrieved. The sample fileexample.yamlshows how your token should look like.AWQLqueries could be either passed in the command line
with the-a/--awqlparameter or stored in a plaintext file and passed via the-q/--queryparameter. The module
includes asample querywhich will retrieve clicks and impressions per ad for the last 7 days.
Refer toReport TypesandThe AdWords Query Language (AWQL)for more information
about these queries.Installation$pipinstallpyaw-reportingUsageCommand lineusage: awreporting [-h] (-a AWQL | -q QUERY_FILE) [-t TOKEN] [-o OUTPUT]
                   [-n NUM_THREAD] [-v]

AwReporting - Large scale AdWords reporting tool in Python

optional arguments:
  -h, --help                              show this help message and exit
  -t TOKEN, --token TOKEN                 specify AdWords YAML token path
  -o OUTPUT, --output OUTPUT              define output file name
  -n NUM_THREAD, --num-thread NUM_THREAD  set number of threads
  -v, --verbose                           display activity

required arguments:
  -a AWQL, --awql AWQL                    pass AWQL query
  -q QUERY_FILE, --query-file QUERY_FILE  ...or use a query fileFor example:$awreporting-texample.yaml-a\"SELECT ExternalCustomerId, CampaignId, AdGroupId, Id, Date, Clicks, Impressions \FROM AD_PERFORMANCE_REPORT WHERE Impressions > 0 DURING LAST_7_DAYS"\-oadperformance.csv-n100Or, with a query file:$awreporting-texample.yaml-qquery.txt-oadperformance.csv-n100If you experience problems downloading reports, check the resulting logs inawreporting.logor use the-v/--verboseparameter to verify if something is wrong with your token orAWQLquery.CodeIf you prefer embedding this package in your own code, you could do like so:fromawreportingimportget_reportquery=("SELECT ExternalCustomerId, CampaignId, AdGroupId, Id, Date, Clicks, Impressions ""FROM AD_PERFORMANCE_REPORT ""WHERE Impressions > 0 ""DURING LAST_7_DAYS")get_report('example.yaml',query,'adperformance.csv',100)About the YAML tokenThe example token file providedexample.yamlis not valid. Refer tothis guideif you are using the AdWords API for
the first time.DisclaimerThis is neither an officialAdWords APIrepository nor a clone ofAwReporting. Consider usingAwReportingif you are a Java developer. This framework no longer supports
Python 2.7; only Python 3.6 or greater are compatible sincegoogleadsrequires it.TroubleshootingWe recommend that you try the app with a few number of threads first (the default is 10) and increase the amount
accordingly. The Google Ads server may complain when many API calls are made at the same time, but those exceptions are
handled by the app. We have successfully generated huge report files using 200 threads.When using this tool it might be necessary to enable a DNS cache in your system, such asnscd. This should eliminate DNS lookup problems when repeatedly
calling the AdWords API server. For example, if you find
manyURLError: <urlopen error [Errno -2] Name or service not known>in your logs, enable the DNS cache.In some Linux systemsnscdis not enabled by default, but it can be started with:# systemctl start nscdUseful linkshttps://developers.google.com/adwords/api/https://github.com/googleads/googleads-python-libhttps://github.com/googleads/aw-reporting