Skip to main content

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

Project description

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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

googleadsquerytool-0.1.9.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

googleadsquerytool-0.1.9-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file googleadsquerytool-0.1.9.tar.gz.

File metadata

  • Download URL: googleadsquerytool-0.1.9.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.10.0 Darwin/24.6.0

File hashes

Hashes for googleadsquerytool-0.1.9.tar.gz
Algorithm Hash digest
SHA256 79d23be84436da1dbf1cce34966fc9fdc9050f3f820ce3d608f0b7685f1c7b44
MD5 809c9258ca492b7728dfc9fad92b2cfe
BLAKE2b-256 91dadd9561bb599a438825a377cba25507e6b43a4671208d5af527a1aca6e40f

See more details on using hashes here.

File details

Details for the file googleadsquerytool-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: googleadsquerytool-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.10.0 Darwin/24.6.0

File hashes

Hashes for googleadsquerytool-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 7b9061bedb7f0247c8e9e17999eda069c1b75e7572eae5dea6c279593edea7b0
MD5 bfca307729ad1b7099b4fe96ae49601f
BLAKE2b-256 c973e1e6a2f11999809f059f7a437e0f7b74a30203fdac10380782db89de54fb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page