Fetching references to all the various proto classes required to use the API in
Python can be verbose and requires you to have an intrinsic understanding of the
API or frequently context-switch to reference the protos or documentation.

## The client's `get_service` and `get_type` methods

These two getter methods allow you to retrieve any service or type object in the
API. The `get_service` method is used to retrieve service clients. `get_type` is
used for any other object. Service client classes are defined in code under the
version path `google/ads/googleads/v*/services/` and all types are defined under
the various object categories
`google/ads/googleads/v*/common|enums|errors|resources|services/types/`. All
code underneath the version directory is generated, so it's a best practice to
use these methods instead of importing the objects directly, in case the
structure of the codebase changes.

The following example shows how to use the `get_service` method to retrieve an
instance of the [`GoogleAdsService`](https://developers.google.com/google-ads/api/reference/rpc/v26/GoogleAdsService.md.txt) client
(or an asynchronous `GoogleAdsServiceAsyncClient` in `google-ads` `v28.4.0` and
later by passing `is_async=True`):

```python
from google.ads.googleads.client import GoogleAdsClient

# "load_from_storage" loads your API credentials from disk so they
# can be used for service initialization. Providing the optional `version`
# parameter means that the v26 version of GoogleAdsService will
# be returned.
client = GoogleAdsClient.load_from_storage(version="v26")
googleads_service = client.get_service("GoogleAdsService")

# Supported in google-ads v28.4.0 and later: retrieve an async service client.
googleads_async_service = client.get_service("GoogleAdsService", is_async=True)
```

The following example shows how to use the `get_type` method to retrieve a
[`Campaign`](https://developers.google.com/google-ads/api/reference/rpc/v26/Campaign.md.txt) instance:

```python
from google.ads.googleads.client import GoogleAdsClient

client = GoogleAdsClient.load_from_storage(version="v26")
campaign = client.get_type("Campaign")
```

## Enums

While you can use the `get_type` method to retrieve enums, each
`GoogleAdsClient` instance also has an `enums` attribute that dynamically loads
enums using the same mechanism as the `get_type` method. This interface is
simpler and easier to read than using `get_type`:

```python
from google.ads.googleads.client import GoogleAdsClient

client = GoogleAdsClient.load_from_storage(version="v26")

campaign = client.get_type("Campaign")
campaign.status = client.enums.CampaignStatusEnum.PAUSED
```

Proto object fields that are enums are represented in Python by the built-in
[`enum`](https://docs.python.org/3/library/enum.html) type. That means that you can read the value of the member
directly. Working with the `campaign` instance from the previous example in a
Python REPL:

```python
>>> print(campaign.status)
CampaignStatus.PAUSED
>>> type(campaign.status)
<enum 'CampaignStatus'>
>>> print(campaign.status.value)
3
```

Sometimes it's useful to know the name of the field that corresponds to the enum
value. You can access this information using the `name` attribute:

```python
>>> print(campaign.status.name)
'PAUSED'
>>> type(campaign.status.name)
<class 'str'>
```

Interacting with enums is different depending on whether you have the
[`use_proto_plus`](https://developers.google.com/google-ads/api/docs/client-libs/python/protobuf-messages.md.txt#proto-plus-versus-protobuf-messages)
configuration set to `true` or `false`. For details on the two interfaces, see
the [protobuf messages documentation](https://developers.google.com/google-ads/api/docs/client-libs/python/protobuf-messages.md.txt#enums).

## Versioning

Multiple versions of the API are maintained at the same time. While
`v26` is the latest version, earlier versions are still
accessible until they are sunset. The library includes separate proto message
classes that correspond to each active API version. To access a message class
for a specific version, supply the `version` keyword parameter when initializing
a client so that it always returns an instance from that given version:

```python
from google.ads.googleads.client import GoogleAdsClient

client = GoogleAdsClient.load_from_storage(version="v26")
# The Campaign instance will be from the v26 version of the API.
campaign = client.get_type("Campaign")
```

If you don't specify a `version` when initializing the client, you can specify
the version per call when calling the `get_service` and `get_type` methods
(note that if `version` is set when initializing `GoogleAdsClient`, it overrides
any `version` argument passed to `get_service` or `get_type`):

```python
from google.ads.googleads.client import GoogleAdsClient

client = GoogleAdsClient.load_from_storage()
# This loads the v26 version of the GoogleAdsService.
googleads_service = client.get_service(
    "GoogleAdsService", version="v26"
)

# This loads a specific supported API version (such as v23) of a Campaign.
campaign = client.get_type("Campaign", version="v23")
```

If no `version` keyword parameter is provided, the library defaults to the
highest API version supported by your installed `google-ads` package
(`"v26"` in the latest release). Note that minor API releases
(such as `v26.1`) are accessed using their major version string
(`version="v26"`). An updated list of the latest and other
available versions
can be found in the left-hand navigation section of the
[API Reference](https://developers.google.com/google-ads/api/reference/rpc) documentation.