pytrends-modern 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,37 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 pytrends-modern contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ ---
24
+
25
+ This project incorporates code and ideas from:
26
+
27
+ 1. pytrends (https://github.com/GeneralMills/pytrends)
28
+ - Original Google Trends API implementation
29
+ - License: Apache 2.0
30
+
31
+ 2. trendspyg (https://github.com/flack0x/trendspyg)
32
+ - RSS feed support and modern features
33
+ - License: MIT
34
+
35
+ 3. google-trends Flask app
36
+ - Visualization and retry logic concepts
37
+ - License: MIT
@@ -0,0 +1,6 @@
1
+ include README.md
2
+ include LICENSE
3
+ include pyproject.toml
4
+ recursive-include pytrends_plus *.py py.typed
5
+ recursive-include examples *.py
6
+ recursive-include tests *.py
@@ -0,0 +1,394 @@
1
+ Metadata-Version: 2.4
2
+ Name: pytrends-modern
3
+ Version: 0.1.0
4
+ Summary: Modern Google Trends API - Combining the best of pytrends, with RSS feeds, Selenium scraping, and enhanced features
5
+ Author: pytrends-modern contributors
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/yiromo/pytrends-modern
8
+ Project-URL: Documentation, https://github.com/yiromo/pytrends-modern#readme
9
+ Project-URL: Repository, https://github.com/yiromo/pytrends-modern
10
+ Project-URL: Issues, https://github.com/yiromo/pytrends-modern/issues
11
+ Keywords: google,trends,api,data,scraping,selenium,rss
12
+ Classifier: Development Status :: 5 - Production/Stable
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Requires-Python: >=3.8
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: requests>=2.28.0
26
+ Requires-Dist: pandas>=1.5.0
27
+ Requires-Dist: lxml>=4.9.0
28
+ Provides-Extra: selenium
29
+ Requires-Dist: selenium>=4.0.0; extra == "selenium"
30
+ Requires-Dist: webdriver-manager>=4.0.0; extra == "selenium"
31
+ Provides-Extra: cli
32
+ Requires-Dist: click>=8.0.0; extra == "cli"
33
+ Requires-Dist: rich>=13.0.0; extra == "cli"
34
+ Provides-Extra: export
35
+ Requires-Dist: pyarrow>=10.0.0; extra == "export"
36
+ Requires-Dist: openpyxl>=3.0.0; extra == "export"
37
+ Provides-Extra: dev
38
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
39
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
40
+ Requires-Dist: pytest-vcr>=1.0.2; extra == "dev"
41
+ Requires-Dist: black>=23.0.0; extra == "dev"
42
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
43
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
44
+ Provides-Extra: all
45
+ Requires-Dist: pytrends-modern[cli,export,selenium]; extra == "all"
46
+ Dynamic: license-file
47
+
48
+ # pytrends-modern
49
+
50
+ **The Modern Google Trends API** - Combining the best features from pytrends, trendspyg, and more.
51
+
52
+ [![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
53
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
54
+
55
+ ## ๐ŸŒŸ Why pytrends-modern?
56
+
57
+ pytrends-modern is a **next-generation** Google Trends library that combines:
58
+
59
+ - โœ… **All classic pytrends features** - Interest over time, by region, related topics/queries
60
+ - โœ… **RSS Feed Support** - Fast real-time trending data with rich media (0.2s vs 10s)
61
+ - โœ… **Enhanced Error Handling** - Automatic retries, rate limit management, proxy rotation
62
+ - โœ… **Modern Python** - Full type hints, async support, dataclasses
63
+ - โœ… **Selenium Integration** - Advanced scraping when needed
64
+ - โœ… **Multiple Export Formats** - CSV, JSON, Parquet, Excel, DataFrame
65
+ - โœ… **Comprehensive CLI** - Easy command-line interface with rich output
66
+ - โœ… **Better Rate Limiting** - Smart backoff, quota management
67
+ - โœ… **Active Maintenance** - Modern codebase, actively maintained
68
+
69
+ ## ๐Ÿš€ Quick Start
70
+
71
+ ### Installation
72
+
73
+ ```bash
74
+ # Basic installation
75
+ pip install pytrends-modern
76
+
77
+ # With Selenium support (for advanced scraping)
78
+ pip install pytrends-modern[selenium]
79
+
80
+ # With CLI support
81
+ pip install pytrends-modern[cli]
82
+
83
+ # With all features
84
+ pip install pytrends-modern[all]
85
+ ```
86
+
87
+ ### Basic Usage
88
+
89
+ ```python
90
+ from pytrends_plus import TrendReq
91
+
92
+ # Initialize
93
+ pytrends = TrendReq(hl='en-US', tz=360)
94
+
95
+ # Build payload
96
+ pytrends.build_payload(
97
+ kw_list=['Python', 'JavaScript'],
98
+ timeframe='today 12-m',
99
+ geo='US'
100
+ )
101
+
102
+ # Get interest over time
103
+ interest_df = pytrends.interest_over_time()
104
+ print(interest_df.head())
105
+
106
+ # Get interest by region
107
+ region_df = pytrends.interest_by_region()
108
+ print(region_df.head())
109
+
110
+ # Get related queries
111
+ related = pytrends.related_queries()
112
+ print(related['Python']['top'])
113
+ ```
114
+
115
+ ### RSS Feed (Fast Real-Time Data)
116
+
117
+ ```python
118
+ from pytrends_plus import TrendsRSS
119
+
120
+ # Get trending searches with rich media
121
+ rss = TrendsRSS()
122
+ trends = rss.get_trends(geo='US')
123
+
124
+ for trend in trends:
125
+ print(f"Title: {trend['title']}")
126
+ print(f"Traffic: {trend['traffic']}")
127
+ print(f"Articles: {len(trend['articles'])}")
128
+ print(f"Image: {trend['picture']}")
129
+ print("---")
130
+ ```
131
+
132
+ ### CLI Usage
133
+
134
+ ```bash
135
+ # Get interest over time
136
+ pytrends-modern interest --keywords "Python,JavaScript" --timeframe "today 12-m"
137
+
138
+ # Get trending searches
139
+ pytrends-modern trending --geo US
140
+
141
+ # Get RSS feed
142
+ pytrends-modern rss --geo US --format json
143
+
144
+ # Export to CSV
145
+ pytrends-modern interest --keywords "AI" --output trends.csv
146
+ ```
147
+
148
+ ## ๐Ÿ“Š Features Comparison
149
+
150
+ | Feature | pytrends | trendspyg | pytrends-modern |
151
+ |---------|----------|-----------|---------------|
152
+ | Interest Over Time | โœ… | โŒ | โœ… |
153
+ | Interest by Region | โœ… | โŒ | โœ… |
154
+ | Related Topics/Queries | โœ… | โŒ | โœ… |
155
+ | RSS Feed | โŒ | โœ… | โœ… |
156
+ | Rich Media (Images/Articles) | โŒ | โœ… | โœ… |
157
+ | Selenium Support | โŒ | โœ… | โœ… |
158
+ | Type Hints | โŒ | โœ… | โœ… |
159
+ | Async Support | โŒ | โŒ | โœ… |
160
+ | CLI | โŒ | โœ… | โœ… |
161
+ | Active Maintenance | โŒ | โœ… | โœ… |
162
+ | Auto Retry | Partial | โœ… | โœ… |
163
+ | Multiple Export Formats | โŒ | โœ… | โœ… |
164
+
165
+ ## ๐ŸŽฏ Key Features
166
+
167
+ ### 1. Classic Trends Data
168
+ All the beloved pytrends methods, modernized:
169
+ - `interest_over_time()` - Historical search interest
170
+ - `interest_by_region()` - Geographic distribution
171
+ - `related_topics()` - Related topics
172
+ - `related_queries()` - Related searches
173
+ - `trending_searches()` - Current trending searches
174
+ - `today_searches()` - Daily trends
175
+ - `realtime_trending_searches()` - Real-time trends
176
+ - `suggestions()` - Keyword suggestions
177
+
178
+ ### 2. RSS Feed Support
179
+ Fast access to real-time trending data:
180
+ - **0.2 seconds** vs 10+ seconds for full scraping
181
+ - Rich media: images, news articles, headlines
182
+ - Perfect for monitoring and journalism
183
+ - Multiple geo support (125+ countries)
184
+
185
+ ### 3. Enhanced Error Handling
186
+ - Automatic retry with exponential backoff
187
+ - Rate limit detection and management
188
+ - Proxy rotation support
189
+ - Better error messages
190
+
191
+ ### 4. Modern Python Features
192
+ - Full type hints for IDE support
193
+ - Async/await support for concurrent requests
194
+ - Dataclasses for structured data
195
+ - Modern exception handling
196
+
197
+ ### 5. Selenium Integration
198
+ - Fallback for advanced scraping needs
199
+ - Handles JavaScript-rendered content
200
+ - Automatic driver management
201
+ - Headless mode support
202
+
203
+ ### 6. Multiple Export Formats
204
+ ```python
205
+ # Export to various formats
206
+ df = pytrends.interest_over_time()
207
+
208
+ # CSV
209
+ df.to_csv('trends.csv')
210
+
211
+ # JSON
212
+ pytrends.to_json('trends.json')
213
+
214
+ # Parquet (requires pyarrow)
215
+ pytrends.to_parquet('trends.parquet')
216
+
217
+ # Excel (requires openpyxl)
218
+ df.to_excel('trends.xlsx')
219
+ ```
220
+
221
+ ## ๐Ÿ“š Documentation
222
+
223
+ ### TrendReq Class
224
+
225
+ The main class for Google Trends API access.
226
+
227
+ ```python
228
+ TrendReq(
229
+ hl='en-US', # Language
230
+ tz=360, # Timezone offset
231
+ geo='', # Geographic location
232
+ timeout=(2, 5), # (connect, read) timeouts
233
+ proxies=None, # Proxy list or dict
234
+ retries=3, # Number of retries
235
+ backoff_factor=0.3, # Backoff multiplier
236
+ verify_ssl=True # SSL verification
237
+ )
238
+ ```
239
+
240
+ ### Build Payload
241
+
242
+ ```python
243
+ pytrends.build_payload(
244
+ kw_list=['keyword1', 'keyword2'], # Max 5 keywords
245
+ cat=0, # Category (0 = all)
246
+ timeframe='today 5-y', # Time range
247
+ geo='', # Geographic location
248
+ gprop='' # Property ('', 'images', 'news', 'youtube', 'froogle')
249
+ )
250
+ ```
251
+
252
+ ### Time Frames
253
+ - `'now 1-H'` - Last hour
254
+ - `'now 4-H'` - Last 4 hours
255
+ - `'now 1-d'` - Last day
256
+ - `'now 7-d'` - Last 7 days
257
+ - `'today 1-m'` - Past 30 days
258
+ - `'today 3-m'` - Past 90 days
259
+ - `'today 12-m'` - Past 12 months
260
+ - `'today 5-y'` - Past 5 years (default)
261
+ - `'all'` - Since 2004
262
+ - `'YYYY-MM-DD YYYY-MM-DD'` - Custom range
263
+
264
+ ### Geographic Codes
265
+ Use ISO 3166-1 alpha-2 country codes:
266
+ - `'US'` - United States
267
+ - `'GB'` - United Kingdom
268
+ - `'US-CA'` - California (US states)
269
+ - `'FR'` - France
270
+ - etc.
271
+
272
+ ### Categories
273
+ Common category codes:
274
+ - `0` - All categories
275
+ - `3` - Arts & Entertainment
276
+ - `7` - Business & Industrial
277
+ - `16` - News
278
+ - `20` - Sports
279
+ - `32` - Science
280
+ - More at: https://github.com/pat310/google-trends-api/wiki/Google-Trends-Categories
281
+
282
+ ## ๐Ÿ”ง Advanced Usage
283
+
284
+ ### Proxy Support
285
+
286
+ ```python
287
+ # List of proxies
288
+ pytrends = TrendReq(
289
+ proxies=['https://proxy1.com:8080', 'https://proxy2.com:8080'],
290
+ retries=3
291
+ )
292
+
293
+ # Dict format
294
+ pytrends = TrendReq(
295
+ proxies={
296
+ 'http': 'http://proxy.com:8080',
297
+ 'https': 'https://proxy.com:8080'
298
+ }
299
+ )
300
+ ```
301
+
302
+ ### Async Support
303
+
304
+ ```python
305
+ import asyncio
306
+ from pytrends_plus import AsyncTrendReq
307
+
308
+ async def get_trends():
309
+ pytrends = AsyncTrendReq(hl='en-US')
310
+ await pytrends.build_payload(['Python', 'JavaScript'])
311
+ df = await pytrends.interest_over_time()
312
+ return df
313
+
314
+ df = asyncio.run(get_trends())
315
+ ```
316
+
317
+ ### Rate Limit Handling
318
+
319
+ ```python
320
+ from pytrends_plus import TrendReq
321
+ from pytrends_plus.exceptions import TooManyRequestsError
322
+
323
+ pytrends = TrendReq(retries=5, backoff_factor=0.5)
324
+
325
+ try:
326
+ pytrends.build_payload(['keyword'])
327
+ df = pytrends.interest_over_time()
328
+ except TooManyRequestsError:
329
+ print("Rate limited. Wait before retrying.")
330
+ ```
331
+
332
+ ### Batch Processing
333
+
334
+ ```python
335
+ from pytrends_plus import TrendReq
336
+ import time
337
+
338
+ keywords = ['Python', 'JavaScript', 'Rust', 'Go', 'Java']
339
+ pytrends = TrendReq()
340
+
341
+ results = {}
342
+ for kw in keywords:
343
+ pytrends.build_payload([kw], timeframe='today 12-m')
344
+ results[kw] = pytrends.interest_over_time()
345
+ time.sleep(2) # Avoid rate limits
346
+ ```
347
+
348
+ ## ๐Ÿงช Testing
349
+
350
+ ```bash
351
+ # Run tests
352
+ pytest
353
+
354
+ # With coverage
355
+ pytest --cov=pytrends_plus
356
+
357
+ # Specific test
358
+ pytest tests/test_request.py::test_interest_over_time
359
+ ```
360
+
361
+ ## ๐Ÿค Contributing
362
+
363
+ Contributions are welcome! Please:
364
+ 1. Fork the repository
365
+ 2. Create a feature branch
366
+ 3. Add tests for new features
367
+ 4. Ensure all tests pass
368
+ 5. Submit a pull request
369
+
370
+ ## ๐Ÿ“ License
371
+
372
+ MIT License - see LICENSE file for details
373
+
374
+ ## ๐Ÿ™ Credits
375
+
376
+ This project builds upon and combines features from:
377
+ - [pytrends](https://github.com/GeneralMills/pytrends) - Original Google Trends API
378
+ - [trendspyg](https://github.com/flack0x/trendspyg) - RSS feed support and modern features
379
+ - [google-trends Flask app](https://github.com/flack0x/google-trends) - Visualization and retry logic
380
+
381
+ ## ๐Ÿ“Š Changelog
382
+
383
+ ### Version 1.0.0 (2025-12-26)
384
+ - Initial release
385
+ - Combined pytrends, trendspyg, and google-trends features
386
+ - Added async support
387
+ - Full type hints
388
+ - Enhanced error handling
389
+ - CLI interface
390
+ - Multiple export formats
391
+
392
+ ## โš ๏ธ Disclaimer
393
+
394
+ 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.