Google Ads API Client Library for Python
This project hosts the Python client library for the Google Ads API.
Features
Distributed via PyPI.
Easy management of credentials.
Easy creation of Google Ads API service clients.
Requirements
Python 2.7.13+ / 3.5.3+
Getting started
Installation
This library is distributed via PyPI. If you have not already done so, install pip, the following command to install this client library:
pip install google-ads
Configuration file setup
To authenticate your API calls, you must specify your client ID, client secret, refresh token, developer token, and, if you are authenticating with a manager account, a login customer id. If you have not yet created a client ID, see the Authorization guide and the authentication samples to get started. Likewise, see Obtain your developer token if you do not yet have one.
When initializing a GoogleAdsClient instance via the load_from_storage class method, the default behavior is to load a configuration file named google-ads.yaml located in your home directory. Included in this repository is a template you can use.
Create a GoogleAdsClient
You can run the following to retrieve a GoogleAdsClient instance using a configuration file named google-ads.yaml stored in your home directory:
client = google.ads.google_ads.client.GoogleAdsClient.load_from_storage()
Get types and service clients
You can use a GoogleAdsClient instance to retrieve any type or service used by the API. To retrieve a type such as a CampaignOperation, provide its name to the get_type method:
campaign_operation = client.get_type('CampaignOperation')
Likewise, you can provide the name of a service to get_service in order to retrieve the corresponding service client instance:
google_ads_service = client.get_service('GoogleAdsService')
API versioning
With the release of Google Ads API v1_0 it’s now possible to specify an API version when getting services and types. The get_service and get_type client methods accept a second named parameter, version that refers to a valid API version. For example, to request an instance of the GoogleAdsService that uses Google Ads API version v0 use the following:
google_ads_service = client.get_service('GoogleAdsService', version='v0')
The currently available list of versions is:
'v0'
'v1'
Enabling and Configuring logging
The library uses Python’s built in logging framework. You can specify your configuration via the configuration file; see google-ads.yaml for an example. The library logs to stderr by default. You can easily pipe log messages to a file; when running an example:
python example.py args 2> example.log
It’s also possible to configure logging programmatically using Python’s built-in logging library by setting a logging configuration before initializing the client. You can retrieve the client logger instance and configure it with the following example:
logging.basicConfig(level=logging.INFO, format='[%(asctime)s - %(levelname)s] %(message).5000s')
logging.getLogger('google.ads.google_ads.client').setLevel(logging.INFO)
NOTE: The client logger is configured when the client is initialized, so if you have logger configurations in your google-ads.yaml file and you want to override them programmatically, you will need to call the above lines _before_ initializing the client, otherwise the configuration from yaml will take precedent as it’s provided first.
The client generates logs at a few different levels and you can set your configuration to see some or all of the below:
Level |
Successful Request |
Failed Request |
|---|---|---|
DEBUG |
A detailed log with complete request and response objects as JSON. |
None |
INFO |
A concise summary with specific request and response fields. |
A detailed log with complete request and exception objects as JSON. |
WARNING |
None |
A concise summary with specific request information, the exception state and message. |
Since the Python logging framework ignores log messages that are less severe than the configured level, setting to WARNING means you will only see concise messages related to failed requests, but setting to DEBUG means you will see all possible types of logs in the above table.
Miscellaneous
Metadata
Release files for google-ads 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| google-ads-1.2.0.tar.gz | 1.2 MB | Without provenance | Details for google-ads-1.2.0.tar.gz |
Release files / google-ads-1.2.0.tar.gz
| Download URL | google-ads-1.2.0.tar.gz |
|---|---|
| Size | 1.2 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
33c388a031dcf44594ed724f8f833f0a34e605efe3ef999eaa60011d2c221fa4
|
|
BLAKE2b-256 checksum How to use checksums |
7992d396efeee8fb52e920b0361ecf555ce1c2d57780ba41f3f2caed0f1ec28b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.13
|
Security for google-ads 1.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.