
Security News
Vite Releases Technical Preview of Rolldown-Vite, a Rust-Based Bundler
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
A fork of pytrends with full async/await and retry support.
pip install pytrends-async
from pytrendsasync.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 pytrendsasync.request import TrendReq
pytrends = TrendReq(hl='en-US', tz=360, timeout=10, proxies=['https://34.203.233.13:80',])
timeout(connect, read)
'360'
proxies
['https://34.203.233.13:80','https://35.201.123.31:880', ..., ...]
retries
backoff_factor
{backoff factor} * (2 ^ ({number of total retries} - 1))
seconds. If the backoff_factor is 0.1, then sleep() will sleep for [0.0s, 0.2s, 0.4s, …] between retries. By default, backoff is disabled (set to 0).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
kw_list = ["Blockchain"]
pytrends.build_payload(kw_list, cat=0, timeframe='today 5-y', geo='', gprop='')
Parameters
kw_list
The following API methods are available:
Interest Over Time: returns historical, indexed data for when the keyword was searched most as shown on Google Trends' Interest Over Time section.
Historical Hourly Interest: returns historical, indexed, hourly data for when the keyword was searched most as shown on Google Trends' Interest Over Time section. It sends multiple requests to Google, each retrieving one week of hourly data. It seems like this would be the only way to get historical, hourly data.
Interest by Region: returns data for where the keyword is most searched as shown on Google Trends' Interest by Region section.
Related Topics: returns data for the related keywords to a provided keyword shown on Google Trends' Related Topics section.
Related Queries: returns data for the related keywords to a provided keyword shown on Google Trends' Related Queries section.
Trending Searches: returns data for latest trending searches shown on Google Trends' Trending Searches section.
Top Charts: returns the data for a given topic shown in Google Trends' Top Charts section.
Suggestions: returns a list of additional suggested keywords that can be used to refine a trend search.
Many API methods use the following:
kw_list
keywords to get data for
Example ['Pizza']
Up to five terms in a list: ['Pizza', 'Italian', 'Spaghetti', 'Breadsticks', 'Sausage']
Advanced Keywords
"iron"
will have a drop down of "Iron Chemical Element, Iron Cross, Iron Man, etc"
.https://www.google.com/trends/explore#q=%2Fm%2F025rw19&cmpt=q
"%2Fm%2F025rw19"
is the topic "Iron Chemical Element" to use this with pytrendspytrends.suggestions()
to automate this.cat
cat=
and ends before the next &
or view this wiki page containing all available categories"https://www.google.com/trends/explore#q=pizza&cat=71"
'71'
is the categorygeo
'US'
'US-AL'
'GB-ENG'
tz
'360'
timeframe
Date to start from
Defaults to last 5yrs, 'today 5-y'
.
Everything 'all'
Specific dates, 'YYYY-MM-DD YYYY-MM-DD' example '2016-12-14 2017-01-25'
Specific datetimes, 'YYYY-MM-DDTHH YYYY-MM-DDTHH' example '2017-02-06T10 2017-02-12T07'
Current Time Minus Time Pattern:
By Month: 'today #-m'
where # is the number of months from that date to pull data for
'today 3-m'
would get data from today to 3months agoDaily: 'now #-d'
where # is the number of days from that date to pull data for
'now 7-d'
would get data from the last weekHourly: 'now #-H'
where # is the number of hours from that date to pull data for
'now 1-H'
would get data from the last hourgprop
'images'
images
, news
, youtube
or froogle
(for Google Shopping results)await pytrends.interest_over_time()
Returns pandas.Dataframe
await 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
kw_list
year_start, month_start, day_start, hour_start, year_end, month_end, day_end, hour_end
sleep
Returns pandas.Dataframe
await pytrends.interest_by_region(resolution='COUNTRY', inc_low_vol=True, inc_geo_code=False)
Parameters
resolution
inc_low_vol
inc_geo_code
Returns pandas.DataFrame
await pytrends.related_topics()
Returns dictionary of pandas.DataFrames
await pytrends.related_queries()
Returns dictionary of pandas.DataFrames
await pytrends.trending_searches(pn='united_states') # trending searches in real time for United States
await pytrends.trending_searches(pn='japan') # Japan
Returns pandas.DataFrame
await pytrends.top_charts(date, hl='en-US', tz=300, geo='GLOBAL')
Parameters
date
201611
for November 2016 Top Chart dataReturns pandas.DataFrame
await pytrends.suggestions(keyword)
Parameters
keyword
Returns dictionary
await pytrends.categories()
Returns dictionary
Major JSON revision ideas taken from pat310's JavaScript library
Connecting to google code heavily based off Stack Overflow post
With some ideas pulled from Matt Reid's Google Trends API
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog,
asyncio.sleep
in dailydata.py
retries
and backoff_factor
to TrendsReq.__init__()
. retries
and backoff_factor
are disabled by default (set to 0). These parameters will only affect retrying if proxies are not in use.TrendReq.blacklisted_proxies
instead of removed from the proxies list.dailydata.py
now uses asyncio.sleep
instead of time.sleep
.GetNewProxy()
replaced with internal method _iterate_proxy()
FAQs
Pseudo API for Google Trends with asyncio support.
We found that pytrends-async demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
Research
Security News
A malicious npm typosquat uses remote commands to silently delete entire project directories after a single mistyped install.
Research
Security News
Malicious PyPI package semantic-types steals Solana private keys via transitive dependency installs using monkey patching and blockchain exfiltration.