• Stars
    star
    678
  • Rank 66,609 (Top 2 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created over 10 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The Python client library for Google's Ads APIs

The googleads Python client library

This client library simplifies accessing Google's SOAP Ads APIs - such as Ad Manager. The library provides easy ways to store your authentication and create SOAP web service clients. It also contains example code to help you get started integrating with our APIs.

Getting started

  1. Download and install the library

    setuptools is a pre-requisite for installing the googleads library

    It is recommended that you install the library and its dependencies from PyPI using pip. This can be accomplished with a single command:

    $ pip install googleads

    As an alternative, you can download the library as a tarball. To start the installation, navigate to the directory that contains your downloaded unzipped client library and run the "setup.py" script as follows:

    $ python setup.py build install

  2. Copy the googleads.yaml file to your home directory.

    This will be used to store credentials and other settings that can be loaded to initialize a client.

  3. Set up your OAuth2 credentials

    The Ad Manager API uses OAuth2 as the authentication

  4. mechanism. Follow the appropriate guide below based on your use case.

    If you're accessing an API using your own credentials...

    If you're accessing an API on behalf of clients...

Where can I find samples?

You can find code examples for the latest versions of Ad Manager on the releases page.

Alternatively, you can find Ad Manager samples in the examples directory of this repository.

Caching authentication information

It is possible to cache your API authentication information. The library includes a sample file showing how to do this named googleads.yaml. Fill in the fields for the API and features you plan to use. The library's LoadFromStorage methods default to looking for a file with this name in your home directory, but you can pass in a path to any file with the correct yaml contents.

# Use the default location - your home directory:
ad_manager_client = ad_manager.AdManagerClient.LoadFromStorage()

# Alternatively, pass in the location of the file:
ad_manager_client = ad_manager.AdManagerClient.LoadFromStorage('C:\My\Directory\googleads.yaml')

Where do I submit bug reports and/or feature requests?

If you have issues directly related to the client library, use the issue tracker.

If you have issues pertaining to a specific API, use the product support forums:

How do I log SOAP interactions?

The library uses Python's built in logging framework. You can specify your configuration via the configuration file; see googleads.yaml for an example.

Alternatively, you can manually specify your logging configuration. For example, if you want to log your SOAP interactions to stdout, and you are using the Zeep soap library, you can do the following:

logging.basicConfig(level=logging.INFO, format=googleads.util.LOGGER_FORMAT)
logging.getLogger('googleads.soap').setLevel(logging.DEBUG)

If you wish to log to a file, you'll need to attach a log handler to this source which is configured to write the output to a file.

How do I disable log filters?

The zeep plugin used for logging strips sensitive data from its output. If you would like this data included in logs, you'll need to implement your own simple logging plugin. For example:

class DangerousZeepLogger(zeep.Plugin):
  def ingress(self, envelope, http_headers, operation):
    logging.debug('Incoming response: \n%s', etree.tostring(envelope, pretty_print=True))
    return envelope, http_headers

  def egress(self, envelope, http_headers, operation, binding_options):
    logging.debug('Incoming response: \n%s', etree.tostring(envelope, pretty_print=True))
    return envelope, http_headers

ad_manager_client.zeep_client.plugins.append(DangerousZeepLogger())

How can I configure or disable caching?

By default, clients are cached because reading and digesting the WSDL can be expensive. However, the default caching method requires permission to access a local file system that may not be available in certain hosting environments such as App Engine.

You can pass an implementation of zeep.cache.Base to the AdManagerClient initializer to modify the default caching behavior.

For example, configuring a different location and duration of the cache file with zeep

doc_cache = zeep.cache.SqliteCache(path=cache_path)
ad_manager_client = ad_manager.AdManagerClient(
  oauth2_client, application_name, network_code=network_code, cache=doc_cache)

You can also disable caching in similar fashion with zeep

ad_manager_client = ad_manager.AdManagerClient(
  oauth2_client, application_name, network_code=network_code,
  cache=googleads.common.ZeepServiceProxy.NO_CACHE)

Requirements

Python Versions

This library only supports Python 3.7+.

External Dependencies:

- httplib2             -- https://pypi.python.org/pypi/httplib2/
- oauth2client         -- https://pypi.python.org/pypi/oauth2client/
- pysocks              -- https://pypi.python.org/pypi/PySocks/
- pytz                 -- https://pypi.python.org/pypi/pytz
- pyYAML               -- https://pypi.python.org/pypi/pyYAML/
- xmltodict            -- https://pypi.python.org/pypi/xmltodict/
- zeep                 -- https://pypi.python.org/pypi/zeep
- mock                 -- https://pypi.python.org/pypi/mock
                          (only needed to run unit tests)
- pyfakefs             -- https://pypi.python.org/pypi/pyfakefs
                          (only needed to run unit tests)

Authors:

Mark Saniscalchi
David Wihl
Ben Karl

More Repositories

1

googleads-mobile-android-examples

googleads-mobile-android
Java
1,693
star
2

googleads-mobile-unity

Official Unity Plugin for the Google Mobile Ads SDK
C#
1,355
star
3

googleads-mobile-ios-examples

googleads-mobile-ios
Objective-C
953
star
4

googleads-php-lib

Google Ad Manager SOAP API Client Library for PHP
PHP
657
star
5

google-ads-python

Google Ads API Client Library for Python
Python
498
star
6

videojs-ima

IMA SDK Plugin for Video.js
JavaScript
449
star
7

googleads-mobile-flutter

A Flutter plugin for the Google Mobile Ads SDK
Java
341
star
8

google-api-ads-ruby

Ad Manager SOAP API Client Libraries for Ruby
Ruby
297
star
9

google-ads-php

Google Ads API Client Library for PHP
PHP
295
star
10

googleads-ima-html5

Samples for the HTML5 IMA SDK.
JavaScript
260
star
11

googleads-mobile-android-mediation

Sample Android project showcasing how to build a mediation adapter or custom event for the Google Mobile Ads SDK.
Java
240
star
12

googleads-java-lib

Google Ad Manager SOAP API Client Library for Java
Java
226
star
13

googleads-shopping-samples

Samples for the Content API for Shopping and the Manufacturer Center API
Java
192
star
14

google-ads-java

Google Ads API Client Library for Java
Java
167
star
15

google-media-framework-android

[DEPRECATED] The Google Media Framework (GMF) is a lightweight media player designed to make video playback and integration with the Google IMA SDK on Android easier.
Java
155
star
16

googleads-adsense-examples

Samples for the AdSense Management API
Java
142
star
17

swift-package-manager-google-mobile-ads

Swift
133
star
18

googleads-mobile-ios-mediation

Objective-C
118
star
19

googleads-mobile-android-native-templates

Java
116
star
20

googleads-ima-android

Samples for the IMA Android SDK.
Java
114
star
21

googleads-dotnet-lib

Google Ad Manager SOAP API .NET client library
C#
108
star
22

googleads-dfa-reporting-samples

Samples for the DoubleClick for Advertisers Reporting and Trafficking API
C#
106
star
23

googleads-consent-sdk-android

Consent SDK
Java
101
star
24

publisher-ads-lighthouse-plugin

Publisher Ads Audits for Lighthouse is a tool to improve ad speed and overall quality through a series of automated audits. This tool will aid in resolving discovered problems, providing a tool to be used to evaluate effectiveness of iterative changes while suggesting actionable feedback.
JavaScript
98
star
25

google-media-framework-ios

The Google Media Framework (GMF) is a lightweight media player designed to make video playback and integration with the Google IMA SDK on iOS easier.
Objective-C
74
star
26

admob-ads-in-flutter

Dart
73
star
27

google-ads-dotnet

This project hosts the .NET client library for the Google Ads API.
C#
72
star
28

google-ads-ruby

Google Ads API Ruby Client Library
Ruby
70
star
29

googleads-ima-ios

Samples for the iOS IMA SDK.
Objective-C
57
star
30

googleads-bidmanager-examples

PHP
42
star
31

googleads-admob-api-samples

googleads-admob-api-samples
Java
40
star
32

admob-inline-ads-in-flutter

Dart
40
star
33

google-publisher-tag-samples

Google Publisher Tag (GPT) code samples.
TypeScript
36
star
34

googleads-adxbuyer-examples

Samples for the DoubleClick Ad Exchange Buyer REST API
C#
34
star
35

googleads-ima-html5-dai

JavaScript
33
star
36

google-ads-doctor

Go
31
star
37

googleads-consent-sdk-ios

Consent SDK
Objective-C
31
star
38

googleads-adxseller-examples

Samples for the DoubleClick Ad Exchange Seller REST API
Java
20
star
39

googleads-ima-roku-dai

Brightscript
15
star
40

google-ads-perl

Google Ads API Client Library for Perl
Perl
15
star
41

googleads-mobile-ios-native-templates

Objective-C
14
star
42

dfp-playground

JavaScript
14
star
43

googleads-ima-tvos-dai

Objective-C
11
star
44

adwords-scripts-linkchecker

App Engine-based link checker for AdWords Scripts and Apps Script
Java
11
star
45

googleads-ima-cast

Samples for the Chromecast IMA SDK
JavaScript
10
star
46

googleads-displayvideo-examples

Display & Video 360 (DV360) API code samples.
Java
10
star
47

angular-dfp

Semantic DoubleClick integration with AngularJS
JavaScript
10
star
48

authorized-buyers-rtb-api-samples

C#
9
star
49

googleads-dynamic-ad-insertion

JavaScript
9
star
50

googleads-dfp-java-dfp-playground

DFP API Playground
Java
9
star
51

googleads-viewability-insights-extension

A DevTools extension for inspecting the viewability of Ad Manager Ads.
JavaScript
9
star
52

app-conversion-solutions

App Conversion Solutions with Google Ads API
Java
8
star
53

google-publisher-tag-types

Automatically generated TypeScript type definitions for the Google Publisher Tag JavaScript API
TypeScript
8
star
54

mobilevsi-android

Java
7
star
55

googleads-ima-android-dai

Java
7
star
56

googleads-dfa-samples

Samples for the DoubleClick for Advertisers API
PHP
7
star
57

googleads-ima-cast-dai

JavaScript
6
star
58

admob-firebase-codelabs-android

Kotlin
6
star
59

googleads-ima-tvos-client-side

Objective-C
6
star
60

googleads-perl-lib

AdWords API Perl Client Library
Perl
5
star
61

googleads-ima-ios-dai

Objective-C
5
star
62

html5-to-dfp

Python
5
star
63

admob-firebase-codelabs-unity

C#
5
star
64

swift-package-manager-google-user-messaging-platform

Swift
5
star
65

googleads-pal-webapp

An app demonstrating PAL SDK
TypeScript
4
star
66

googleads-ima-tizen-dai

JavaScript
4
star
67

gpt-ad

A Polymer element for defining GPT Ads in Polymer apps.
HTML
4
star
68

swift-package-manager-google-programmatic-access-library-ios

Swift
4
star
69

admob-appopen-unity

C#
3
star
70

swift-package-manager-google-interactive-media-ads-tvos

Swift
3
star
71

gpt-light-ad

HTML
3
star
72

swift-package-manager-google-programmatic-access-library-tvos

Swift
2
star
73

authorized-buyers-marketplace-api-samples

C#
2
star
74

swift-package-manager-google-interactive-media-ads-ios

Swift
2
star
75

conf-data-processing-architecture-reference-sample

2
star
76

hbbtv-lshape-demo

JavaScript
2
star
77

googleads-pal

Java
2
star
78

search-campaign-setup-booster

Python
2
star
79

google-publisher-tag-playground

An interactive code playground for Google Publisher Tag (GPT) samples.
TypeScript
2
star
80

comparison-shopping-service-api-samples

Code samples for the Comparison Shopping Service API (CSS API)
Java
1
star
81

.allstar

1
star
82

.github

1
star