100 free credits. No credit card required.Start building
Logo
Back to blog

Google Trends API in Python: Interest Over Time Example

··9 min read

Call a Google Trends API from Python with one GET and an API key. Get interest over time and related queries as JSON, with params, credits and error cases.

Google Trends API in Python: Interest Over Time Example

To use a Google Trends API from Python, send one GET request with an API key. With SocialCrawl, GET /v1/google_trends/explore returns interest over time for up to five keywords, and GET /v1/google_trends/rising returns the rising and top related queries for one keyword. Each call is 5 credits, and there is no SDK, no OAuth and no scraping.

Google announced a Trends API alpha in July 2025, with access limited to applicants, so there is no public key to sign up for. pytrends is the unofficial library many Python projects used instead, but its repository was archived read-only in April 2025. This API gives you the same kind of data over plain HTTP. For provider choice and pricing, see best Google Trends APIs.

An isometric line-chart slab with one rising curve, the interest-over-time series a Google Trends API returns.

Call GET /v1/google_trends/explore with keywords (one to five, comma-separated), an optional location and an optional timeframe. The response holds a dated series for each keyword and an averages list, all on Google's relative 0 to 100 index. It is not search volume.

python
import os
import requests

BASE = "https://www.socialcrawl.dev"
r = requests.get(
    f"{BASE}/v1/google_trends/explore",
    params={
        "keywords": "oat milk,almond milk,soy milk",
        "location": "US",
        "timeframe": "past_12_months",
    },
    headers={"x-api-key": os.environ["SOCIALCRAWL_API_KEY"]},
    timeout=90,
)
r.raise_for_status()
payload = r.json()

for row in payload["data"]["averages"]:
    print(row["keyword"], row["value"])

The same request in curl:

bash
curl -s --max-time 90 -H "x-api-key: $SOCIALCRAWL_API_KEY" \
  "https://www.socialcrawl.dev/v1/google_trends/explore?keywords=oat%20milk,almond%20milk,soy%20milk&location=US&timeframe=past_12_months"

The response, trimmed to one point per series:

json
{
  "success": true,
  "data": {
    "averages": [
      { "keyword": "oat milk", "value": 51 },
      { "keyword": "almond milk", "value": 68 },
      { "keyword": "soy milk", "value": 24 }
    ],
    "series": [
      {
        "keyword": "oat milk",
        "points": [{ "date": "2026-08-30", "value": 60, "partial": true }]
      }
    ]
  },
  "credits_used": 5
}

Chart these numbers with care.

  • Put every term you want to compare in one call. With several keywords the values are normalised across the set: the highest point of any keyword in the window is 100 and everything else is relative to it. Two separate calls are not comparable.
  • Drop the last point. partial: true marks a bucket Google is still accumulating, normally the most recent one. Left in, it looks like a drop in interest that never happened.
  • The index is not a volume. Google publishes no absolute search counts, so a value of 68 does not mean 68 searches. Google's own explanation says a point is a share of searches in that place and window, scaled to 100.

explore takes keywords, timeframe, location and category. Only keywords is required. Each keyword must be 2 to 100 characters, and more than five is rejected with a free 400.

ParameterWhat it accepts
keywords1 to 5 comma-separated terms
locationAn ISO country code (US, KR), a full name (South Korea) or a numeric code (2840)
timeframepast_hour, past_4_hours, past_day, past_7_days, past_30_days, past_90_days, past_12_months (default), past_5_years
categoryA numeric Google Trends category code. The default 0 means all categories

timeframe is a fixed list of presets, so there is no arbitrary date range. Short windows change the granularity: past_hour and past_4_hours return minute-level points and past_5_years returns weekly ones, so do not assume a fixed spacing when you plot.

category helps with ambiguous terms. "Jaguar" in the automotive category and "jaguar" overall are two different series. For Korean demand, pair it with /v1/naver/search-trend, since much Korean search happens on Naver.

Call GET /v1/google_trends/rising with one keyword. It returns two lists: rising queries with a percentage growth, and top queries with a 0 to 100 value. Use top to see where demand sits now, and rising to see what is breaking out before it moves the main series.

