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 v18.1.0 of this library. 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
Caveats
There are some caveats. The primary one is that type inference does not work for the get_type
and get_service
methods of Client
. The only exception is get_service("GoogleAdsService")
, which is supported since it's so common. The workaround in other cases is to explicitly state the type. For get_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.v10 import CampaignOperation
campaign_operation: CampaignOperation = client.get_type('CampaignOperation')
# Or this:
from google.ads.googleads.v10 import CampaignOperation
campaign_operation = CampaignOperation()
# Replace this:
campaign_service = client.get_service('CampaignService')
# With this:
from google.ads.googleads.v10 import CampaignServiceClient
campaign_service: CampaignServiceClient = client.get_service('CampaignService')
# But you can keep this:
google_ads_service = client.get_service('GoogleAdsService')
While it is technically possible to type these methods 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. The only overloads included are those necessary to make it work for GoogleAdsService.
Certain types are too lenient compared to what's allowed at runtime. GoogleAdsClient.enums
is typed as Any
and so is the mapping
argument to protobuf message constructors.
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. This might improve in the future, but for now:
# Replace this:
AdGroupAd({"status": "ENABLED", ad={"type": 2}})
# With this:
from google.ads.googleads.v10 import AdGroupAdStatusEnum, AdTypeEnum, Ad
AdGroupAd(status=AdGroupAdStatusEnum.AdGroupAdStatus.ENABLED, ad=Ad(type=AdTypeEnum.AdType.TEXT_AD))
Note that if you're using Mypy you need to use the --namespace-packages
option as google
and google.ads
are namespace packages.
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
Hashes for google_ads_stubs-11.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 113a94e32374360431ec3c92d9210f1ad771d5c4c3a6e5ff1c2ed6157018feb6 |
|
MD5 | ebb29f6b50cbe97da60f22b1f8ad7f20 |
|
BLAKE2b-256 | 0c3e725c4b6273c76cda1aa1368f7b21a6219ad2a442a3dc53e53e82e0bddc38 |