Type stubs for google-ads
Project description
Type stubs for the Google Ads API Client Library for Python
This package provides type stubs for the Google Ads API Client Library for Python. It's currently compatible with v25.0.0 of this library (v17.1 of the API). It allows you to type check usage of the library with e.g. mypy and will also improve autocomplete in many editors.
This is in no way affiliated with Google.
Most stubs were created automatically by stubgen, the rest are handwritten or generated by self-made scripts.
If you find incorrect annotations, please create an issue. Contributions for fixes are also welcome.
Installation
$ pip install google-ads-stubs
The stubs should be automatically picked up by your editor or typechecker, but note that if you're using Mypy you need to use the --namespace-packages
option as google
and google.ads
are namespace packages.
Caveats
The stubs assume the client is constructed with use_proto_plus=True
. If you use use_proto_plus=False
, they are unlikely to be of much use to you.
Type inference does not work for the get_type
method of GoogleAdsClient
.The workaround is to explicitly state the type. You can also instantiate the object directly to get inference.
# Replace this:
campaign_operation = client.get_type('CampaignOperation')
# With this:
from google.ads.googleads.v17 import CampaignOperation
campaign_operation: CampaignOperation = client.get_type('CampaignOperation')
# Or this:
from google.ads.googleads.v17 import CampaignOperation
campaign_operation = CampaignOperation()
While it is technically possible to type this method using a combination of overloading and literal types, this is not included in these stubs. The reason is that it requires about 10,000 overloads, which makes most typecheckers fairly slow.
Certain parts of the stubs assume you are using the latest included API version. This includes GoogleAdsClient.enums
and calls to GoogleAdsClient.get_type
and GoogleAdsClient.get_service
without specifying the version
argument. If you use an older version, you should import enums directly and specify version
in these calls even if you specified it when constructing the client.
Certain types are too lenient compared to what's allowed at runtime. The first argument to protobuf message constructors accepts any mapping. On the other hand certain types are more strict than what's allowed at runtime. You can't substitute a protobuf message for an equivalent dict or an enum with it's equivalent name or value.
# Replace this:
AdGroupAd({
"status": "ENABLED",
"ad": {"type": 2},
})
# With this:
from google.ads.googleads.v17 import AdGroupAdStatusEnum, AdStrengtEnum, AdTypeEnum, Ad
AdGroupAd(
status=AdGroupAdStatusEnum.AdGroupAdStatus.ENABLED,
ad=Ad(type=AdTypeEnum.AdType.TEXT_AD),
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file google_ads_stubs-19.0.0.tar.gz
.
File metadata
- Download URL: google_ads_stubs-19.0.0.tar.gz
- Upload date:
- Size: 601.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7c0196e7428e6196fa188ab351e01e22e018ed3313259ec1c18c3a6d6ac9bc6 |
|
MD5 | 0fd823383b365b7decc144d505f3062f |
|
BLAKE2b-256 | 988dab60e91f75da5af69c8a30d4f5275729f90c487135707e601ddf7b547893 |
File details
Details for the file google_ads_stubs-19.0.0-py3-none-any.whl
.
File metadata
- Download URL: google_ads_stubs-19.0.0-py3-none-any.whl
- Upload date:
- Size: 2.3 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9873798b99295e37148a2c6412c7bb3042db721a158393625b7dbe3516dc2dc7 |
|
MD5 | b4b2c6203e31365ed6fff7dc67a60e93 |
|
BLAKE2b-256 | 5a3788c3ae550f662fca616ca15fc175a1229136ce3351487bff7faa6a4f7294 |