python
r = requests.get(
    f"{BASE}/v1/google_trends/rising",
    params={
        "keyword": "solid state battery",
        "location": "US",
        "timeframe": "past_12_months",
    },
    headers={"x-api-key": os.environ["SOCIALCRAWL_API_KEY"]},
    timeout=90,
)
r.raise_for_status()
data = r.json()["data"]

for row in data["rising"]:
    print(row["query"], row["growth"], row.get("is_breakout"))
for row in data["top"]:
    print(row["query"], row["value"])

Trimmed response:

json
{
  "data": {
    "rising": [
      { "query": "example query one", "growth": 650, "is_breakout": false },
      { "query": "example query two", "growth": null, "is_breakout": true }
    ],
    "top": [
      { "query": "example top query", "value": 100 }
    ]
  },
  "credits_used": 5
}

A rising row with is_breakout: true is a query Google labels "Breakout", which means growth above +5,000%. When Google gives no percentage for it, growth is null. Do not fill in a number for it.

The parameter is keyword, singular, because Google returns related queries for one term at a time. A comma-separated list is a free 400. The usual order is explore first to size the series, then rising on the winner.

Two errors are common and both cost nothing. A 404 means Google holds too little search volume for that keyword in that place and window. A 400 means a parameter was not recognised, most often the location. Neither is a timeout.

json
{
  "success": false,
  "error": {
    "type": "RESOURCE_NOT_FOUND",
    "message": "No search-interest data were returned for this keyword. ... You were not charged for this request.",
    "status": 404
  },
  "credits_used": 0
}

For a 404, try a wider timeframe, a broader keyword, or the keyword in the local language of the location. If you send several keywords, the call still succeeds as long as one of them has data. For a 400, check the location first: it must be an ISO code, a country name as Google Trends spells it, or a numeric code, and Google does not publish every country. The full list of error types is in error handling.

Set a client timeout of at least 60 seconds for explore and rising. Repeat calls inside the 2-minute cache return immediately at no charge.

GET /v1/google_trends/trending returns the Trending Now list for a country or region, with no keyword in. It is 5 credits and returns each trend's search volume bucket, increase percentage, start time, categories and up to three news articles. Use it when a keyword would bias what you find.

bash
curl "https://www.socialcrawl.dev/v1/google_trends/trending?location=DE&hours=24&sort=search_volume&limit=25" \
  -H "x-api-key: YOUR_API_KEY"

search_volume is the lower bound of Google's bucket, so 50000 means 50K or more. Google covers 125 countries and has no worldwide list.

Sign up, copy a key from the dashboard, and send it in the x-api-key header. New accounts start with 100 free credits, which covers 20 calls at 5 credits each. Authentication details are in Authentication. Field-by-field detail for all three endpoints is in the Google Trends docs, and you can try the same call in the explorer before writing code.

Frequently asked questions

Google announced a Trends API alpha in July 2025, available to a limited group of testers who apply for access. It is not a public REST API you can sign up for with a key. SocialCrawl offers a public x-api-key GET that returns the same kind of 0 to 100 series.

Send a GET request with requests to /v1/google_trends/explore and an x-api-key header, then read data.series and data.averages from the JSON. No SDK and no browser session is needed.

Call GET /v1/google_trends/rising with a single keyword. The response has a rising list with percentage growth and a top list with a 0 to 100 value. Each call is 5 credits.

Each request is normalised to its own window, so the 100 in one call is not the 100 in another. To compare terms, put all of them, up to five, in one explore call.

No. Google publishes only a relative 0 to 100 index, and neither explore nor rising returns an absolute count. The Trending Now endpoint returns a volume bucket, which is a lower bound such as 50K or more.

What happens when a keyword has no data?

The API returns a 404 at 0 credits instead of a billed empty series. Try a wider timeframe, a broader keyword, or the term in the local language of the location.

Topics
#google-trends-api-python#google-trends-interest-over-time#google-trends-python#google-trends-related-queries#google-trends-api-documentation#google-trends-api-example#pytrends#google-trends-python-api

Related posts

🤖 AI agent or LLM? Read this page as markdown