GeneralMills / pytrends

Pseudo API for Google Trends
Other
3.23k stars 817 forks source link

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

back to top

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

back to top

API Methods

The following API methods are available:

back to top

Common API parameters

Many API methods use the following:

back to top

Interest Over Time

pytrends.interest_over_time()

Returns pandas.Dataframe

back to top

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.

back to top

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

back to top

Interest by Region

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

Parameters

Returns pandas.DataFrame

back to top

Related Topics

pytrends.related_topics()

Returns dictionary of pandas.DataFrames

back to top

Related Queries

pytrends.related_queries()

Returns dictionary of pandas.DataFrames

back to top

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

back to top

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

back to top

Top Charts

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

Parameters

Returns pandas.DataFrame

back to top

Suggestions

pytrends.suggestions(keyword)

Parameters

Returns dictionary

back to top

Categories

pytrends.categories()

Returns dictionary

back to top

Caveats

Contributing

See the CONTRIBUTING file.

Credits