Skip to main content

Type stubs for the Google Ads API Client Library for Python

PyPI version

This package provides type stubs for the Google Ads API Client Library for Python. It's currently compatible with v31.4.0 of this library (v25.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.v25.services import CampaignOperation
campaign_operation: CampaignOperation = client.get_type('CampaignOperation')
# Or this:
from google.ads.googleads.v25.services 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.v25.resources import Ad
from google.ads.googleads.v25.enums import AdGroupAdStatusEnum, AdTypeEnum
AdGroupAd(
    status=AdGroupAdStatusEnum.AdGroupAdStatus.ENABLED, 
    ad=Ad(type=AdTypeEnum.AdType.TEXT_AD),
)

Development

You can run gen.sh to generate new stubs, but note that there are a few manual steps before and after mentioned in the script.

Feel free to use this to open a PR when new versions come out.

Contributions to automate the remaining manual steps are also welcome.

Release files for google-ads-stubs 27.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for google-ads-stubs 27.1.0
File Size Uploaded
google_ads_stubs-27.1.0.tar.gz 1.8 MB

Built distribution (wheel)

Table of built distributions (wheels) for google-ads-stubs 27.1.0
File Interpreter ABI Platform
google_ads_stubs-27.1.0-py3-none-any.whl Python 3 none any

Total release size:9.5 MB

Release history Release notifications | RSS feed

This release

27.1.0 This release

2 release files

27.0.0

2 release files

26.0.0

2 release files

25.1.0

2 release files

24.0.0

2 release files

23.0.0

2 release files

22.0.0

2 release files

21.0.0

2 release files

20.0.0

2 release files

19.0.0

2 release files

18.1.0

2 release files

18.0.0

2 release files

17.0.0

2 release files

16.2.0

2 release files

16.1.0

2 release files

16.0.0

2 release files

15.2.1

2 release files

15.2.0

2 release files

15.1.0

2 release files

14.1.0

2 release files

14.0.0

2 release files

13.1.0

2 release files

11.0.0

2 release files

10.0.0

2 release files

9.0.0

2 release files

8.1.0

2 release files

8.0.0

2 release files

7.0.0

2 release files

6.0.1

2 release files

6.0.0

2 release files

5.0.1

2 release files

5.0.0

2 release files

4.1.0

2 release files

4.0.1

2 release files

4.0.0

2 release files

3.1.1

2 release files

3.1.0

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page