Guide
Google Trends API in Python without fighting 429 errors
If you’ve used pytrends, you’ve probably hit Google’s 429 error: Google limits how often one IP address can query Trends, and there’s no good way around that from a single machine. pytrends itself was archived in April 2025, and Google’s official Trends API is still an alpha you have to apply for. This guide gets the same data into pandas through a hosted Google Trends API instead: interest over time, comparisons, regions, related queries and Trending Now, plus daily data for ranges longer than 9 months, which pytrends never could.
This guide uses our Google Trends Scraper & API on the Apify Store. Every step works with a free Apify account.
This is the error in question:
pytrends.exceptions.TooManyRequestsError: The request failed: Google returned a response with code 429
How the hosted API handles Google’s limits
The API is our Google Trends Scraper & API on Apify. It runs in Apify’s cloud and introduces itself honestly, as an Apify crawler named ApifyBot, rather than pretending to be a web browser. When Google turns a request away, it tries again from a different IP address on Apify’s proxy, up to 8 times. Anything that still fails is listed in the run’s status message and in an ERRORS record, and a run that gets no data at all is marked as failed, so it never ends with silently empty results.
It charges per result. Apify’s free plan includes $5 of usage a month, which covers about 2,500 search terms.
Setup
- Open Google Trends Scraper & API and click Try for free to create a free Apify account. No credit card is needed.
- Copy your API token from Settings → API & Integrations in Apify Console.
- Install the client and pandas, and put the token in an environment variable:
pip install apify-client pandas
export APIFY_TOKEN=your-token
Keep the token out of your code and your repositories.
Interest over time
Two small helpers do all the work. The first runs the API and returns its results; the second turns them into the same table pytrends’ interest_over_time() returned: one column per term, one row per date.
import os
import pandas as pd
from apify_client import ApifyClient
client = ApifyClient(os.environ["APIFY_TOKEN"])
def google_trends(**run_input):
run = client.actor("clearpull/google-trends-scraper").call(run_input=run_input)
return list(client.dataset(run.default_dataset_id).iterate_items())
def timeline(results):
rows = [
{"date": point["date"], "term": result["searchTerm"], "value": point["value"]}
for result in results
if result["type"] == "searchTerm" and result["hasData"]
for point in result["interestOverTime"]
]
frame = pd.DataFrame(rows)
frame["date"] = pd.to_datetime(frame["date"])
return frame.pivot(index="date", columns="term", values="value")
results = google_trends(
searchTerms=["coffee", "matcha", "tea"],
compareTogether=True,
geo="US",
timeRange="today 12-m",
)
print(timeline(results).tail())
compareTogether=True puts the terms on one shared 0–100 scale, like passing several keywords to build_payload. Leave it out and each term gets its own scale.
Time ranges use the same codes as pytrends: now 7-d, today 3-m, today 12-m, today 5-y, all, or two dates in customTimeRange, such as "2025-01-01 2025-06-30".
Trend direction, regions and related queries
Each result also carries a few summary numbers, so you don’t have to compute them yourself:
for result in results:
print(result["searchTerm"], result["trendDirection"], result["changePercent"],
result["peakInterest"], result["peakDate"][:10])
trendDirection is rising, falling or stable. It compares the average of the last quarter of the period with the first quarter: a change of 15% or more either way counts as rising or falling. That makes it easy to sort hundreds of keywords at once.
Regions and related queries come as lists of dicts, ready for a DataFrame:
matcha = next(r for r in results if r["searchTerm"] == "matcha")
print(pd.DataFrame(matcha["interestByRegion"]).head()) # geoCode, geoName, value
print(pd.DataFrame(matcha["relatedQueries"]["rising"]).head()) # query, value, formattedValue
For US metro areas or cities, add regionResolution="DMA" or "CITY".
Trending Now
for row in google_trends(trendingNowGeos=["US", "GB"]):
print(row["geo"], row["approxTraffic"], row["title"])
Each row has Google’s traffic estimate (such as "20K+"), when the trend started, and links to the news stories behind it.
Daily data for five years
Google only returns daily values for ranges up to about 9 months. Ask for 5 years and you get weekly numbers. With dailyData=True, the API fetches overlapping 250-day windows and stitches them into one daily series:
results = google_trends(searchTerms=["air fryer"], geo="US", timeRange="today 5-y", dailyData=True)
daily = timeline(results)
print(len(daily)) # about 1,826 daily values instead of 261 weekly ones
How the stitching works, with code you can run on any data source: How to get daily Google Trends data for more than 9 months.
pytrends equivalents
| pytrends | Here |
|---|---|
build_payload(kw_list, timeframe, geo, cat, gprop) | searchTerms, timeRange, geo, category, searchProperty, plus compareTogether=True |
interest_over_time() | interestOverTime |
interest_by_region(resolution=...) | interestByRegion, with regionResolution |
related_queries() | relatedQueries["top"] and relatedQueries["rising"] |
trending_searches(pn=...) | trendingNowGeos |
What it costs
On Apify’s free plan: $2 per 1,000 search terms with data, $1 per 1,000 trending searches, and nothing for terms Google has no data for. Paid Apify plans pay less, down to $1.60 and $0.80. A weekly check of 100 keywords comes to about $0.90 a month, which the free plan covers. With daily data, each extra 250-day window counts as one more term, so 5 years of daily data for one keyword is about $0.02.
Disclosure: we (clearpull) built this API.
Need data from another public source, or a different setup? Get in touch.