A Google Colab script that connects to the Google Search Console API and exports all queries and their ranking pages into CSV files — including clicks, impressions, CTR, and position.
- Authenticates with Google via OAuth (no service account or owner access required)
- Pulls up to 16 months of Search Console data
- Exports every query + page combination with the following metrics:
- Query
- Page URL
- Clicks
- Impressions
- CTR (%)
- Average Position
- Saves data in batches of 10,000 rows per CSV file to avoid timeouts
- Auto-downloads all CSV files to your computer when complete
- A Google account with access to a Search Console property (owner, full, or restricted access)
- A Google Cloud project with the Search Console API enabled
- OAuth 2.0 credentials (Desktop App type)
- Go to Google Cloud Console
- Select or create a project
- Navigate to APIs & Services → Enabled APIs & Services
- Search for Google Search Console API and click Enable
- In Google Cloud Console, go to APIs & Services → OAuth consent screen
- Select External and click Create
- Fill in App name, User support email, and Developer contact email
- Click Save and Continue through all remaining screens
- Go to APIs & Services → Credentials
- Click + Create Credentials → OAuth Client ID
- Choose Desktop App as the application type
- Give it a name (e.g.
GSC Colab Export) and click Create
- Copy your Client ID and Client Secret from the popup
Open the script in Google Colab and update the following fields:
# Step 3 — paste your credentials here
CLIENT_CONFIG = {
"installed": {
"client_id": "YOUR_CLIENT_ID.apps.googleusercontent.com", # ← replace
"client_secret": "YOUR_CLIENT_SECRET", # ← replace
...
}
}# Step 6 — set your Search Console property URL
SITE_URL = "https://www.example.com/" # ← replace with your exact GSC property URLTip: Run Step 5 first — it prints all GSC properties your account can access so you can copy the exact URL.
When you run Step 4, the script will print an authorization URL.
- Open the URL in your browser
- Sign in with the Google account that has Search Console access
- Click Allow on the permissions screen
- Copy the authorization code and paste it back into the Colab input box
Run all remaining cells. The script will:
- Print all accessible Search Console properties
- Begin fetching data in batches of 2,500 rows per API request
- Save a new CSV file every 10,000 rows
- Auto-download all CSV files when complete
Note: Large sites with many queries can take a long time to export. The script handles timeouts automatically with retry logic, backing off between attempts.
If the script times out or you stop it manually, any CSV files already saved can still be downloaded. Run this in a new Colab cell:
import os
from google.colab import files
saved = sorted([f for f in os.listdir(".") if f.startswith("search_console_export")])
print(f"Found {len(saved)} file(s):")
for f in saved:
size = os.path.getsize(f) / 1024
print(f" {f} ({size:,.0f} KB)")
for f in saved:
files.download(f)
⚠️ Files are lost if the Colab runtime resets. Download them before closing your session.
| Variable | Default | Description |
|---|---|---|
API_BATCH_SIZE |
2500 |
Rows fetched per API request. Lower this if you experience timeouts. |
CSV_BATCH_SIZE |
10000 |
Rows per CSV file |
MAX_RETRIES |
5 |
Number of retry attempts on timeout |
RETRY_DELAY |
15 |
Base seconds to wait between retries (increases with each attempt) |
REQUEST_TIMEOUT |
90 |
Seconds before a request times out |
CSV files are named sequentially:
search_console_export_part1.csv
search_console_export_part2.csv
...
Each file contains the following columns:
| Column | Description |
|---|---|
| Query | The search query |
| Page | The ranking page URL |
| Clicks | Total clicks in the date range |
| Impressions | Total impressions in the date range |
| CTR | Click-through rate (%) |
| Position | Average ranking position |
- The Search Console API returns data with a ~3 day lag, so the export ends 3 days before today
- The API only returns the top 1,000 rows per unique query/page combination
- Data covers the last 16 months (the maximum Search Console retains)
- This script uses OAuth user authentication — no service account or property owner access is required