This is a package you can use to query reporting data from the Google Ads API.
Project description
GoogleAdsQueryTool 
Number of Downloads per month
This is a package you can use to query reporting data from the Google Ads API.
Build status
Requirements
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79d23be84436da1dbf1cce34966fc9fdc9050f3f820ce3d608f0b7685f1c7b44
|
|
| MD5 |
809c9258ca492b7728dfc9fad92b2cfe
|
|
| BLAKE2b-256 |
91dadd9561bb599a438825a377cba25507e6b43a4671208d5af527a1aca6e40f
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b9061bedb7f0247c8e9e17999eda069c1b75e7572eae5dea6c279593edea7b0
|
|
| MD5 |
bfca307729ad1b7099b4fe96ae49601f
|
|
| BLAKE2b-256 |
c973e1e6a2f11999809f059f7a437e0f7b74a30203fdac10380782db89de54fb
|