SERP Clustering API
Cluster keywords that share ranking URLs by posting a keyword and URL CSV to a small FastAPI service.
#about
Clusters keywords that rank with the same organic URLs and returns the groups as JSON.
Post a CSV with one row per keyword and ranking URL (columns named keyword and url by default) to /cluster-serps, and queries sharing at least common_urls URLs (default 4) are grouped, after blank rows are dropped, duplicates removed and queries lowercased.
Grouping is greedy, so each keyword joins only one cluster and borderline keywords depend on input order.
With no authentication or rate limiting, it belongs on a local machine or behind a proxy with auth.
- Platform
- Python script (requires Python 3.x)
- Input
- CSV with one row per keyword and ranking URL, for example the top 10 results per keyword from the DataForSEO SERP API (columns keyword and url by default)
- Output
- JSON object containing serp_clusters array, total_clusters count, and common_urls_threshold.
- Category
- Keyword Research
Use cases
- Integrating SERP clustering into automated keyword pipelines
- Building internal tools that consume clustering results via API
- Batch processing multiple keyword sets programmatically
#features
- REST API with Swagger UI and ReDoc auto-documentation
- Configurable common_urls threshold (default 4)
- Reads a keyword column and a URL column (keyword and url by default, or set keyword_column and url_column)
- Deduplicates and lowercases queries before clustering
- JSON response with cluster ID, similar_query, queries array, and common URLs list
- Docker and gunicorn deployment examples included
#how-to-use
- Start the server with uvicorn app:app --reload (runs on port 8000)
- POST the CSV to /cluster-serps, adding keyword_column and url_column form fields if your column names differ, and an optional common_urls parameter
- Receive JSON response with clustered keyword groups and shared URLs
#faq
- Where does the input CSV come from and what must it contain?
- Any source that gives one row per keyword and ranking URL, such as the top 10 organic results per keyword from the DataForSEO SERP API (the README includes a short script for its Standard queue, at about $0.0006 per keyword; Live requests currently return many URLs as unresolved google.com/goto links, which breaks URL matching) or a rank tracker export. Only two columns are read: keyword and url by default. If your file uses other names, pass them as the keyword_column and url_column form fields; a missing column returns an HTTP 400 error that lists the columns found. Other columns are ignored, and rows with a blank keyword or URL are dropped.
- Why does a keyword only ever appear in one cluster?
- Clustering is greedy: once a query has been paired into a cluster it is marked processed and excluded from all later comparisons. A keyword whose SERP overlaps several groups joins whichever it is compared against first, so the result is order-dependent and borderline keywords can land in different clusters if you change or reorder the input set.
- How should I choose the common_urls threshold?
- It is the minimum number of identical organic URLs two queries must share to be clustered, defaulting to 4. Matching is on exact URL strings after deduplication, so with top-10 SERPs the default requires roughly 40 percent overlap. Lower it for looser clusters, raise it if unrelated keywords are being merged, and scale it up if your export contains more than 10 results per query.
- Will it handle very large keyword sets?
- The algorithm compares every query against every other query in memory, so runtime grows quadratically with the number of unique queries. Small and mid-sized exports return quickly; for very large sets expect the request to take noticeably longer rather than fail.
- Is the API safe to expose publicly?
- There is no authentication, rate limiting or file size restriction built in; anyone who can reach the endpoint can upload CSVs. Run it locally, behind a reverse proxy with auth, or on a private network. The README includes Docker and gunicorn examples for deployment.
/contact
Want me to run this for you? I run this tool as a managed service, or build something custom around your data. You get the insights without touching the code.