Back to Blog

How to Build a Keyword Rank Tracker in Python Using a SERP API

Build a Python keyword rank tracker with a SERP API. Track positions, monitor competitors, schedule daily checks, and export ranking data.

May 23, 2026
Updated May 30, 2026By SerpBase Team3 min readpython rank trackerserp apirank trackingseo automationpython tutorial

Why Build a Custom Rank Tracker

Off-the-shelf rank trackers charge based on keyword volume, and costs spiral quickly. Building your own with a SERP API gives you full control over keywords, markets, refresh frequency, and budget.

Prerequisites

  • Python 3.8+
  • A SerpBase API key (free 100 searches to start)
  • Basic familiarity with Python and JSON

Step 1: Set Up the Project

mkdir rank-tracker && cd rank-tracker
python -m venv venv
source venv/bin/activate
pip install requests pandas

Step 2: Make Your First API Call

import requests
import json

API_KEY = "your-api-key"
url = "https://api.serpbase.dev/google/search"
headers = {
    "X-API-Key": API_KEY,
    "Content-Type": "application/json"
}

def check_rank(keyword, domain, gl="us", hl="en"):
    payload = {"q": keyword, "gl": gl, "hl": hl}
    resp = requests.post(url, json=payload, headers=headers)
    data = resp.json()

    for result in data.get("organic", []):
        if domain in result.get("link", ""):
            return {
                "keyword": keyword,
                "position": result["position"],
                "title": result["title"],
                "url": result["link"],
                "snippet": result.get("snippet", "")
            }
    return {"keyword": keyword, "position": None}

print(check_rank("python tutorials", "realpython.com"))

Step 3: Track Multiple Keywords

keywords = [
    "python tutorials",
    "learn python",
    "python for beginners",
    "python web framework"
]

domain = "realpython.com"
results = []

for kw in keywords:
    result = check_rank(kw, domain)
    results.append(result)
    print(f"{kw}: position {result['position']}")

import pandas as pd
df = pd.DataFrame(results)
df.to_csv("rankings.csv", index=False)

Step 4: Add Multi-Market Tracking

markets = [
    {"gl": "us", "hl": "en", "name": "US"},
    {"gl": "gb", "hl": "en", "name": "UK"},
    {"gl": "de", "hl": "de", "name": "Germany"},
]

all_results = []
for kw in keywords:
    for market in markets:
        result = check_rank(kw, domain, market["gl"], market["hl"])
        result["market"] = market["name"]
        all_results.append(result)

Step 5: Schedule Daily Checks

# save as schedule_rankings.py
import schedule
import time

def daily_rank_check():
    print("Running daily rank check...")
    # your rank tracking logic here
    results = [check_rank(kw, domain) for kw in keywords]
    df = pd.DataFrame(results)
    df.to_csv(f"rankings_{pd.Timestamp.now().date()}.csv", index=False)
    print("Done!")

schedule.every().day.at("08:00").do(daily_rank_check)

while True:
    schedule.run_pending()
    time.sleep(60)

Step 6: Detect Ranking Changes

def detect_changes(yesterday_file, today_file):
    yesterday = pd.read_csv(yesterday_file)
    today = pd.read_csv(today_file)
    merged = yesterday.merge(today, on="keyword", suffixes=("_prev", "_curr"))

    merged["change"] = merged["position_prev"] - merged["position_curr"]
    winners = merged[merged["change"] > 0].sort_values("change", ascending=False)
    losers = merged[merged["change"] < 0].sort_values("change")

    print("Biggest winners:")
    print(winners[["keyword", "position_prev", "position_curr", "change"]])

    print("Biggest losers:")
    print(losers[["keyword", "position_prev", "position_curr", "change"]])

Cost Analysis

Tracking 500 keywords daily in 3 markets:

  • 500 × 30 × 3 = 45,000 searches/month
  • At SerpBase $0.50/1k = $22.50/month
  • At Serper.dev = $112.50/month
  • At SerpApi = $1,125/month

Next Steps

  • Add email or Slack alerts for ranking drops
  • Build a simple dashboard with Streamlit
  • Track competitor domains alongside your own
  • Export historical data for reporting

Production Hardening Checklist

The first version of a rank tracker can be small, but the production version needs guardrails. The most common failure is mixing different query settings and then treating the results as one clean ranking history.

Keep these fields fixed for every tracked keyword:

FieldExample
Querybest rank tracking api
Countryus
Languageen
LocationUnited States or a city-level location
Devicedesktop or mobile
Search typeorganic web results

Store the full JSON response for a short period, not only the final rank number. When a ranking changes, the raw response lets you verify whether the movement came from a true position change, a SERP feature insertion, a local pack, or a temporary parsing issue.

Useful next reads: rank tracking API for SEO tools, localized Google SERP API, and SERP feature monitoring.

FAQ

How many keywords should a new rank tracker monitor first?

Start with 100 to 500 keywords and one market. That is enough to test scheduling, storage, alerts, and cost before adding more countries or devices.

Should rank tracking use live checks every time a user opens a dashboard?

Usually no. Scheduled collection plus caching is more stable and much cheaper. Live checks should be reserved for manual refreshes or high-priority keywords.