Modern Google Trends API - Combining the best of pytrends, with RSS feeds, Selenium scraping, and enhanced features
Project description
pytrends-modern
The Modern Google Trends API - Combining the best features from pytrends, trendspyg, and more.
๐ Why pytrends-modern?
pytrends-modern is a next-generation Google Trends library that combines:
- โ All classic pytrends features - Interest over time, by region, related topics/queries
- โ RSS Feed Support - Fast real-time trending data with rich media (0.2s vs 10s)
- โ Enhanced Error Handling - Automatic retries, rate limit management, proxy rotation
- โ Modern Python - Full type hints, async support, dataclasses
- โ Selenium Integration - Advanced scraping when needed
- โ Multiple Export Formats - CSV, JSON, Parquet, Excel, DataFrame
- โ Comprehensive CLI - Easy command-line interface with rich output
- โ Better Rate Limiting - Smart backoff, quota management
- โ Active Maintenance - Modern codebase, actively maintained
๐ Quick Start
Installation
# Basic installation
pip install pytrends-modern
# With Selenium support (for advanced scraping)
pip install pytrends-modern[selenium]
# With CLI support
pip install pytrends-modern[cli]
# With all features
pip install pytrends-modern[all]
Basic Usage
from pytrends_plus import TrendReq
# Initialize
pytrends = TrendReq(hl='en-US', tz=360)
# Build payload
pytrends.build_payload(
kw_list=['Python', 'JavaScript'],
timeframe='today 12-m',
geo='US'
)
# Get interest over time
interest_df = pytrends.interest_over_time()
print(interest_df.head())
# Get interest by region
region_df = pytrends.interest_by_region()
print(region_df.head())
# Get related queries
related = pytrends.related_queries()
print(related['Python']['top'])
RSS Feed (Fast Real-Time Data)
from pytrends_plus import TrendsRSS
# Get trending searches with rich media
rss = TrendsRSS()
trends = rss.get_trends(geo='US')
for trend in trends:
print(f"Title: {trend['title']}")
print(f"Traffic: {trend['traffic']}")
print(f"Articles: {len(trend['articles'])}")
print(f"Image: {trend['picture']}")
print("---")
CLI Usage
# Get interest over time
pytrends-modern interest --keywords "Python,JavaScript" --timeframe "today 12-m"
# Get trending searches
pytrends-modern trending --geo US
# Get RSS feed
pytrends-modern rss --geo US --format json
# Export to CSV
pytrends-modern interest --keywords "AI" --output trends.csv
๐ Features Comparison
| Feature | pytrends | trendspyg | pytrends-modern |
|---|---|---|---|
| Interest Over Time | โ | โ | โ |
| Interest by Region | โ | โ | โ |
| Related Topics/Queries | โ | โ | โ |
| RSS Feed | โ | โ | โ |
| Rich Media (Images/Articles) | โ | โ | โ |
| Selenium Support | โ | โ | โ |
| Type Hints | โ | โ | โ |
| Async Support | โ | โ | โ |
| CLI | โ | โ | โ |
| Active Maintenance | โ | โ | โ |
| Auto Retry | Partial | โ | โ |
| Multiple Export Formats | โ | โ | โ |
๐ฏ Key Features
1. Classic Trends Data
All the beloved pytrends methods, modernized:
interest_over_time()- Historical search interestinterest_by_region()- Geographic distributionrelated_topics()- Related topicsrelated_queries()- Related searchestrending_searches()- Current trending searchestoday_searches()- Daily trendsrealtime_trending_searches()- Real-time trendssuggestions()- Keyword suggestions
2. RSS Feed Support
Fast access to real-time trending data:
- 0.2 seconds vs 10+ seconds for full scraping
- Rich media: images, news articles, headlines
- Perfect for monitoring and journalism
- Multiple geo support (125+ countries)
3. Enhanced Error Handling
- Automatic retry with exponential backoff
- Rate limit detection and management
- Proxy rotation support
- Better error messages
4. Modern Python Features
- Full type hints for IDE support
- Async/await support for concurrent requests
- Dataclasses for structured data
- Modern exception handling
5. Selenium Integration
- Fallback for advanced scraping needs
- Handles JavaScript-rendered content
- Automatic driver management
- Headless mode support
6. Multiple Export Formats
# Export to various formats
df = pytrends.interest_over_time()
# CSV
df.to_csv('trends.csv')
# JSON
pytrends.to_json('trends.json')
# Parquet (requires pyarrow)
pytrends.to_parquet('trends.parquet')
# Excel (requires openpyxl)
df.to_excel('trends.xlsx')
๐ Documentation
TrendReq Class
The main class for Google Trends API access.
TrendReq(
hl='en-US', # Language
tz=360, # Timezone offset
geo='', # Geographic location
timeout=(2, 5), # (connect, read) timeouts
proxies=None, # Proxy list or dict
retries=3, # Number of retries
backoff_factor=0.3, # Backoff multiplier
verify_ssl=True # SSL verification
)
Build Payload
pytrends.build_payload(
kw_list=['keyword1', 'keyword2'], # Max 5 keywords
cat=0, # Category (0 = all)
timeframe='today 5-y', # Time range
geo='', # Geographic location
gprop='' # Property ('', 'images', 'news', 'youtube', 'froogle')
)
Time Frames
'now 1-H'- Last hour'now 4-H'- Last 4 hours'now 1-d'- Last day'now 7-d'- Last 7 days'today 1-m'- Past 30 days'today 3-m'- Past 90 days'today 12-m'- Past 12 months'today 5-y'- Past 5 years (default)'all'- Since 2004'YYYY-MM-DD YYYY-MM-DD'- Custom range
Geographic Codes
Use ISO 3166-1 alpha-2 country codes:
'US'- United States'GB'- United Kingdom'US-CA'- California (US states)'FR'- France- etc.
Categories
Common category codes:
0- All categories3- Arts & Entertainment7- Business & Industrial16- News20- Sports32- Science- More at: https://github.com/pat310/google-trends-api/wiki/Google-Trends-Categories
๐ง Advanced Usage
Proxy Support
# List of proxies
pytrends = TrendReq(
proxies=['https://proxy1.com:8080', 'https://proxy2.com:8080'],
retries=3
)
# Dict format
pytrends = TrendReq(
proxies={
'http': 'http://proxy.com:8080',
'https': 'https://proxy.com:8080'
}
)
Async Support
import asyncio
from pytrends_plus import AsyncTrendReq
async def get_trends():
pytrends = AsyncTrendReq(hl='en-US')
await pytrends.build_payload(['Python', 'JavaScript'])
df = await pytrends.interest_over_time()
return df
df = asyncio.run(get_trends())
Rate Limit Handling
from pytrends_plus import TrendReq
from pytrends_plus.exceptions import TooManyRequestsError
pytrends = TrendReq(retries=5, backoff_factor=0.5)
try:
pytrends.build_payload(['keyword'])
df = pytrends.interest_over_time()
except TooManyRequestsError:
print("Rate limited. Wait before retrying.")
Batch Processing
from pytrends_plus import TrendReq
import time
keywords = ['Python', 'JavaScript', 'Rust', 'Go', 'Java']
pytrends = TrendReq()
results = {}
for kw in keywords:
pytrends.build_payload([kw], timeframe='today 12-m')
results[kw] = pytrends.interest_over_time()
time.sleep(2) # Avoid rate limits
๐งช Testing
# Run tests
pytest
# With coverage
pytest --cov=pytrends_plus
# Specific test
pytest tests/test_request.py::test_interest_over_time
๐ค Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new features
- Ensure all tests pass
- Submit a pull request
๐ License
MIT License - see LICENSE file for details
๐ Credits
This project builds upon and combines features from:
- pytrends - Original Google Trends API
- trendspyg - RSS feed support and modern features
- google-trends Flask app - Visualization and retry logic
๐ Changelog
Version 1.0.0 (2025-12-26)
- Initial release
- Combined pytrends, trendspyg, and google-trends features
- Added async support
- Full type hints
- Enhanced error handling
- CLI interface
- Multiple export formats
โ ๏ธ Disclaimer
This is an unofficial library and is not affiliated with or endorsed by Google. Use responsibly and in accordance with Google's Terms of Service.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytrends_modern-0.1.0.tar.gz.
File metadata
- Download URL: pytrends_modern-0.1.0.tar.gz
- Upload date:
- Size: 31.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69f63ee3df7d779b40bab74b0a3742da74622480c764766b833ce239fc43506b
|
|
| MD5 |
43d5aa10c505c0712ca562639baa8654
|
|
| BLAKE2b-256 |
4b47ac45a58c762baa8e169328af6c02eb14eae8edb974490e1330c403d8dee5
|
File details
Details for the file pytrends_modern-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pytrends_modern-0.1.0-py3-none-any.whl
- Upload date:
- Size: 25.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ecc8d908eecefee3fe4089d98feb2216819eef5736ad22ec699d0cefeaaacbf8
|
|
| MD5 |
fbdd6af15337504a818c6752c806feb9
|
|
| BLAKE2b-256 |
5ecc9a9f8851833d930a0aff3b8f5a6cceb55824a356511fcb8c21f7dec41763
|