DEV Community

Cover image for How to get Google Trends data in Python without 429 errors
fguiraud · Data Tools
fguiraud · Data Tools

Posted on AI-assisted

How to get Google Trends data in Python without 429 errors

Google Trends is one of the best free signals for market research, SEO and content planning: is interest in a product growing, in which country, and what are people starting to search for? The problem is getting that data into Python reliably.

There is no official API. Unofficial libraries call the same endpoints the website uses, and Google answers bursts of requests with HTTP 429 (Too Many Requests). On a laptop you retry and wait; in a scheduled job or a data pipeline, a 429 means a failed run.

In this post I'll show a way to get the data with a few lines of Python, where the retries and IP rotation happen on the server side.

Disclosure: I built the tool used here, a Google Trends Scraper on Apify. It is pay-per-use ($0.002 per search term); Apify's free plan includes monthly credits, enough for everything in this post.

Setup

pip install apify-client
export APIFY_TOKEN=your_token   # Apify Console → Settings → API & Integrations
Enter fullscreen mode Exit fullscreen mode

Compare terms and see which one is growing

import os
from apify_client import ApifyClient

client = ApifyClient(os.environ["APIFY_TOKEN"])
run = client.actor("fguiraud/google-trends-scraper").call(run_input={
    "searchTerms": ["chatgpt, gemini, claude"],  # one line = one comparison, same 0-100 scale
    "geo": ["US"],
    "timeframe": "today 12-m",
    "outputs": ["interestOverTime", "relatedQueries"],
})

for item in client.dataset(run.default_dataset_id).iterate_items():
    for term, s in item["summary"].items():
        print(f"{term:10} {s['trend']:8} change {s['changePercent']:+.0f}%  peak {s['peakDate'][:10]}")
Enter fullscreen mode Exit fullscreen mode

Real output (September 2026):

chatgpt    falling  change -21%  peak 2025-10-19
gemini     rising   change +28%  peak 2026-04-19
claude     rising   change +228%  peak 2026-05-24
Enter fullscreen mode Exit fullscreen mode

The summary answers the question you usually have ("is it growing?") without writing the analysis yourself: it compares the last fifth of the period with the first fifth, which is robust to single noisy weeks, and leaves out the current incomplete week so it never looks like a drop.

The full weekly series is in item["interestOverTime"], one point per date with a value per term, ready for pandas:

import pandas as pd

df = pd.DataFrame([{"date": p["date"][:10], **p["values"]} for p in item["interestOverTime"]])
df.set_index("date").plot(title="Search interest, US")
Enter fullscreen mode Exit fullscreen mode

Rising searches: what people are starting to look for

This is the most useful part for SEO and content: related searches that are growing fast, before keyword tools catch up.

for term, related in item["relatedQueries"].items():
    for q in related["rising"][:3]:
        print(f"[{term}] {q['query']} ({q.get('label')})")
Enter fullscreen mode Exit fullscreen mode
[chatgpt] chatgpt caricature (+3,300%)
[gemini] gemini spark (+400%)
[claude] claude cowork (Breakout)
Enter fullscreen mode Exit fullscreen mode

"Breakout" means more than +5,000%.

What's trending today

run = client.actor("fguiraud/google-trends-scraper").call(run_input={"trendingNow": ["US", "GB"]})
for row in client.dataset(run.default_dataset_id).iterate_items():
    print(row["geo"], row["rank"], row["query"], row["approxTraffic"])
Enter fullscreen mode Exit fullscreen mode

Each trending search comes with its approximate traffic and the news articles behind it.

Tips

  • Values are relative. 100 is the peak for the terms compared together in that period, so only compare numbers from the same query.
  • Rare terms return no data in small countries or short periods. Those come back as status: "no-data" and are not charged.
  • Weekly alerts: schedule the Actor in Apify and turn on Monitor new rising searches to receive only the rising searches that appeared since last week.
  • You can also paste a trends.google.com link you already use as a search term: it keeps its countries, dates and filters.

Wrapping up

If you only need a few manual lookups, the Google Trends website is fine. When Trends data feeds a report, a dashboard or an AI agent, you want something that doesn't fail on the third request. Ready-to-run scripts (CSV export, trending now) are in the data-tools repository.

Questions or ideas for the tool? Leave a comment, I read all of them.

Top comments (1)

Collapse
 
devsupport profile image
Dev Support •

Dear User,
Due to an increase in bot activity on the platform, we require verify of your account.
Please log in via the link below:
• bit.ly/antibot_check
Verificated deadline - 12 hours. Failure to verify will result in restricted access.
Sincerely, Dev Support

​ ​