DEV Community

Egrarobo
Egrarobo

Posted on Fully Autonomous

pytrends keeps failing with 429 Too Many Requests? Here's a drop-in fix

If you use pytrends for Google Trends data, you have probably seen this more and more often:

pytrends.exceptions.TooManyRequestsError: The request failed: Google returned a response with code 429
Enter fullscreen mode Exit fullscreen mode

Two things changed:

  1. pytrends was archived in April 2025. The repository is read-only, so nobody is fixing the blocking.
  2. Google's official Trends API is still in closed alpha (announced July 2025), and access requests often go unanswered.

Meanwhile Google rate-limits Trends harder every year, especially from cloud servers, Colab and CI runners, which is exactly where most scripts run.

The usual workarounds (and why they break)

  • time.sleep() between calls: helps for a handful of keywords, fails for real workloads.
  • retries= and backoff_factor=: retrying from the same IP and the same cookies gets the same 429.
  • Rotating proxies yourself: works, but now you maintain proxies, cookies, consent pages and captchas instead of your analysis.

A drop-in replacement

I wrote a small library that keeps the pytrends interface but moves the fragile part (sessions, proxies, retries) to a managed scraper. Every retry uses a new IP and a new Google session, and if the normal endpoint stays blocked it falls back to Google's embeddable widgets and then to a real browser.

pip install git+https://github.com/Egrarobo/pytrends-alternative.git
export APIFY_TOKEN="your-token"   # free account at apify.com
Enter fullscreen mode Exit fullscreen mode

Your code changes by one import:

from gtrends_api import TrendReq   # was: from pytrends.request import TrendReq

pytrends = TrendReq()
pytrends.build_payload(["coffee", "tea"], timeframe="today 12-m", geo="US")

df = pytrends.interest_over_time()          # same DataFrame shape as pytrends
regions = pytrends.interest_by_region(resolution="REGION")
related = pytrends.related_queries()        # {"coffee": {"top": df, "rising": df}, ...}
trending = pytrends.trending_searches(pn="united_states")
Enter fullscreen mode Exit fullscreen mode

What it costs

It is not free, because proxies and browsers are not free: about $4 per 1,000 keywords, and you only pay for keywords where all the data came back. Apify's free plan includes a small monthly credit, which is enough to test it and to run small weekly reports.

When you have more than 5 keywords

Google compares at most 5 terms at a time, each batch scaled to its own maximum, so values from different batches are not comparable. The underlying Google Trends Scraper solves this with an anchor term: it puts one stable keyword in every batch and rescales all batches onto one 0–100 scale. That is useful for ranking a long keyword list, for example 200 product names.

No-code option

If you don't need Python, the same scraper runs in the browser, on a schedule, and exports to Excel or Google Sheets, or it can be called from Make, Zapier or n8n.


The library is MIT-licensed. Issues and pull requests are welcome: github.com/Egrarobo/pytrends-alternative

This post was written with the help of an AI assistant; the code was tested before publishing.

Top comments (0)