pytrends was the default way to get Google Trends data in Python. The GitHub repository GeneralMills/pytrends is now archived. The last push was on 2024-08-10. It still had about 1.16 million downloads on PyPI in the last 30 days (pypistats, November 2026).
So a lot of scripts still depend on a library that will not get fixes. When Google changes something, or starts to answer with 429 Too Many Requests, there is nobody to fix it.
This post shows how I moved a pytrends script to a hosted scraper that returns the same data as JSON.
Disclosure: I built the scraper used below (Google Trends Scraper on Apify). It is a paid tool with a free monthly allowance. If you want to stay fully free, the last section lists the trade-offs.
What pytrends gave you
A typical pytrends script looks like this:
from pytrends.request import TrendReq
pytrends = TrendReq(hl="en-US", tz=360)
pytrends.build_payload(["python"], geo="US", timeframe="today 3-m")
over_time = pytrends.interest_over_time()
by_region = pytrends.interest_by_region()
related = pytrends.related_queries()
You get interest over time, interest by region, and related queries (top and rising).
The same data with apify-client
Install the client:
pip install apify-client pandas
Get an API token from your Apify account (Settings → API & Integrations). Then:
import os
import pandas as pd
from apify_client import ApifyClient
client = ApifyClient(os.environ["APIFY_TOKEN"])
run = client.actor("krammer/google-trends-scraper").call(
run_input={"searchTerms": ["python"], "geo": "US", "timeRange": "today 3-m"}
)
item = next(iter(client.dataset(run.default_dataset_id).iterate_items()))
# interest_over_time()
over_time = pd.DataFrame(
[{"date": p["formattedTime"], "python": p["value"][0]}
for p in item["interestOverTime_timelineData"]]
)
# interest_by_region()
by_region = pd.DataFrame(
[{"region": r["geoName"], "python": r["value"][0]}
for r in item["interestBySubregion"]]
).sort_values("python", ascending=False)
# related_queries()
top = pd.DataFrame(item["relatedQueries_top"])[["query", "value"]]
rising = pd.DataFrame(item["relatedQueries_rising"])[["query", "formattedValue"]]
print(over_time.tail(3))
print(by_region.head(3))
print(top.head(3))
Output from a run on 2026-11-16:
date python
90 Nov 14, 2026 31
91 Nov 15, 2026 31
92 Nov 16, 2026 33
region python
0 Kansas 100
1 Virginia 52
2 Maryland 50
query value
0 what is python 100
1 ball python 78
2 python code 76
One run returns one item per search term. For python in the US over 3 months, the item had 93 time points, 51 states, 200 cities, 210 metro areas (DMA), and 25 top plus 25 rising related queries.
Mapping pytrends calls
| pytrends | Input or output field |
|---|---|
build_payload(kw_list, geo, timeframe, cat, gprop) |
searchTerms, geo, timeRange, category, property
|
interest_over_time() |
interestOverTime_timelineData |
interest_by_region() |
interestBySubregion, interestByCity, interestByMetro; interestBy for worldwide |
related_queries() |
relatedQueries_top, relatedQueries_rising
|
trending_searches() |
"mode": "trending" with "trendingGeos": ["US"]
|
To compare terms on one scale (like kw_list=["iphone", "samsung galaxy"]), send them as one comma-separated entry and set isMultiple:
run_input = {"searchTerms": ["iphone,samsung galaxy"], "isMultiple": True, "geo": "US"}
Each time point then has one value per term: p["value"][0], p["value"][1].
Trending searches
run = client.actor("krammer/google-trends-scraper").call(
run_input={"mode": "trending", "trendingGeos": ["US"]}
)
for row in client.dataset(run.default_dataset_id).iterate_items():
print(row["title"], row["approxTraffic"])
Cost and limits
- You pay per search term that returns data. On the Apify Free plan it is $0.0048 per term. Terms with no data are free.
- Free Apify accounts can use up to $1.00 of this scraper per month.
- Each term takes about 8 seconds. The default run timeout is 300 seconds, which is about 30 terms. Raise the timeout for bigger batches.
- Related topics are not returned (the fields are empty arrays).
- If Google limits requests, the run stops early and the remaining terms are not charged. Try again about 10 minutes later.
If you want to stay free
You can keep using pytrends as long as it works for your queries. Pin the version, add retries with backoff for 429, and cache results so you send fewer requests. The risk is that the next Google change breaks it and no release will fix it.
If you only need a few terms once in a while, the Google Trends website lets you download CSV files by hand.
Top comments (0)