Google Trends API Python Client

Extract Google Trends data with our Google Trends API Python client. Get programmatic access to search popularity, regional interest, related topics, and more using simple Python code. Start free, no credit card required.

POWERING THE WORLD'S TOP DATA-DRIVEN TEAMS

The Apify API client for Python is the official library that allows you to use Google Trends API in Python, providing convenience functions and automatic retries on errors. Get started with simple pip installation and robust error handling built-in.

Python

Python

1from apify_client import ApifyClient
2
3# Initialize the ApifyClient with your Apify API token
4# Replace '<YOUR_API_TOKEN>' with your token.
5client = ApifyClient("<YOUR_API_TOKEN>")
6
7# Prepare the Actor input
8run_input = {
9 "searchTerms": ["webscraping"],
10 "timeRange": "",
11 "viewedFrom": "",
12}
13
14# Run the Actor and wait for it to finish
15run = client.actor("emastra/google-trends-scraper").call(run_input=run_input)
16
17# Fetch and print Actor results from the run's dataset (if there are any)
18print("πŸ’Ύ Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
19for item in client.dataset(run["defaultDatasetId"]).iterate_items():
20 print(item)
21
22# πŸ“š Want to learn more πŸ“–? Go to β†’ https://docs.apify.com/api/client/python/docs/quick-start

Use our Python API client to extract Google Trends data by providing search terms or Google Trends URLs with your filters. The API returns structured data, including search popularity, regional interest, related topics, and more, which is perfect for pandas DataFrames, data analysis, and Python applications.

Input

{
"geo": "",
"category": "",
"isPublic": false,
"maxItems": 0,
"timeRange": "",
"isMultiple": false,
"searchTerms": [
"webscraping"
],
"maxConcurrency": 10,
"skipDebugScreen": false,
"maxRequestRetries": 7,
"pageLoadTimeoutSecs": 180
}

Output

{
"interestBy": [
{
"value": [
100
],
"geoCode": "SH",
"geoName": "St. Helena",
"hasData": [
true
],
"maxValueIndex": 0,
"formattedValue": [
"100"
]
},
{
"value": [
60
],
"geoCode": "TN",
"geoName": "Tunisia",
"hasData": [
true
],
"maxValueIndex": 0,
"formattedValue": [
"60"
]
},
{
"value": [
56
],
"geoCode": "SG",
"geoName": "Singapore",
"hasData": [
true
],
"maxValueIndex": 0,
"formattedValue": [
"56"
]
},
{
"value": [
46
],
"geoCode": "PK",
"geoName": "Pakistan",
"hasData": [
true
],
"maxValueIndex": 0,
"formattedValue": [
"46"
]
},
{
"value": [
0
],
"geoCode": "KM",
"geoName": "Comoros",
"hasData": [
false
],
"maxValueIndex": 0,
"formattedValue": [
""
]
},
{
"value": [
0
],
"geoCode": "IO",
"geoName": "British Indian Ocean Territory",
"hasData": [
false
],
"maxValueIndex": 0,
"formattedValue": [
""
]
}
],
"searchTerm": "web scraping",
"inputUrlOrTerm": "web scraping",
"interestByCity": [],
"relatedTopics_top": [
{
"link": "/trends/explore?q=/m/07ykbs&date=today+12-m",
"topic": {
"mid": "/m/07ykbs",
"type": "Topic",
"title": "Web scraping"
},
"value": 100,
"hasData": true,
"formattedValue": "100"
},
{
"link": "/trends/explore?q=/m/0828v&date=today+12-m",
"topic": {
"mid": "/m/0828v",
"type": "Topic",
"title": "World Wide Web"
},
"value": 97,
"hasData": true,
"formattedValue": "97"
},
{
"link": "/trends/explore?q=/m/05z1_&date=today+12-m",
"topic": {
"mid": "/m/05z1_",
"type": "Programming language",
"title": "Python"
},
"value": 29,
"hasData": true,
"formattedValue": "29"
},
{
"link": "/trends/explore?q=/m/026sq&date=today+12-m",
"topic": {
"mid": "/m/026sq",
"type": "Topic",
"title": "Data"
},
"value": 14,
"hasData": true,
"formattedValue": "14"
},
{
"link": "/trends/explore?q=/m/085n4&date=today+12-m",
"topic": {
"mid": "/m/085n4",
"type": "Topic",
"title": "Website"
},
"value": 9,
"hasData": true,
"formattedValue": "9"
},
{
"link": "/trends/explore?q=/m/0c828v&date=today+12-m",
"topic": {
"mid": "/m/0c828v",
"type": "Software",
"title": "Selenium"
},
"value": 5,
"hasData": true,
"formattedValue": "5"
},
{
"link": "/trends/explore?q=/m/0z5n&date=today+12-m",
"topic": {
"mid": "/m/0z5n",
"type": "Type of software",
"title": "Application programming interface"
},
"value": 5,
"hasData": true,
"formattedValue": "5"
},
{
"link": "/trends/explore?q=/m/022qrc8&date=today+12-m",
"topic": {
"mid": "/m/022qrc8",
"type": "HTML parser",
"title": "Beautiful Soup"
},
"value": 5,
"hasData": true,
"formattedValue": "5"
},
{
"link": "/trends/explore?q=/m/07k1x&date=today+12-m",
"topic": {
"mid": "/m/07k1x",
"type": "Topic",
"title": "Tool"
},
"value": 5,
"hasData": true,
"formattedValue": "5"
},
{
"link": "/trends/explore?q=/m/086nh&date=today+12-m",
"topic": {
"mid": "/m/086nh",
"type": "Topic",
"title": "Web page"
},
"value": 5,
"hasData": true,
"formattedValue": "5"
},
{
"link": "/trends/explore?q=/m/0g57xn&date=today+12-m",
"topic": {
"mid": "/m/0g57xn",
"type": "Field of study",
"title": "Sentiment analysis"
},
"value": 50,
"formattedValue": "+50%"
}
],
"relatedQueries_top": [
{
"link": "/trends/explore?q=python+scraping&date=today+12-m",
"query": "python scraping",
"value": 100,
"hasData": true,
"formattedValue": "100"
},
{
"link": "/trends/explore?q=python&date=today+12-m",
"query": "python",
"value": 96,
"hasData": true,
"formattedValue": "96"
},
{
"link": "/trends/explore?q=web+scraping+python&date=today+12-m",
"query": "web scraping python",
"value": 94,
"hasData": true,
"formattedValue": "94"
},
{
"link": "/trends/explore?q=web+data+scraping&date=today+12-m",
"query": "web data scraping",
"value": 39,
"hasData": true,
"formattedValue": "39"
},
{
"link": "/trends/explore?q=data+scraping&date=today+12-m",
"query": "data scraping",
"value": 38,
"hasData": true,
"formattedValue": "38"
},
{
"link": "/trends/explore?q=web+scraping+in+python&date=today+12-m",
"query": "web scraping in python",
"value": 18,
"hasData": true,
"formattedValue": "18"
},
{
"link": "/trends/explore?q=what+is+web+scraping&date=today+12-m",
"query": "what is web scraping",
"value": 17,
"hasData": true,
"formattedValue": "17"
},
{
"link": "/trends/explore?q=selenium+web+scraping&date=today+12-m",
"query": "selenium web scraping",
"value": 17,
"hasData": true,
"formattedValue": "17"
},
{
"link": "/trends/explore?q=selenium&date=today+12-m",
"query": "selenium",
"value": 16,
"hasData": true,
"formattedValue": "16"
},
{
"link": "/trends/explore?q=web+scraping+google&date=today+12-m",
"query": "web scraping google",
"value": 16,
"hasData": true,
"formattedValue": "16"
},
{
"link": "/trends/explore?q=api&date=today+12-m",
"query": "api",
"value": 16,
"hasData": true,
"formattedValue": "16"
},
{
"link": "/trends/explore?q=website+scraping&date=today+12-m",
"query": "website scraping",
"value": 16,
"hasData": true,
"formattedValue": "16"
},
{
"link": "/trends/explore?q=web+scraping+api&date=today+12-m",
"query": "web scraping api",
"value": 16,
"hasData": true,
"formattedValue": "16"
},
{
"link": "/trends/explore?q=web+scraping+using+python&date=today+12-m",
"query": "web scraping using python",
"value": 15,
"hasData": true,
"formattedValue": "15"
},
{
"link": "/trends/explore?q=web+scraping+with+python&date=today+12-m",
"query": "web scraping with python",
"value": 14,
"hasData": true,
"formattedValue": "14"
},
{
"link": "/trends/explore?q=web+scraping+tools&date=today+12-m",
"query": "web scraping tools",
"value": 12,
"hasData": true,
"formattedValue": "12"
},
{
"link": "/trends/explore?q=beautifulsoup&date=today+12-m",
"query": "beautifulsoup",
"value": 11,
"hasData": true,
"formattedValue": "11"
},
{
"link": "/trends/explore?q=beautifulsoup+web+scraping&date=today+12-m",
"query": "beautifulsoup web scraping",
"value": 11,
"hasData": true,
"formattedValue": "11"
},
{
"link": "/trends/explore?q=web+scraping+free&date=today+12-m",
"query": "web scraping free",
"value": 11,
"hasData": true,
"formattedValue": "11"
},
{
"link": "/trends/explore?q=web+scraper&date=today+12-m",
"query": "web scraper",
"value": 11,
"hasData": true,
"formattedValue": "11"
},
{
"link": "/trends/explore?q=scraper&date=today+12-m",
"query": "scraper",
"value": 11,
"hasData": true,
"formattedValue": "11"
},
{
"link": "/trends/explore?q=scrape&date=today+12-m",
"query": "scrape",
"value": 11,
"hasData": true,
"formattedValue": "11"
},
{
"link": "/trends/explore?q=web+scrape&date=today+12-m",
"query": "web scrape",
"value": 11,
"hasData": true,
"formattedValue": "11"
},
{
"link": "/trends/explore?q=python+selenium+web+scraping&date=today+12-m",
"query": "python selenium web scraping",
"value": 11,
"hasData": true,
"formattedValue": "11"
},
{
"link": "/trends/explore?q=python+selenium&date=today+12-m",
"query": "python selenium",
"value": 11,
"hasData": true,
"formattedValue": "11"
}
],
"interestBySubregion": [],
"relatedQueries_rising": [
{
"link": "/trends/explore?q=chatgpt+web+scraping&date=today+12-m",
"query": "chatgpt web scraping",
"value": 4250,
"formattedValue": "+4,250%"
},
{
"link": "/trends/explore?q=analisis+data+adalah&date=today+12-m",
"query": "analisis data adalah",
"value": 1150,
"formattedValue": "+1,150%"
},
{
"link": "/trends/explore?q=analisis+data&date=today+12-m",
"query": "analisis data",
"value": 750,
"formattedValue": "+750%"
},
{
"link": "/trends/explore?q=playwright&date=today+12-m",
"query": "playwright",
"value": 50,
"formattedValue": "+50%"
},
{
"link": "/trends/explore?q=web+scraping+tool+free&date=today+12-m",
"query": "web scraping tool free",
"value": 50,
"formattedValue": "+50%"
}
],
"interestOverTime_averages": [],
"interestOverTime_timelineData": [
{
"time": "1673136000",
"value": [
99
],
"hasData": [
true
],
"formattedTime": "Jan 8 – 14, 2023",
"formattedValue": [
"99"
],
"formattedAxisTime": "Jan 8, 2023"
},
{
"time": "1673740800",
"value": [
96
],
"hasData": [
true
],
"formattedTime": "Jan 15 – 21, 2023",
"formattedValue": [
"96"
],
"formattedAxisTime": "Jan 15, 2023"
},
{
"time": "1674345600",
"value": [
99
],
"hasData": [
true
],
"formattedTime": "Jan 22 – 28, 2023",
"formattedValue": [
"99"
],
"formattedAxisTime": "Jan 22, 2023"
},
{
"time": "1674950400",
"value": [
98
],
"hasData": [
true
],
"formattedTime": "Jan 29 – Feb 4, 2023",
"formattedValue": [
"98"
],
"formattedAxisTime": "Jan 29, 2023"
},
{
"time": "1675555200",
"value": [
100
],
"hasData": [
true
],
"formattedTime": "Feb 5 – 11, 2023",
"formattedValue": [
"100"
],
"formattedAxisTime": "Feb 5, 2023"
},
{
"time": "1676160000",
"value": [
91
],
"hasData": [
true
],
"formattedTime": "Feb 12 – 18, 2023",
"formattedValue": [
"91"
],
"formattedAxisTime": "Feb 12, 2023"
},
{
"time": "1676764800",
"value": [
98
],
"hasData": [
true
],
"formattedTime": "Feb 19 – 25, 2023",
"formattedValue": [
"98"
],
"formattedAxisTime": "Feb 19, 2023"
},
{
"time": "1703376000",
"value": [
80
],
"hasData": [
true
],
"formattedTime": "Dec 24 – 30, 2023",
"formattedValue": [
"80"
],
"formattedAxisTime": "Dec 24, 2023"
},
{
"time": "1703980800",
"value": [
81
],
"hasData": [
true
],
"formattedTime": "Dec 31, 2023 – Jan 6, 2024",
"formattedValue": [
"81"
],
"formattedAxisTime": "Dec 31, 2023"
},
{
"time": "1704585600",
"value": [
91
],
"hasData": [
true
],
"isPartial": true,
"formattedTime": "Jan 7 – 13, 2024",
"formattedValue": [
"91"
],
"formattedAxisTime": "Jan 7, 2024"
}
]
}
1Sign up for Apify account

Creating an account is quick and free β€” no credit card required. Your account gives you access to more than 5,000 scrapers and APIs.

Get started for free

2Install Apify Python client

Install the Apify Python client using pip: pip install apify-client. This package provides a simple interface to interact with Google Trends API from your Python applications.


3Get your Apify API token

Go to settings in the Apify console and navigate to the β€œAPI & Integrations” tab. There, create a new token and save it for later.


4Integrate Google Trends API

Navigate to the Google Trends API page and click on the API dropdown menu in the top right corner. In the dropdown menu, you can see API clients, API endpoints, and more. Use the provided Python code examples to integrate Google Trends API into your Python application.

Open Google Trends Python API

5Get your Google Trends data via API

The Google Trends API returns structured JSON data that works perfectly with pandas, NumPy, and other Python data analysis libraries.

Why use Apify?

Never get blocked

Every plan (free included) comes with Apify Proxy, which is great for avoiding blocking and giving you access to geo-specific content.

Customers love us

We truly care about the satisfaction of our users and thanks to that we're one of the best-rated data extraction platforms on both G2 and Capterra.

Monitor your runs

With our latest monitoring features, you always have immediate access to valuable insights on the status of your web scraping tasks.

Export to various formats

Your datasets can be exported to any format that suits your data workflow, including Excel, CSV, JSON, XML, HTML table, JSONL, and RSS.

Integrate Apify to your workflow

You can integrate your Apify runs with platforms such as Zapier, Make, Keboola, Google Drive, or GitHub. Connect with practically any cloud service or web app.

Large developer community

Apify is built by developers, so you'll be in good hands if you have any technical questions. Our Discord server is always here to help!

Frequently asked questions