Skip to main content

Google Trends API for Python and JavaScript

A maintained way to get Google Trends data from code, after pytrends was archived:

  • interest over time
  • interest by region
  • related queries (top and rising)
  • related topics

It works for any country, time range and search vertical (Web, YouTube, News, Images, Shopping).

Demo: pytrends-style code comparing chatgpt, gemini and claude

Guides: pytrends alternative: fixing 429 errors · Google's trending searches in Python

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

pytrends = TrendReq()
pytrends.build_payload(["chatgpt", "gemini", "claude"], timeframe="today 3-m", geo="US")
pytrends.interest_over_time().tail(3)
            chatgpt  gemini  claude  isPartial
date
2026-11-01       53      21      16      False
2026-11-02       79      32      23      False
2026-11-03       71      32      22       True

How it works, and what it costs

Google has no public Trends API, and its website rate-limits scripts quickly. That's why pytrends users hit 429 Too Many Requests constantly.

This library doesn't call Google from your machine. Each call starts a run of a hosted scraper, Google Trends Scraper on Apify, which handles rotating IPs, retries and backoff. The library then returns the results.

You need a free Apify account and its API token:

  1. Sign up at apify.com.
  2. Copy the token from Settings → API & Integrations.
  3. Set it with export APIFY_TOKEN=....

Pricing is pay-per-use:

  • $0.02 per call (run).
  • $0.002 per search term.
  • $0.001 for each extra section that returns data.
  • For example, 100 keywords in one call cost about $0.22.
  • Failed queries aren't charged.
  • Apify's free plan includes monthly credit, which covers casual use.

Disclosure: the maintainer of this repo also publishes that scraper. The client code is MIT, and you can point it at any actor with the same input (actor=). Links to apify.com include my referral code, so Apify may pay me a commission if you sign up. It doesn't change your price.

Install

pip install "pytrends-alt[pandas]"

The core client has no dependencies. Pandas is only needed for the pytrends-compatible TrendReq.

For JavaScript (Node 18+): npm install gtrends-client, or copy js/index.mjs. It's a single file with no dependencies.

The package is named pytrends-alt on PyPI; you still import google_trends_api.

Python

Migrating from pytrends

TrendReq supports these pytrends calls and returns DataFrames shaped like pytrends' output:

  • build_payload(kw_list, cat, timeframe, geo, gprop)
  • interest_over_time()
  • interest_by_region()
  • related_queries()

Constructor arguments such as hl, tz, retries, backoff_factor and proxies are accepted and ignored, because retries and proxies now happen server-side.

Batch API (faster, cheaper)

pytrends needed one request per keyword group. Here, one call can process hundreds of queries in parallel:

from google_trends_api import GoogleTrends

gt = GoogleTrends()  # reads APIFY_TOKEN
rows = gt.fetch(
    ["air fryer", "standing desk", "iphone, samsung galaxy"],   # comma = compare on one chart (max 5)
    geo="US", timeframe="today 12-m",
    sections=["interestOverTime", "interestByRegion", "relatedQueries"],
)
for r in rows:
    print(r["searchTerm"], r["interestOverTime"][-1]["values"], r["relatedQueries"])

Plain-dict helpers, no pandas needed:

  • gt.interest_over_time(["a", "b"])
  • gt.interest_by_region(...)
  • gt.related_queries(...)

Time frames:

  • presets: now 1-H, now 4-H, now 1-d, now 7-d, today 1-m, today 3-m, today 12-m, today 5-y, all
  • custom: "2024-01-01 2024-06-30"

Search verticals (property): web, youtube, news, images, shopping. pytrends' gprop values also work, including froogle.

JavaScript

import { GoogleTrends } from './index.mjs';

const gt = new GoogleTrends({ token: process.env.APIFY_TOKEN });
const rows = await gt.interestOverTime(['air fryer'], { geo: 'GB', timeframe: 'today 1-m' });
// [{ date: '2026-11-03T00:00:00.000Z', isPartial: true, 'air fryer': 38 }, ...]

Output

Values are Google's relative interest, from 0 to 100. Rising related queries are percentage growth, and "Breakout" means more than +5000%. Full item format:

{
  "searchTerm": "iphone, samsung galaxy",
  "keywords": ["iphone", "samsung galaxy"],
  "interestOverTime": [{ "date": "2026-08-03T00:00:00.000Z", "isPartial": false, "values": { "iphone": 46, "samsung galaxy": 2 } }],
  "interestByRegion": [{ "geoCode": "US-KS", "geoName": "Kansas", "values": { "iphone": 95, "samsung galaxy": 5 } }],
  "relatedQueries": { "iphone": { "top": [{ "query": "iphone 18", "value": 100 }], "rising": [{ "query": "iphone duo release date", "value": 13150, "formattedValue": "Breakout" }] } }
}

FAQ

Is there an official Google Trends API? Google announced one as an alpha in 2025 for a limited set of testers. If you have access, use it. This library is for everyone else.

Why not just fix pytrends' 429 errors? The 429s come from Google limiting requests per IP. Fixing them means rotating IPs and backing off, which this library does on the server side.

Can I trust the rising queries? Google sometimes slips generic, unrelated "rising" queries into results it serves to automated traffic, for example "learn golang" as a rising search for protein powder. The scraper detects lists like that and keeps only queries that belong to the keyword. It reports the number removed as risingRemoved. Top queries and interest over time aren't affected.

Is it free? The code is free. Running queries costs Apify credit, as shown above.

Development

python -m pytest tests        # offline, uses a recorded real response
cd js && npm test

MIT licensed.

Metadata

Release files for pytrends-alt 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytrends-alt 0.1.0
File Size Uploaded Provenance Actions
pytrends_alt-0.1.0.tar.gz 9.4 kB Without provenance Details for pytrends_alt-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pytrends-alt 0.1.0
File Interpreter ABI Platform Actions
pytrends_alt-0.1.0-py3-none-any.whl Python 3 none any Details for pytrends_alt-0.1.0-py3-none-any.whl

Total release size: 18.1 kB

Release files / pytrends_alt-0.1.0.tar.gz

Download URL pytrends_alt-0.1.0.tar.gz
Size 9.4 kB
Tags Source
SHA-256 checksum
How to use checksums
dfb9ec6057b162741cd9bd16d693209a7fcbd519da68cd9c845ba1207a8492dc
BLAKE2b-256 checksum
How to use checksums
1bb8e0081ea66c1ca2d875c6d602c725b6bbd3c014edb980f19b8eaf60010f31
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / pytrends_alt-0.1.0-py3-none-any.whl

Download URL pytrends_alt-0.1.0-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d61775c859770579417c2ab58c7c2dc46e9bfb8f592686b320da691644dc0c06
BLAKE2b-256 checksum
How to use checksums
364b9944737807fd5b31c8f177f450e7b9cb1ae1fdd9273a337ad3c453a2c52f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Security for pytrends-alt 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page