google-trends-compare 0.1.0__py3-none-any.whl

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,68 @@
1
+ Metadata-Version: 2.4
2
+ Name: google-trends-compare
3
+ Version: 0.1.0
4
+ Summary: Compare more than 5 keywords in Google Trends on one shared 0-100 scale. A pytrends alternative without 429 errors.
5
+ License-Expression: MIT
6
+ Project-URL: Homepage, https://github.com/sassrami/google-trends-compare
7
+ Project-URL: Hosted scraper, https://apify.com/granola2/google-trends-scraper
8
+ Keywords: google trends,pytrends,pytrends alternative,google trends api,keyword research,seo
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Topic :: Internet :: WWW/HTTP
11
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
12
+ Requires-Python: >=3.10
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: apify-client>=3.5
16
+ Dynamic: license-file
17
+
18
+ # Compare more than 5 keywords in Google Trends (pytrends alternative)
19
+
20
+ Google Trends compares at most 5 keywords at a time, and every request rescales its own top value to 100. Split 12 keywords into batches of 5 and the numbers from different batches can't be compared. On top of that, pytrends is archived and Google answers scripts with HTTP 429.
21
+
22
+ **In Colab?** [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/sassrami/google-trends-compare/blob/main/google_trends_colab.ipynb) Colab is where pytrends fails most (Google Cloud IPs get 429 on the first request). The notebook runs the same comparison, shows a ranking and a chart, and downloads a CSV.
23
+
24
+ `google-trends-compare` gets interest over time for **any number of keywords on one shared 0-100 scale**, as a CSV or a Python dict. It calls a hosted Google Trends scraper on Apify, so there is no rate limiting, cookie handling or proxy setup on your side.
25
+
26
+ ```bash
27
+ pip install google-trends-compare
28
+ export APIFY_TOKEN=... # free account at https://apify.com (Settings > API & Integrations)
29
+ # Windows PowerShell: $env:APIFY_TOKEN = "..."
30
+ google-trends-compare sneakers "running shoes" "trail running shoes" "barefoot shoes" \
31
+ "wide toe box shoes" "minimalist shoes" "walking shoes" "hiking boots" "waterproof shoes" \
32
+ "cross training shoes" "carbon plate running shoes" "zero drop shoes" --geo US
33
+ ```
34
+
35
+ Output (`trends.csv`, real data, US, last 12 months):
36
+
37
+ | date | sneakers | hiking boots | walking shoes | barefoot shoes | zero drop shoes |
38
+ | --- | ---: | ---: | ---: | ---: | ---: |
39
+ | 2025-11-02 | 24 | 1.78 | 2.3 | 0.92 | 0.21 |
40
+ | 2025-11-09 | 25 | 1.88 | 2.3 | 0.92 | 0.21 |
41
+ | 2025-11-16 | 28 | 2.3 | 2.3 | 0.92 | 0.21 |
42
+
43
+ All columns share one scale: averaged over the year, "sneakers" (35.4) is about 160 times "zero drop shoes" (0.22). Fetched in separate batches of 5, those two numbers would come from different scales and could not be compared.
44
+
45
+ Options: `--geo` (country code, empty = worldwide), `--time` (`today 5-y`, `now 7-d`, `2024-01-01 2024-12-31`, ...), `--out` (CSV path).
46
+
47
+ From Python (pandas is optional):
48
+
49
+ ```python
50
+ import pandas as pd
51
+ from google_trends_compare import compare
52
+
53
+ df = pd.DataFrame(compare(["pickleball", "padel", "tennis", "squash", "badminton", "golf"], geo="US"))
54
+ ```
55
+
56
+ `compare()` returns `{keyword: {date: value}}`, so `pd.DataFrame` gives one column per keyword and one row per date. Keywords with no data are left out.
57
+
58
+ ## Cost
59
+
60
+ The scraper charges per result: one keyword's time series is one result, $0.005 or less. 50 keywords cost about $0.25. Keywords Google has no data for are not charged. Apify's free plan includes monthly credit that covers small runs.
61
+
62
+ ## Why not pytrends?
63
+
64
+ pytrends was archived on GitHub in 2025. Google rate-limits Trends per IP, and datacenter and cloud IPs (Colab, AWS, CI) often get 429 on the first request. If you want to keep doing it yourself: a few seconds between requests, a fresh session after each 429, exponential backoff, and residential IPs for volume.
65
+
66
+ ## Disclosure
67
+
68
+ I built and maintain the scraper this calls: [granola2/google-trends-scraper](https://apify.com/granola2/google-trends-scraper). It also returns related queries, interest by region and trending searches. This script is MIT licensed.
@@ -0,0 +1,7 @@
1
+ google_trends_compare.py,sha256=gQTw4lNY-tn88ysJ0paguWrenVi2oMQpYZGz2xFVdFg,2988
2
+ google_trends_compare-0.1.0.dist-info/licenses/LICENSE,sha256=QSuN0XBYAyWs-QP5KZut7NAj-xa0sDNfN0LOsh1KpGw,1065
3
+ google_trends_compare-0.1.0.dist-info/METADATA,sha256=ega_zEqz3YESQ_FFNGlCJXKODULyxdzatN75svbnzFk,4176
4
+ google_trends_compare-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
5
+ google_trends_compare-0.1.0.dist-info/entry_points.txt,sha256=hlaWyn5jeneXnKKjiAcwrui8rZVNV04Y69cSr6qQTd4,69
6
+ google_trends_compare-0.1.0.dist-info/top_level.txt,sha256=etts9dhqG7HNvhAbNtA7jxHoAMnvF_i4LU6Jxiky6p0,22
7
+ google_trends_compare-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ google-trends-compare = google_trends_compare:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Granola2
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.
@@ -0,0 +1 @@
1
+ google_trends_compare
@@ -0,0 +1,74 @@
1
+ """Compare any number of keywords on one Google Trends 0-100 scale.
2
+
3
+ Command line:
4
+ export APIFY_TOKEN=... # free account at apify.com
5
+ google-trends-compare pickleball padel tennis squash badminton golf --geo US
6
+
7
+ Python:
8
+ from google_trends_compare import compare
9
+ data = compare(["pickleball", "padel", "tennis", "squash", "badminton", "golf"], geo="US")
10
+ pandas.DataFrame(data) # one column per keyword, one row per date
11
+
12
+ Writes trends.csv on the command line: one row per date, one column per keyword, all on one scale.
13
+ """
14
+
15
+ import argparse
16
+ import csv
17
+ import os
18
+
19
+ from apify_client import ApifyClient
20
+
21
+ __version__ = "0.1.0"
22
+ ACTOR = "granola2/google-trends-scraper"
23
+
24
+
25
+ def to_series(items: list[dict]) -> dict[str, dict[str, float]]:
26
+ """Turn the Actor's interestOverTime rows into {keyword: {date: value}}, in the Actor's rank order."""
27
+ return {
28
+ i["keyword"]: {p["date"]: p["value"] for p in i["points"]}
29
+ for i in items
30
+ if i.get("report") == "interestOverTime"
31
+ }
32
+
33
+
34
+ def compare(
35
+ keywords: list[str], geo: str = "", time: str = "today 12-m", token: str | None = None
36
+ ) -> dict[str, dict[str, float]]:
37
+ """Return {keyword: {date: value}} for all keywords on one shared 0-100 scale.
38
+
39
+ Keywords without Google Trends data are left out. The token defaults to the APIFY_TOKEN environment variable.
40
+ """
41
+ client = ApifyClient(token or os.environ["APIFY_TOKEN"])
42
+ run = client.actor(ACTOR).call(
43
+ run_input={"keywords": keywords, "geo": geo, "timeRange": time, "reports": ["interestOverTime"]}
44
+ )
45
+ return to_series(client.dataset(run.default_dataset_id).list_items().items)
46
+
47
+
48
+ def to_rows(series: dict[str, dict[str, float]]) -> list[list]:
49
+ """Turn {keyword: {date: value}} into CSV rows: a header, then one date-sorted row per date."""
50
+ dates = sorted({d for points in series.values() for d in points})
51
+ return [["date", *series], *([d] + [points.get(d, "") for points in series.values()] for d in dates)]
52
+
53
+
54
+ def main() -> None:
55
+ """Command-line entry point: fetch the keywords and write a CSV."""
56
+ ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
57
+ ap.add_argument("keywords", nargs="+")
58
+ ap.add_argument("--geo", default="", help="country code like US or DE; empty = worldwide")
59
+ ap.add_argument("--time", default="today 12-m", help="e.g. 'today 5-y', 'now 7-d', '2024-01-01 2024-12-31'")
60
+ ap.add_argument("--out", default="trends.csv")
61
+ args = ap.parse_args()
62
+
63
+ series = compare(args.keywords, args.geo, args.time)
64
+ rows = to_rows(series)
65
+ with open(args.out, "w", newline="", encoding="utf-8") as f:
66
+ csv.writer(f).writerows(rows)
67
+ print(f"Wrote {len(rows) - 1} dates x {len(series)} keywords to {args.out}")
68
+ missing = set(args.keywords) - set(series)
69
+ if missing:
70
+ print("No Google Trends data for:", ", ".join(sorted(missing)))
71
+
72
+
73
+ if __name__ == "__main__":
74
+ main()