Home

Awesome

pytrends

Introduction

Unofficial API for Google Trends

Allows simple interface for automating downloading of reports from Google Trends. Only good until Google changes their backend again :-P. When that happens feel free to contribute!

Looking for maintainers! Please open an issue with a method of contacting you if you're interested.

Table of Contents

Installation

pip install pytrends

Requirements

<sub><sup>back to top</sub></sup>

API

Connect to Google

from pytrends.request import TrendReq

pytrends = TrendReq(hl='en-US', tz=360)

or if you want to use proxies as you are blocked due to Google rate limit:

from pytrends.request import TrendReq

pytrends = TrendReq(hl='en-US', tz=360, timeout=(10,25), proxies=['https://34.203.233.13:80',], retries=2, backoff_factor=0.1, requests_args={'verify':False})

Note: the parameter hl specifies host language for accessing Google Trends. Note: only https proxies will work, and you need to add the port number after the proxy ip address

Build Payload

kw_list = ["Blockchain"]
pytrends.build_payload(kw_list, cat=0, timeframe='today 5-y', geo='', gprop='')

Parameters

<sub><sup>back to top</sub></sup>

API Methods

The following API methods are available:

<sub><sup>back to top</sub></sup>

Common API parameters

Many API methods use the following:

<sub><sup>back to top</sub></sup>

Interest Over Time

pytrends.interest_over_time()

Returns pandas.Dataframe

<sub><sup>back to top</sub></sup>

Multirange Interest Over Time

pytrends.build_payload(kw_list=['pizza', 'bagel'], timeframe=['2022-09-04 2022-09-10', '2022-09-18 2022-09-24']))
pytrends.multirange_interest_over_time()

Returns pandas.Dataframe. It includes the average in the first row.

<sub><sup>back to top</sub></sup>

Historical Hourly Interest

pytrends.get_historical_interest(kw_list, year_start=2018, month_start=1, day_start=1, hour_start=0, year_end=2018, month_end=2, day_end=1, hour_end=0, cat=0, geo='', gprop='', sleep=0)

Parameters

Returns pandas.Dataframe

<sub><sup>back to top</sub></sup>

Interest by Region

pytrends.interest_by_region(resolution='COUNTRY', inc_low_vol=True, inc_geo_code=False)

Parameters

Returns pandas.DataFrame

<sub><sup>back to top</sub></sup>

Related Topics

pytrends.related_topics()

Returns dictionary of pandas.DataFrames

<sub><sup>back to top</sub></sup>

Related Queries

pytrends.related_queries()

Returns dictionary of pandas.DataFrames

<sub><sup>back to top</sub></sup>

Trending Searches

pytrends.trending_searches(pn='united_states') # trending searches in real time for United States
pytrends.trending_searches(pn='japan') # Japan

Returns pandas.DataFrame

<sub><sup>back to top</sub></sup>

Realtime Search Trends

pytrends.realtime_trending_searches(pn='US') # realtime search trends for United States
pytrends.realtime_trending_searches(pn='IN') # India

Returns pandas.DataFrame

<sub><sup>back to top</sub></sup>

Top Charts

pytrends.top_charts(date, hl='en-US', tz=300, geo='GLOBAL')

Parameters

Returns pandas.DataFrame

<sub><sup>back to top</sub></sup>

Suggestions

pytrends.suggestions(keyword)

Parameters

Returns dictionary

<sub><sup>back to top</sub></sup>

Categories

pytrends.categories()

Returns dictionary

<sub><sup>back to top</sub></sup>

Caveats

Contributing

See the CONTRIBUTING file.

Credits