DEV Community

Cover image for Build a Minimal SERP Snapshot Script for Keyword Checks
Elowen
Elowen

Posted on

Build a Minimal SERP Snapshot Script for Keyword Checks

If you check the same keyword manually every few days, you will eventually run into the same problem: you cannot reliably compare what changed.

A browser tab gives you a result page.

A snapshot gives you something you can store, diff, review, and discuss with a team.

This post shows a minimal pattern for saving SERP snapshots from a SERP API. The goal is not to build a full SEO platform. The goal is to create a small, repeatable starting point.

What the script should do

For a first version, keep the job narrow:

  • accept a keyword
  • call a SERP API
  • extract the top organic results
  • save the snapshot with a timestamp
  • keep the raw response optional for debugging

That is enough to answer a basic question later:

"What did the search results look like when we checked this keyword?"

A simple snapshot shape

I like to save a normalized object before thinking about dashboards or alerts.

{
  "keyword": "serp api for seo monitoring",
  "checked_at": "2026-07-01T09:00:00Z",
  "results": [
    {
      "position": 1,
      "title": "Example result title",
      "url": "https://example.com/page",
      "snippet": "Short result summary..."
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

The exact fields will depend on the SERP API you use. If you use Talor Data or another SERP API provider, map this shape to the response fields from the provider docs instead of assuming every API returns the same schema.

Minimal Python example

This example is intentionally generic. Replace the endpoint, auth format, parameters, and response field names with the SERP API you use.

import json
import os
from datetime import datetime, timezone

import requests


SERP_API_ENDPOINT = os.environ["SERP_API_ENDPOINT"]
SERP_API_KEY = os.environ["SERP_API_KEY"]


def fetch_serp(keyword: str) -> dict:
    response = requests.get(
        SERP_API_ENDPOINT,
        headers={"Authorization": f"Bearer {SERP_API_KEY}"},
        params={
            "q": keyword,
            "engine": "google",
            "location": "United States",
        },
        timeout=30,
    )
    response.raise_for_status()
    return response.json()


def normalize_results(raw: dict) -> list[dict]:
    # Adjust this path to match your SERP API response schema.
    organic_results = raw.get("organic_results", [])

    normalized = []
    for index, item in enumerate(organic_results[:10], start=1):
        normalized.append(
            {
                "position": item.get("position", index),
                "title": item.get("title"),
                "url": item.get("link") or item.get("url"),
                "snippet": item.get("snippet"),
            }
        )

    return normalized


def save_snapshot(keyword: str, results: list[dict]) -> str:
    checked_at = datetime.now(timezone.utc).isoformat()
    snapshot = {
        "keyword": keyword,
        "checked_at": checked_at,
        "results": results,
    }

    safe_keyword = keyword.lower().replace(" ", "_").replace("/", "_")
    filename = f"serp_snapshot_{safe_keyword}_{checked_at[:10]}.json"

    with open(filename, "w", encoding="utf-8") as file:
        json.dump(snapshot, file, indent=2, ensure_ascii=False)

    return filename


if __name__ == "__main__":
    keyword = "serp api for seo monitoring"
    raw = fetch_serp(keyword)
    results = normalize_results(raw)
    path = save_snapshot(keyword, results)
    print(f"Saved {len(results)} results to {path}")
Enter fullscreen mode Exit fullscreen mode

What to store first

Do not start with every possible field.

Start with the fields you can explain:

  • keyword
  • checked timestamp
  • location or market
  • position
  • title
  • URL
  • snippet
  • result type if your API provides it

Once this is reliable, you can add SERP features, ads, People Also Ask, local packs, or AI search modules depending on your monitoring goals.

Why this is useful

The first benefit is not automation.

The first benefit is repeatability.

When someone asks why traffic changed, you can look back at saved search result snapshots instead of trying to recreate an old SERP from memory.

A SERP API such as Talor Data SERP API can act as the collection layer behind this workflow, while your script owns the parts that are specific to your team: storage, naming, review, and comparison.

Final note

If you already save SERP snapshots, I would be interested in how you structure them. Do you store only normalized fields, or do you keep the raw API response as well?

Top comments (0)