Google Trends API in Python: extract Google Trends data with apify-client
The Google Trends API runs from Python with the apify-client library: install it with pip, call the Actor kwerix/google-trends-api with a keyword list and read one row per keyword from the run's dataset. The same script returns the trend, the seasonality, the breakout queries and the regions, and a max_total_charge_usd option caps what the run can cost.
KwerixPublished

How to call the Google Trends API from Python
There are 4 steps to call the Google Trends API from Python.
- Install the client with
pip install apify-client. - Copy your API token from Apify Console → Settings → API & Integrations.
- Call the Actor
kwerix/google-trends-apiwith a keyword list, a location and a time range. - Iterate over the items of the run’s dataset, one row per keyword.
import os
from decimal import Decimal
from apify_client import ApifyClient
client = ApifyClient(os.environ["APIFY_TOKEN"])
run = client.actor("kwerix/google-trends-api").call(
run_input={"keywords": ["sunscreen", "retinol"], "geo": "US"},
max_total_charge_usd=Decimal("0.50"),
)
for row in client.dataset(run["defaultDatasetId"]).iterate_items():
print(row["keyword"], row["trendSlopePctPerYear"], row["breakoutQueries"][:3])Which fields does the Python client receive?
The Python client receives 6 groups of fields in every row of the Google Trends API.
| Field | Type | Example (sunscreen) |
|---|---|---|
averageInterest, peakDate | float, date | 26.3, 2026-06-07 |
trendSlopePctPerYear, yoyChangePct | float | 21.6, 55.9 |
seasonality | dict | {"isSeasonal": True, "publishBy": "2027-04-24"} |
breakoutQueries | list of str | ["beauty of joseon", …] |
risingQueries, topQueries | list of dict | {"query": "best sunscreen", "value": 100} |
interestByRegion | list of dict | {"geoName": "Wyoming", "value": 100} |
How to compare keywords in Python
Comparing keywords in Python takes one switch: compareKeywords, with an anchor keyword of medium popularity.
rows = run({"keywords": keywords, "geo": "US", "timeRange": "today 12-m",
"compareKeywords": True, "anchorKeyword": "retinol", "includeRelatedQueries": False})
ranked = sorted((r for r in rows if r.get("comparison")), key=lambda r: r["comparison"]["rank"])
for r in ranked:
print(r["comparison"]["rank"], r["keyword"], r["comparison"]["averageOnCommonScale"])Which Python examples are ready to run?
4 Python examples are ready to run in the Kwerix repository on GitHub, under the MIT license.
- keyword_analysis.py: trend, year-over-year change, seasonality and breakout queries for a keyword list.
- compare_keywords.py: any number of keywords ranked on one scale.
- seasonal_calendar.py: an SEO content calendar with the keywords to publish for and the dates.
- trending_now.py: what is trending now in one or more countries, by category.
How to cap the cost of a Python run
A Python run caps its cost with max_total_charge_usd, which stops charging at the amount set; at $0.0015 per keyword, Decimal("0.50") covers up to 333 keywords.
- The Python client is one of 4 ways to extract Google Trends data via API, with JavaScript, plain HTTP and MCP.
- Scripts written for the archived library move line by line in the alternative to pytrends guide.
Google Trends API in Python FAQ
Is there an official Google Trends library for Python?
No. Google publishes no Python library for Google Trends; pytrends was unofficial and archived on April 17, 2025, and the official API is an alpha with access by application.
Does the Google Trends API need pandas in Python?
No. The rows come back as Python dictionaries, and pandas is optional for anyone who wants a DataFrame.