DEV Community

Dylan Parker
Dylan Parker

Posted on

Automating Google Search Console reporting with Python

I’ve been trying to automate more of my SEO reporting workflow lately, especially repetitive Google Search Console exports. Instead of manually downloading query data every week, I put together a small Python script that pulls top search queries directly from the Search Console API.

Here’s a simplified version:

from datetime import datetime, timedelta
from google.oauth2 import service_account
from googleapiclient.discovery import build

SCOPES = ['https://www.googleapis.com/auth/webmasters.readonly']
SERVICE_ACCOUNT_FILE = 'path/to/service-account.json'

def get_top_queries(site_url, days=30):
credentials = service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE,
scopes=SCOPES
)

service = build('searchconsole', 'v1', credentials=credentials)

request = {
'startDate': (
datetime.now() - timedelta(days=days)
).strftime('%Y-%m-%d'),

'endDate': datetime.now().strftime('%Y-%m-%d'),

'dimensions': ['query'],
'rowLimit': 10
Enter fullscreen mode Exit fullscreen mode

}

response = service.searchanalytics().query(
siteUrl=site_url,
body=request
).execute()

return response.get('rows', [])

Enter fullscreen mode Exit fullscreen mode




Example usage

queries = get_top_queries('https://example.com')

for row in queries:
print(
f"Query: {row['keys'][0]}, "
f"Clicks: {row['clicks']}, "
f"Impressions: {row['impressions']}"
)

This has been useful for:

automated SEO dashboards
weekly reporting
tracking query trends over time
identifying declining pages earlier

Sometimes I also cross-reference GSC data with live SERP tracking tools for comparison, but GSC alone already provides a surprisingly solid base for automation.

Curious what APIs or datasets other developers are using for SEO automation:

Google Search Console?
GA4?
server logs?
SERP APIs?
custom crawlers?

Would love to hear other workflows or reporting setups people are building.

Top comments (2)

Collapse
 
harjjotsinghh profile image
Harjot Singh

Pulling GSC into your own automated reporting is one of the highest-ROI scripts an indie/SEO-minded dev can write, because the GSC UI caps you at 1000 rows and a short retention window, while the API lets you warehouse the full history and slice it however you want. The classic wins: track query/page performance over time past the 16-month limit, catch ranking drops the day they happen instead of when you notice traffic, and join GSC data against your own analytics. Owning the data pipeline instead of living in the dashboard is the unlock.

The angle I'd add, given where search is heading: GSC tells you about classic blue-link clicks, but more and more discovery is happening inside AI answers (ChatGPT, Perplexity, AI Overviews) that GSC doesn't fully capture - so the reporting that matters in 2026 is increasingly "am I cited in AI answers," not just "where do I rank." Worth instrumenting both. That measure-what-actually-drives-outcomes instinct is something I think about a lot building Moonshift, the thing I work on - a multi-agent pipeline that takes a prompt to a deployed SaaS - where being legible to AI (in your case, getting cited; in mine, AI-readable code/context) is the new distribution. Multi-model routing keeps a build ~$3 flat, first run free no card. Nice automation. Are you pulling the full API history into a warehouse, or just scheduled CSV exports? The warehouse route is where the compounding value is.

Collapse
 
micheljee profile image
Michel Jee

Great snippet! I've been using similar GSC automation but never thought to layer in SERP data for deeper insights. How do you handle rate limiting with those API calls when you scale up to multiple sites?