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
}
response = service.searchanalytics().query(
siteUrl=site_url,
body=request
).execute()
return response.get('rows', [])
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 (0)