A Python library for accessing Google Trends data
Low maintenance activity. Last release 23 months ago, commits in 0 of the last 26 weeks. Weaker on commit activity and recent releases.
pip install trendspyTrendsPy
Python library for accessing Google Trends data.
Key Features
Explore
- Track popularity over time (
interest_over_time) - Analyze geographic distribution (
interest_by_region) - Compare interest across different timeframes and regions (multirange support)
- Get related queries and topics (
related_queries,related_topics)
Trending Now
- Access current trending searches (
trending_now,trending_now_by_rss) - Get related news articles (
trending_now_news_by_ids) - Retrieve historical data for 500+ trending keywords with independent normalization (
trending_now_showcase_timeline)
Search Utilities
- Find category IDs (
categories) - Search for location codes (
geo)
Flexible Time Formats
- Custom intervals:
'now 123-H','today 45-d' - Date-based offsets:
'2024-02-01 10-d' - Standard ranges:
'2024-01-01 2024-12-31'
Installation
pip install trendspy
Basic Usage
from trendspy import Trends
tr = Trends()
df = tr.interest_over_time(['python', 'javascript'])
df.plot(title='Python vs JavaScript Interest Over Time',
figsize=(12, 6))
# Analyze geographic distribution
geo_df = tr.interest_by_region('python')
# Get related queries
related = tr.related_queries('python')
Advanced Features
Search Categories and Locations
# Find technology-related categories
categories = tr.categories(find='technology')
# Output: [{'name': 'Computers & Electronics', 'id': '13'}, ...]
# Search for locations
locations = tr.geo(find='york')
# Output: [{'name': 'New York', 'id': 'US-NY'}, ...]
# Use in queries
df = tr.interest_over_time(
'python',
geo='US-NY', # Found location ID
cat='13' # Found category ID
)
Real-time Trending Searches and News
# Get current trending searches in the US
trends = tr.trending_now(geo='US')
# Get trending searches with news articles
trends_with_news = tr.trending_now_by_rss(geo='US')
print(trends_with_news[0]) # First trending topic
print(trends_with_news[0].news[0]) # Associated news article
# Get news articles for specific trending topics
news = tr.trending_now_news_by_ids(
trends[0].news_tokens, # News tokens from trending topic
max_news=3 # Number of articles to retrieve
)
for article in news:
print(f"Title: {article.title}")
print(f"Source: {article.source}")
print(f"URL: {article.url}\n")