Why Build a Rank Tracker?
Manual rank checking is slow, error-prone, and impossible to do at scale. A simple Python script that runs daily and logs your positions takes less than 50 lines of code -- and SerpBase makes it affordable enough to run thousands of checks per month for a few dollars.
What You Need
- Python 3.8+
- A SerpBase API key (get 100 free searches at serpbase.dev)
- A list of keywords to track
Install the only dependency:
pip install requests
Step 1: Fetch Rankings for a Keyword
import requests
SERPBASE_KEY = "YOUR_API_KEY"
YOUR_DOMAIN = "yourdomain.com"
def get_rank(keyword: str, domain: str) -> int | None:
response = requests.post(
"https://api.serpbase.dev/google/search",
headers={"X-API-Key": SERPBASE_KEY},
json={"q": keyword, "gl": "us", "hl": "en", "page": 1},
timeout=15,
)
response.raise_for_status()
results = response.json().get("organic", [])
for result in results:
if domain in result.get("link", ""):
return result["position"]
return None # not in top 10
Step 2: Track Multiple Keywords
import csv
import time
from datetime import date
KEYWORDS = [
"serp api",
"google search api",
"rank tracking tool",
"seo monitoring python",
]
def track_all(keywords: list[str], domain: str) -> list[dict]:
rows = []
for kw in keywords:
rank = get_rank(kw, domain)
rows.append({
"date": date.today().isoformat(),
"keyword": kw,
"rank": rank if rank else "not found",
})
print(f"{kw}: {rank}")
time.sleep(0.5) # stay within rate limits
return rows
Step 3: Save Results to CSV
def save_to_csv(rows: list[dict], path: str = "rankings.csv") -> None:
with open(path, "a", newline="") as f:
writer = csv.DictWriter(f, fieldnames=["date", "keyword", "rank"])
if f.tell() == 0:
writer.writeheader()
writer.writerows(rows)
Step 4: Put It All Together
if __name__ == "__main__":
data = track_all(KEYWORDS, YOUR_DOMAIN)
save_to_csv(data)
print(f"Saved {len(data)} keyword rankings to rankings.csv")
Step 5: Automate with Cron
Run daily at 8 AM:
crontab -e
# Add this line:
0 8 * * * /usr/bin/python3 /path/to/rank_tracker.py >> /var/log/rank_tracker.log 2>&1
Cost Estimate
At $0.30 per 1,000 requests:
| Keywords | Frequency | Monthly requests | Monthly cost |
|---|---|---|---|
| 10 | Daily | 300 | $0.09 |
| 100 | Daily | 3,000 | $0.90 |
| 1,000 | Daily | 30,000 | $9.00 |
Rank tracking at scale costs less than a cup of coffee per month.
Next Steps
- Multi-page tracking -- set
page: 2to check positions 11-20 - Location-specific rankings -- use different
glvalues per market - Alerting -- send a Slack or email notification when a ranking drops more than 3 positions
- Dashboard -- pipe results into Google Sheets or a SQLite database for trend visualization
Get your API key at serpbase.dev and start tracking in minutes.
Production Hardening Checklist
A Python rank tracker should keep query settings stable before it tries to scale. Otherwise, the dashboard may report false movement caused by a country, language, device, or parser change.
| Field | Keep it explicit |
|---|---|
| Query | The exact keyword string |
| Country | us, gb, de, or the target market |
| Language | en, es, ja, or the report language |
| Device | desktop or mobile |
| Search type | organic web results |
| Timestamp | Stored in UTC for comparisons |
Store the raw SERP JSON for at least a short audit window. If a ranking changes, the raw response helps explain whether the movement came from a real competitor shift, a local pack, a featured snippet, or a temporary parsing problem.
Related guides: rank tracking API for SEO tools, localized Google SERP API, and SERP feature monitoring.
FAQ
How many keywords should the first tracker monitor? Start with 100 to 500 keywords in one market.
Should users trigger live checks on every dashboard load? Usually no. Scheduled checks plus caching are cheaper and more stable.