Metadata-Version: 2.1
Name: google-ads-stubs
Version: 15.2.1
Summary: Type stubs for google-ads
Home-page: https://github.com/henribru/google-ads-stubs
License: Apache-2.0
Author: Henrik Bruåsdal
Author-email: henrik.bruasdal@gmail.com
Requires-Python: >=3.7,<3.12
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Typing :: Stubs Only
Requires-Dist: google-ads (>=22.1.0)
Requires-Dist: google-auth-stubs (>=0.1.0)
Requires-Dist: googleapis-common-protos-stubs (>=2.0.0)
Requires-Dist: grpc-stubs (>=1.24.7)
Requires-Dist: proto-plus-stubs (>=0.3.1,<0.4.0)
Requires-Dist: types-protobuf (>=3.18.0)
Requires-Dist: typing-extensions (>=3.10.0)
Project-URL: Repository, https://github.com/henribru/google-ads-stubs
Description-Content-Type: text/markdown

# Type stubs for the Google Ads API Client Library for Python

[![PyPI version](https://badge.fury.io/py/google-ads-stubs.svg)](https://badge.fury.io/py/google-ads-stubs)

This package provides type stubs for the [Google Ads API Client Library for Python](https://github.com/googleads/google-ads-python). 
It's currently compatible with v22.1.0 of this library (v15 of the API). It allows you to type check usage of the library with e.g. [mypy](http://mypy-lang.org/) and will also improve autocomplete in many editors.

**This is in no way affiliated with Google.**

Most stubs were created automatically by [stubgen](https://mypy.readthedocs.io/en/stable/stubgen.html), 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

There are some caveats. The primary one is that 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. 

```python
# Replace this:
campaign_operation = client.get_type('CampaignOperation')
# With this:
from google.ads.googleads.v15 import CampaignOperation
campaign_operation: CampaignOperation = client.get_type('CampaignOperation')
# Or this:
from google.ads.googleads.v15 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 types are too lenient compared to what's allowed at runtime. `GoogleAdsClient.enums` is typed as `Any` and 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.

```python
# Replace this:
AdGroupAd({
    "status": "ENABLED", 
    "ad_strength": client.enums.AdStrengtEnum.GOOD, 
    "ad": {"type": 2},
})
# With this:
from google.ads.googleads.v15 import AdGroupAdStatusEnum, AdStrengtEnum, AdTypeEnum, Ad
AdGroupAd(
    status=AdGroupAdStatusEnum.AdGroupAdStatus.ENABLED, 
    ad_strength=AdStrengtEnum.AdStrengt.GOOD, 
    ad=Ad(type=AdTypeEnum.AdType.TEXT_AD),
)
```

