Google Ads Ad Manager API Client Library
This is an official Python client library for interacting with the Google Ad Manager API. It provides a programmatic interface to manage ad campaigns, inventory, and other Ad Manager features. The current version is 0.9.0 and it is part of the broader `googleapis/google-cloud-python` monorepo, which typically sees frequent updates, though this specific client's release cadence appears less frequent.
Warnings
- breaking The Ad Manager API version is embedded directly into the Python import path (e.g., `admanager_v202311`). Upgrading the `google-ads-admanager` library might introduce a newer API version in the import path (e.g., `v202402`), requiring code changes even if the library's own major version (0.x.x) remains the same.
- gotcha This `google-ads-admanager` library is a distinct client for the Google Ad Manager API and should not be confused with the older `googleads-python-lib` (which also supported DFP/Ad Manager). They have different import paths, authentication methods, and underlying API interactions.
- gotcha As a pre-1.0 version (currently 0.9.0), the API stability is not guaranteed. Breaking changes in methods, object structures, or underlying API behavior can occur in minor or patch releases.
- gotcha While this library uses `google-auth` for authentication, connecting to the Ad Manager API typically requires specific OAuth 2.0 scopes (e.g., `https://www.googleapis.com/auth/dfp`) and an Ad Manager network ID. Ensure your service account or user credentials have been properly granted these scopes within Google Ad Manager.
- gotcha The Google Ad Manager API is a SOAP-based API. While this Python library aims to abstract away the XML/SOAP complexity, understanding the underlying SOAP structures (e.g., WSDL definitions) can be helpful for advanced usage, debugging, or when implementing features not directly exposed by the client methods.
Install
-
pip install google-ads-admanager
Imports
- NetworkServiceClient
from google.ads.admanager.services.network_service import NetworkServiceClient
from google.ads.admanager_v202311.services.network_service import NetworkServiceClient
Quickstart
import os
from google.ads.admanager_v202311.services.network_service import NetworkServiceClient
def get_admanager_network_info():
try:
# Authenticate using Application Default Credentials (ADC).
# Ensure GOOGLE_APPLICATION_CREDENTIALS env var is set or gcloud is configured.
# For Ad Manager, ensure your credentials have the necessary Ad Manager scope.
client = NetworkServiceClient()
# Get the current network.
network = client.get_current_network()
print(f"Current Ad Manager Network:")
print(f" Network Code: {network.network_code}")
print(f" Display Name: {network.display_name}")
print(f" Time Zone: {network.time_zone}")
print(f" Primary Ad Exchange Id: {network.primary_ad_exchange_id}")
except Exception as e:
print(f"An error occurred: {e}")
# Consider detailed error handling based on API response codes.
if __name__ == '__main__':
get_admanager_network_info()