Skip to main content

GoogleAdsQueryTool PyPI Version

Number of Downloads per month

Downloads

This is a package you can use to query reporting data from the Google Ads API.

Build status

Build Status

Requirements

Python Versions

  • Python 3.9+

Installation

pip install googleadsquerytool

Features

  • Distributed via PyPI.
  • Wrapper around the Google Ads API for easy reporting.
  • Returns data in the form of a pandas DataFrame.

Example usage

Before installing the library, you will need a developer token and client customer ID. Instructions on how to obtain them are outlined here. After you have successfully obtained your developer token and have successfully authenticated as per these instructions you need to create a .yaml file (example) and place it in the home directory of your computer or virtual private server.

from googleadsquerytool import create_dict, GoogleAdsDataRetriever

# These represent your SELECT fields for a GAQL query:
fields = ['campaign.name', 'metrics.impressions', 'metrics.cost_micros', 'metrics.clicks']

# This represents the FROM portion of your GAQL query:
resource_name = 'campaign'

# Additional where clauses can be passed but are not mandatory
custom_where_clause = 'campaign.status = "ENABLED" AND campaign.serving_status = "SERVING"'

# Dictionary to append rows into:
ads_data = create_dict(fields)

# Create client object:
client = GoogleAdsDataRetriever(customer_id='Customer_id_that_your_mcc_account_has_access_to')

# Optional: If your Google Ads configuration file is in a custom location or has a custom name:
# client = GoogleAdsDataRetriever(customer_id='Customer_id_that_your_mcc_account_has_access_to', config_path='/path/to/your_config.yaml')

# Make a request to the API:
google_ads_data_df = client.get_data(
   query_fields=ads_data, 
   from_resource_name=resource_name, 
   headers=False, # Pass a list of headers that you would like to have
   start_date='2024-01-01',
   end_date='2024-01-31', 
   where=custom_where_clause, 
   remove_zero_impressions=True)

For some queries, such as those involving campaign labels, start and end dates cannot be specified, nor can zero-impression rows be removed. In these cases, you can leave these fields blank.

Configuration File

By default, the library looks for a Google Ads configuration file named google-ads.yaml in your home directory. If your configuration file is in a different location or has a different name, you can specify the path using the config_path parameter:

# Using a custom configuration file path
client = GoogleAdsDataRetriever(
    customer_id='Customer_id_that_your_mcc_account_has_access_to',
    config_path='/path/to/your_custom_config.yaml'
)
fields = ['campaign.name', 'label.name', 'label.status', 'label.text_label.background_color']

resource_name = 'campaign_label'

label_data = create_dict(fields)

Header_names = ['Campaign', 'Label', 'Label Status', 'Label Color']

label_df = client.get_data(
   query_fields=label_data,
   from_resource_name=resource_name,
   headers=Header_names,
   remove_zero_impressions=False)

Release files for googleadsquerytool 0.1.9

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

Source distribution (sdist)

Source distribution for googleadsquerytool 0.1.9
File Size Uploaded
googleadsquerytool-0.1.9.tar.gz 3.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for googleadsquerytool 0.1.9
File Interpreter ABI Platform
googleadsquerytool-0.1.9-py3-none-any.whl Python 3 none any Details

Total release size: 7.3 kB

Release files / googleadsquerytool-0.1.9.tar.gz

Download URL googleadsquerytool-0.1.9.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
79d23be84436da1dbf1cce34966fc9fdc9050f3f820ce3d608f0b7685f1c7b44
BLAKE2b-256 checksum
How to use checksums
91dadd9561bb599a438825a377cba25507e6b43a4671208d5af527a1aca6e40f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.10.0 Darwin/24.6.0

Release files / googleadsquerytool-0.1.9-py3-none-any.whl

Download URL googleadsquerytool-0.1.9-py3-none-any.whl
Size 3.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7b9061bedb7f0247c8e9e17999eda069c1b75e7572eae5dea6c279593edea7b0
BLAKE2b-256 checksum
How to use checksums
c973e1e6a2f11999809f059f7a437e0f7b74a30203fdac10380782db89de54fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.10.0 Darwin/24.6.0

Release history Release notifications | RSS feed

This release

0.1.9 This release

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

1 release file

0.1.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