Keyword Research with Google Related Searches and People Also Ask (Python)
One Google search returns two free keyword lists, related searches and People also ask. A Python script follows both two levels deep, removes duplicates, caps API calls and exports a CSV.
One Google search for "coffee grinder" hands you two lists of keyword ideas for free, and each idea in them can be searched to produce two more lists. Most people read the "People also ask" box and never look at the related searches below it, or the other way round. This guide builds a Python script that starts from a few seeds, follows both lists two levels deep, removes duplicates, stops at a call budget you set and exports everything to a CSV.

What you need
- Python 3.9 or newer and
requests(pip install requests). - A JustSERP API key. Sign up and copy it from your dashboard.
export JUSTSERP_API_KEY="your-key-here"Run the script from a terminal or a server, not from browser code, so the key stays private.
Two fields, two kinds of idea
Every response can contain two lists of plain strings. Both are only present when Google showed them, so default to an empty list.
related_searchholds related searches: close variations and neighbours of your keyword, such as "best burr coffee grinder". Note the singular name.related_questionsholds the "People also ask" questions, such as "What is the best grinder for espresso?". These are natural blog and FAQ topics. You get the question text only, not Google's answers, so the writing is up to you.
Both lists come from an unfiltered, non-personalised results page (we always send filter=0 and pws=0), so your own search history does not bend the suggestions.
How the expansion works
This is a breadth-first search. Level 0 is your seeds. Searching a seed gives level 1 keywords. Searching those gives level 2. We stop there, because each level multiplies the number of searches.

Two safeguards keep it under control. A set of already seen keywords prevents duplicates and loops, and a budget counter stops the run when it reaches your limit. The math shows why the budget matters: 3 seeds with 8 related searches each means 24 level 1 keywords, and searching all of them is 24 more calls. Level 2 is collected but not searched, so depth 2 costs the seeds plus one search per level 1 keyword.
The search helper
The timeout is 90 seconds. Most searches finish in a few seconds, but when Google pushes back we retry before giving up, and a client that hangs up at 30 seconds still has the call counted without getting an answer.
import os
import requests
API_URL = "https://api.justserp.com/v1/search"
API_KEY = os.environ["JUSTSERP_API_KEY"]
def search(keyword, **options):
response = requests.post(
API_URL,
headers={"X-API-Key": API_KEY},
json={"keyword": keyword, **options},
timeout=90,
)
response.raise_for_status()
return response.json()
def suggestions(data):
"""Return (text, kind) pairs from one response."""
found = [(text, "related_search") for text in data.get("related_search") or []]
found += [(text, "question") for text in data.get("related_questions") or []]
return found
The expansion loop

The loop below keeps a queue of keywords to search. Each keyword remembers its depth and the keyword it came from, so the CSV can show where an idea originated. The call counter only counts successful requests, which are the ones that use a call. A 400 or 500 is not charged, so skipping those and moving on costs nothing.
from collections import deque
MAX_DEPTH = 2
MAX_CALLS = 40 # hard budget: never make more than this many successful searches
def normalize(text):
return " ".join(text.lower().split())
def expand(seeds, **options):
seen = {} # normalized keyword -> row
queue = deque()
calls = 0
for seed in seeds:
key = normalize(seed)
if key not in seen:
seen[key] = {"keyword": seed, "depth": 0, "source": "", "kind": "seed"}
queue.append(key)
while queue and calls < MAX_CALLS:
key = queue.popleft()
row = seen[key]
if row["depth"] >= MAX_DEPTH:
continue # collected, but not searched further
try:
data = search(row["keyword"], **options)
except requests.RequestException as err:
print(f"skipped {row['keyword']!r}: {err}")
continue
calls += 1
for text, kind in suggestions(data):
new_key = normalize(text)
if new_key in seen:
continue
seen[new_key] = {
"keyword": text,
"depth": row["depth"] + 1,
"source": row["keyword"],
"kind": kind,
}
queue.append(new_key)
print(f"{calls} API calls, {len(seen)} unique keywords")
return list(seen.values())
Because the queue is first in, first out, every level 0 keyword is searched before any level 1 keyword, so a small budget still covers all your seeds. Keywords at MAX_DEPTH are kept in the results but never searched, which is why depth 2 does not need a second round of calls.
Exporting to CSV
import csv
def export(rows, path="keyword_ideas.csv"):
rows = sorted(rows, key=lambda r: (r["depth"], r["keyword"]))
with open(path, "w", newline="", encoding="utf-8") as handle:
writer = csv.DictWriter(handle, fieldnames=["keyword", "depth", "kind", "source"])
writer.writeheader()
writer.writerows(rows)
print(f"Wrote {len(rows)} rows to {path}")
if __name__ == "__main__":
ideas = expand(["coffee grinder", "espresso machine"], country="United States")
export(ideas)
Open the CSV in a spreadsheet and filter by kind. Rows marked question make good article titles and FAQ entries. Rows marked related_search are close keyword variants you may want to target or group.
Making it fit your market
The extra options flow straight into every request. Pass country="Germany", language="German" to research another market, or device="mobile" to see what phone searchers get. Both take full English names. Codes such as "DE" or "UK" are not recognised, and an unknown name quietly falls back to United States and English while still using a call. If a German run comes back in English, look at meta.googleURL in a response to see what was requested.
Suggestions can differ between markets and devices, so run one expansion per market and keep separate files. The source column in the CSV then lets you trace any idea back to the seed that produced it, which is handy when you decide which topics deserve their own pages. For city-level ideas, add a location in Google's "City,Region,Country" form. It is not validated, so a misspelling gives you ordinary non-local suggestions instead of an error.
Cleaning and grouping the list
Raw suggestions contain near-duplicates and phrases that do not fit your site. Two cheap filters help before you read the list. First, drop anything that does not contain at least one of your core words. Second, group questions by their opening word, so you can see at a glance how many "how", "what" and "why" questions you found:
from collections import Counter
CORE_WORDS = {"coffee", "espresso", "grinder"}
def relevant(rows):
return [r for r in rows if CORE_WORDS & set(normalize(r["keyword"]).split())]
def question_openers(rows):
openers = Counter(
normalize(r["keyword"]).split()[0] for r in rows if r["kind"] == "question"
)
return openers.most_common()
Call relevant(ideas) before export to keep only on-topic rows, and print question_openers(ideas) to see which question types dominate. A topic with many "how to" questions suits a tutorial, while one full of "what is" questions suits an explainer.
Going faster
The loop above is sequential, so 40 calls take around two minutes when each search takes a few seconds, and longer if a query is slow. To speed it up, search a whole level in parallel with a ThreadPoolExecutor and keep it to 10 workers or fewer, the number of requests the Free and Personal plans allow at once. Keep the budget check on the main thread so parallel workers cannot overshoot it.
Habits that stretch your budget
- Start with a small budget such as 20 calls, look at the output, then raise it.
- Use specific seeds. "espresso machine" gives more focused ideas than "coffee".
- Do not trust one run for volume. This gives ideas, not search volume. Check promising keywords in your usual volume tool.
- Cache your CSV. Every search is a fresh fetch from Google, so repeating a search repeats the call. Save results and rerun only when you need fresh ideas.
- Keep the key in an environment variable, never in the script.
Next steps
You now have a repeatable way to turn a handful of seeds into a keyword list. Create a free account for 2,000 free requests, no credit card needed, and see the pricing when you need more. For more request options, read the Python guide to the JustSERP API.