ETL module for Google Ads API data extraction and transformation
Project description
Google Ads Driver
A Python ETL driver for Google Ads API data extraction and transformation. Simplifies the process of extracting Google Ads data and converting it to pandas DataFrames.
Features
- Simple API: Easy-to-use interface for Google Ads data extraction
- Multiple Report Types: Pre-configured report models for common use cases
- Custom Reports: Create custom report configurations
- Robust Error Handling: Comprehensive error handling with retry logic
- Pandas Integration: Direct output to pandas DataFrames
- Type Hints: Full type hint support for better IDE experience
Installation
pip install google-ads-drv
Quick Start
1. Set up credentials
Create a secrets/google-ads.yaml file with your Google Ads API credentials:
developer_token: "YOUR_DEVELOPER_TOKEN"
client_id: "YOUR_CLIENT_ID"
client_secret: "YOUR_CLIENT_SECRET"
refresh_token: "YOUR_REFRESH_TOKEN"
2. Basic usage
from datetime import date, timedelta
from google_ads_reports import GAdsReport, GAdsReportModel, load_credentials
# Load credentials
credentials = load_credentials()
client = GAdsReport(credentials)
# Configure report parameters
customer_id = "1234567890"
start_date = date.today() - timedelta(days=7)
end_date = date.today() - timedelta(days=1)
# Extract report data
df = client.get_gads_report(
customer_id=customer_id,
report_model=GAdsReportModel.keyword_report,
start_date=start_date,
end_date=end_date
)
# Save to CSV
df.to_csv("keyword_report.csv", index=False)
Available Report Models
GAdsReportModel.adgroup_ad_report- Ad group ad performanceGAdsReportModel.keyword_report- Keyword performanceGAdsReportModel.search_terms_report- Search terms analysisGAdsReportModel.conversions_report- Conversion trackingGAdsReportModel.video_report- Video ad performanceGAdsReportModel.assetgroup_report- Asset group performance
Custom Reports
Create custom report configurations:
from google_ads_reports import create_custom_report
custom_report = create_custom_report(
report_name="campaign_performance",
select=[
"campaign.name",
"campaign.status",
"segments.date",
"metrics.impressions",
"metrics.clicks",
"metrics.cost_micros"
],
from_table="campaign",
where="metrics.impressions > 100"
)
df = client.get_gads_report(customer_id, custom_report, start_date, end_date)
Error Handling
The package provides specific exception types for different scenarios:
from google_ads_reports import (
GAdsReport,
AuthenticationError,
ValidationError,
APIError,
DataProcessingError,
ConfigurationError
)
try:
df = client.get_gads_report(customer_id, report_model, start_date, end_date)
except AuthenticationError:
# Handle credential issues
pass
except ValidationError:
# Handle input validation errors
pass
except APIError:
# Handle API errors (after retries)
pass
Examples
Check the examples/ directory for comprehensive usage examples:
basic_usage.py- Simple report extractionmultiple_reports.py- Batch report processingcustom_reports.py- Custom report creationerror_handling.py- Error handling patterns
Configuration
Retry Settings
API calls automatically retry on transient errors with configurable settings:
- Max attempts: 3 (default)
- Base delay: 1 second
- Backoff factor: 2x exponential
- Max delay: 30 seconds
Logging
Configure logging level:
from google_ads_reports import setup_logging
import logging
setup_logging(level=logging.DEBUG) # Enable debug logging
Requirements
- Python 3.9+
- pandas >= 2.0.0
- google-ads >= 24.0.0
- PyYAML >= 6.0.0
Development
For development installation:
git clone https://github.com/your-username/google-ads-drv
cd google-ads-drv
pip install -e ".[dev]"
License
MIT License. See LICENSE file for details.
Support
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
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 google_ads_reports-1.0.tar.gz.
File metadata
- Download URL: google_ads_reports-1.0.tar.gz
- Upload date:
- Size: 13.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.3 Linux/5.15.167.4-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f914056fad98a58baec3d1268cff4f0f85ca189e0c8a06f721487035c3a7664
|
|
| MD5 |
9feaddc57b18c5ef60190e08ac958df2
|
|
| BLAKE2b-256 |
6126524551ef4710a241a82c7ead532acd165a975841f5fa45c947bc7af34f02
|
File details
Details for the file google_ads_reports-1.0-py3-none-any.whl.
File metadata
- Download URL: google_ads_reports-1.0-py3-none-any.whl
- Upload date:
- Size: 14.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.3 Linux/5.15.167.4-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96666e67d74c9fd10fc00d5bfbd67332d11d4336528352e2b3a3f795606b93ad
|
|
| MD5 |
52f0198faef8c7ed5b417c233c011d4a
|
|
| BLAKE2b-256 |
267fa64a6b04be51a0a52260661e02ef3b8434597f9c7a0113429ad2e0ea5811
|