gsc-cli 0.2.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.
gsc/models.py ADDED
@@ -0,0 +1,178 @@
1
+ """Dataclasses for Google Search Console API responses.
2
+
3
+ Each model exposes a ``from_api`` classmethod that maps the camelCase fields
4
+ returned by the Google APIs onto snake_case attributes, using ``.get(...)``
5
+ defaults so partial payloads never raise.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from dataclasses import dataclass, field
11
+
12
+
13
+ @dataclass
14
+ class Site:
15
+ """A verified property in Search Console (``webmasters.sites``)."""
16
+
17
+ site_url: str
18
+ permission_level: str = ""
19
+
20
+ @classmethod
21
+ def from_api(cls, data: dict) -> Site:
22
+ return cls(
23
+ site_url=data.get("siteUrl", ""),
24
+ permission_level=data.get("permissionLevel", ""),
25
+ )
26
+
27
+
28
+ @dataclass
29
+ class SearchAnalyticsRow:
30
+ """A single row of a search-analytics query result."""
31
+
32
+ keys: list[str] = field(default_factory=list)
33
+ clicks: float = 0.0
34
+ impressions: float = 0.0
35
+ ctr: float = 0.0
36
+ position: float = 0.0
37
+
38
+ @classmethod
39
+ def from_api(cls, data: dict) -> SearchAnalyticsRow:
40
+ return cls(
41
+ keys=list(data.get("keys", [])),
42
+ clicks=data.get("clicks", 0.0),
43
+ impressions=data.get("impressions", 0.0),
44
+ ctr=data.get("ctr", 0.0),
45
+ position=data.get("position", 0.0),
46
+ )
47
+
48
+
49
+ @dataclass
50
+ class SearchAnalyticsResponse:
51
+ """The envelope returned by ``searchanalytics.query``."""
52
+
53
+ rows: list[SearchAnalyticsRow] = field(default_factory=list)
54
+ response_aggregation_type: str = ""
55
+
56
+ @classmethod
57
+ def from_api(cls, data: dict) -> SearchAnalyticsResponse:
58
+ return cls(
59
+ rows=[SearchAnalyticsRow.from_api(r) for r in data.get("rows", [])],
60
+ response_aggregation_type=data.get("responseAggregationType", ""),
61
+ )
62
+
63
+
64
+ @dataclass
65
+ class SitemapContent:
66
+ """A per-content-type breakdown inside a sitemap entry."""
67
+
68
+ type: str = ""
69
+ submitted: int = 0
70
+ indexed: int = 0
71
+
72
+ @classmethod
73
+ def from_api(cls, data: dict) -> SitemapContent:
74
+ return cls(
75
+ type=data.get("type", ""),
76
+ submitted=int(data.get("submitted", 0)),
77
+ indexed=int(data.get("indexed", 0)),
78
+ )
79
+
80
+
81
+ @dataclass
82
+ class Sitemap:
83
+ """A submitted sitemap (``webmasters.sitemaps``)."""
84
+
85
+ path: str = ""
86
+ last_submitted: str = ""
87
+ last_downloaded: str = ""
88
+ is_pending: bool = False
89
+ is_sitemaps_index: bool = False
90
+ type: str = ""
91
+ warnings: int = 0
92
+ errors: int = 0
93
+ contents: list[SitemapContent] = field(default_factory=list)
94
+
95
+ @classmethod
96
+ def from_api(cls, data: dict) -> Sitemap:
97
+ return cls(
98
+ path=data.get("path", ""),
99
+ last_submitted=data.get("lastSubmitted", ""),
100
+ last_downloaded=data.get("lastDownloaded", ""),
101
+ is_pending=bool(data.get("isPending", False)),
102
+ is_sitemaps_index=bool(data.get("isSitemapsIndex", False)),
103
+ type=data.get("type", ""),
104
+ warnings=int(data.get("warnings", 0)),
105
+ errors=int(data.get("errors", 0)),
106
+ contents=[SitemapContent.from_api(c) for c in data.get("contents", [])],
107
+ )
108
+
109
+
110
+ @dataclass
111
+ class IndexStatus:
112
+ """The index-status verdict for a URL inspection result."""
113
+
114
+ verdict: str = ""
115
+ coverage_state: str = ""
116
+ robots_txt_state: str = ""
117
+ indexing_state: str = ""
118
+ page_fetch_state: str = ""
119
+ google_canonical: str = ""
120
+ user_canonical: str = ""
121
+ last_crawl_time: str = ""
122
+
123
+ @classmethod
124
+ def from_api(cls, data: dict) -> IndexStatus:
125
+ return cls(
126
+ verdict=data.get("verdict", ""),
127
+ coverage_state=data.get("coverageState", ""),
128
+ robots_txt_state=data.get("robotsTxtState", ""),
129
+ indexing_state=data.get("indexingState", ""),
130
+ page_fetch_state=data.get("pageFetchState", ""),
131
+ google_canonical=data.get("googleCanonical", ""),
132
+ user_canonical=data.get("userCanonical", ""),
133
+ last_crawl_time=data.get("lastCrawlTime", ""),
134
+ )
135
+
136
+
137
+ @dataclass
138
+ class InspectionResult:
139
+ """The result of a URL inspection (``urlInspection.index.inspect``)."""
140
+
141
+ inspection_result_link: str = ""
142
+ index_status: IndexStatus | None = None
143
+
144
+ @classmethod
145
+ def from_api(cls, data: dict) -> InspectionResult:
146
+ result = data.get("inspectionResult", data)
147
+ index_status_data = result.get("indexStatusResult")
148
+ return cls(
149
+ inspection_result_link=result.get("inspectionResultLink", ""),
150
+ index_status=(IndexStatus.from_api(index_status_data) if index_status_data else None),
151
+ )
152
+
153
+
154
+ @dataclass
155
+ class Profile:
156
+ """A stored auth profile from ``config.yaml``."""
157
+
158
+ name: str
159
+ auth_type: str = "oauth2"
160
+ credentials: str = ""
161
+ sites: list[str] = field(default_factory=list)
162
+
163
+ @property
164
+ def is_oauth(self) -> bool:
165
+ return self.auth_type == "oauth2"
166
+
167
+ @property
168
+ def is_service_account(self) -> bool:
169
+ return self.auth_type == "service_account"
170
+
171
+ @classmethod
172
+ def from_api(cls, data: dict) -> Profile:
173
+ return cls(
174
+ name=data.get("name", ""),
175
+ auth_type=data.get("auth_type", "oauth2"),
176
+ credentials=data.get("credentials", ""),
177
+ sites=list(data.get("sites", [])),
178
+ )
@@ -0,0 +1,173 @@
1
+ Metadata-Version: 2.5
2
+ Name: gsc-cli
3
+ Version: 0.2.0
4
+ Summary: Google Search Console CLI and backend for Claude Code SEO-analysis skills.
5
+ Project-URL: Homepage, https://seoconsult.bg
6
+ Project-URL: Documentation, https://github.com/seoconsultbg/gsc-cli#readme
7
+ Project-URL: Repository, https://github.com/seoconsultbg/gsc-cli
8
+ Project-URL: Issues, https://github.com/seoconsultbg/gsc-cli/issues
9
+ Author-email: SEO Consult <margpeeva@gmail.com>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: cli,google-search-console,gsc,search-analytics,search-console-api,seo,sitemaps,url-inspection,webmaster-tools
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Environment :: Console
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Intended Audience :: Information Technology
17
+ Classifier: License :: OSI Approved :: MIT License
18
+ Classifier: Operating System :: OS Independent
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Topic :: Internet :: WWW/HTTP :: Indexing/Search
23
+ Classifier: Topic :: Utilities
24
+ Requires-Python: >=3.11
25
+ Requires-Dist: click>=8.1
26
+ Requires-Dist: google-api-python-client>=2.0
27
+ Requires-Dist: google-auth-httplib2>=0.1
28
+ Requires-Dist: google-auth-oauthlib>=1.0
29
+ Requires-Dist: google-auth>=2.0
30
+ Requires-Dist: pyyaml>=6.0
31
+ Requires-Dist: tabulate>=0.9
32
+ Description-Content-Type: text/markdown
33
+
34
+ # gsc-cli
35
+
36
+ [![PyPI version](https://img.shields.io/pypi/v/gsc-cli.svg)](https://pypi.org/project/gsc-cli/)
37
+ [![Python versions](https://img.shields.io/pypi/pyversions/gsc-cli.svg)](https://pypi.org/project/gsc-cli/)
38
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
39
+ [![Ruff](https://img.shields.io/badge/lint-ruff-261230.svg)](https://github.com/astral-sh/ruff)
40
+
41
+ **A fast, scriptable Google Search Console CLI** - pull Search Analytics, inspect
42
+ URLs, and manage sitemaps straight from your terminal, with clean `--format json`
43
+ output that pipes into any tool. It also powers a set of Claude Code SEO-analysis
44
+ skills.
45
+
46
+ > Built and maintained by **[SEO Consult](https://seoconsult.bg)**, a Bulgarian
47
+ > [SEO агенция](https://seoconsult.bg) that lives in Search Console data.
48
+
49
+ ---
50
+
51
+ ## Why gsc-cli
52
+
53
+ - **Everything as JSON.** `--format json` on any command → feed rankings, CTR, and
54
+ impressions into scripts, notebooks, or LLM prompts without scraping the UI.
55
+ - **Search Analytics done right.** Query by `query`, `page`, `country`, `device`,
56
+ or `date`, with repeatable AND-combined `--filter` expressions.
57
+ - **URL Inspection & sitemaps.** Check index coverage for any URL and list/submit/
58
+ delete sitemaps.
59
+ - **Multi-profile auth.** OAuth2 *and* service accounts, with per-site
60
+ auto-detection - juggle many client properties from one config.
61
+ - **Table / CSV / JSON** output for humans and machines alike.
62
+ - **The data the API leaves out.** Google Lens / Circle to Search traffic
63
+ (Web: multimodal) and the Generative AI report (AI Overviews + AI Mode) exist
64
+ only as UI exports. `gsc multimodal` and `gsc genai` parse those exports and
65
+ join them with API numbers for the same dates.
66
+
67
+ ## Install
68
+
69
+ ```bash
70
+ pip install gsc-cli # from PyPI
71
+ # or, for local development:
72
+ uv sync # create venv + install + register the `gsc` binary
73
+ ```
74
+
75
+ ## Quick start
76
+
77
+ ```bash
78
+ export GSC_CLIENT_SECRETS=/path/to/client_secrets.json # from Google Cloud Console
79
+ gsc auth login # OAuth2 browser flow
80
+ gsc sites list # confirm access
81
+
82
+ # Top queries for the last 28 days, as JSON:
83
+ gsc --format json query https://www.example.com/ \
84
+ --start-date 2026-01-01 --end-date 2026-01-28 --dimensions query
85
+ ```
86
+
87
+ `--format` is **global** and precedes the subcommand
88
+ (`gsc --format json query ...`). Filters use `'dimension operator expression'`,
89
+ e.g. `--filter 'query contains running shoes'`.
90
+
91
+ ## Commands
92
+
93
+ | Command | What it does |
94
+ | --- | --- |
95
+ | `gsc auth` | `login`, `add-profile`, `list/remove-profile`, `status` |
96
+ | `gsc sites` | List and inspect verified properties |
97
+ | `gsc query` | Search Analytics (clicks, impressions, CTR, position) |
98
+ | `gsc inspect` | URL Inspection API - index/coverage verdict for a URL |
99
+ | `gsc sitemaps` | `list`, `get`, `submit`, `delete` |
100
+ | `gsc multimodal` | Parse a Web: multimodal export; `--compare` adds the camera share per page |
101
+ | `gsc genai` | Parse a Generative AI report export; `--compare` adds the AI lift index per page |
102
+
103
+ Run `gsc --help` or `gsc <command> --help` for the full flag reference.
104
+
105
+ ## AI Overviews and AI Mode by page
106
+
107
+ The Generative AI report in Search Console shows how often each page appeared
108
+ inside AI Overviews and AI Mode. The API does not return it, so export it from the
109
+ UI (Performance -> Generative AI -> Export -> Download CSV) and run:
110
+
111
+ ```bash
112
+ gsc genai https://www.example.com/ export.zip --compare --start-date 2026-06-22 --end-date 2026-09-21
113
+ ```
114
+
115
+ For every page you get its AI impressions next to its organic clicks, impressions
116
+ and average position, plus `ai_lift`: the page's share of AI impressions divided by
117
+ its share of organic impressions. Above 1, AI uses the page more than its organic
118
+ weight would suggest. Pages with fewer than 100 AI or 1,000 organic impressions are
119
+ marked `qualified: false`, because small numbers give silly ratios.
120
+
121
+ Add `--bands` to see how AI impressions split across position bands (1-3, 4-10,
122
+ 11-20, 21+). On the sites we have checked so far, most AI visibility sits on pages
123
+ ranking 4-10, not in the top 3. Informational pages score high lift. Stock, deals
124
+ and dealer-locator pages score close to zero, because Google rarely shows an AI
125
+ answer for those searches.
126
+
127
+ `--by date` gives the daily series. Put it next to `gsc query --dimensions date`:
128
+ if the AI-to-organic ratio suddenly collapses, check whether Googlebot can still
129
+ reach the site. On one site, a firewall block cut organic impressions by 42% and AI
130
+ impressions by 93%.
131
+
132
+ Some skill files mention companion skills (for example `ai-visibility-tracking`)
133
+ from a larger private setup. They are optional; the `gsc-*` skills work on their own.
134
+
135
+ ## Use with Claude Code
136
+
137
+ `gsc-cli` is the backend for a suite of Claude Code SEO skills (performance
138
+ overviews, cannibalization detection, quick-win opportunities, period compares,
139
+ indexing audits). The skills shell out to `gsc --format json` and reason over the
140
+ output. They ship as a Claude Code plugin in [`plugins/gsc-cli`](plugins/gsc-cli):
141
+
142
+ ```
143
+ /plugin marketplace add seoconsultbg/gsc-cli
144
+ /plugin install gsc-cli@seoconsult
145
+ ```
146
+
147
+ The plugin needs the `gsc` command on your PATH (`uv tool install gsc-cli` or
148
+ `pipx install gsc-cli`). See [CLAUDE.md](CLAUDE.md) for the architecture.
149
+
150
+ ## Configuration
151
+
152
+ Profiles live in `~/.config/gsc/config.yaml` (override with `GSC_CONFIG_DIR`).
153
+ A command resolves its profile by precedence: explicit `--profile`/`$GSC_PROFILE`
154
+ → the profile whose `sites` list contains the target URL → `default`. Full details
155
+ in [CLAUDE.md](CLAUDE.md).
156
+
157
+ ## Contributing
158
+
159
+ Issues and PRs welcome. Lint/format with `ruff` (line-length 100):
160
+
161
+ ```bash
162
+ uv run ruff check .
163
+ uv run pytest
164
+ ```
165
+
166
+ ## License
167
+
168
+ [MIT](LICENSE) - © 2026 [SEO Consult](https://seoconsult.bg).
169
+
170
+ ---
171
+
172
+ <sub>Maintained by the team at <a href="https://seoconsult.bg">SEO Consult</a>. If gsc-cli
173
+ saves you time, a ⭐ on GitHub helps others find it.</sub>
@@ -0,0 +1,21 @@
1
+ gsc/__init__.py,sha256=a-5syabWzOLPY9eJ4hbImuLTB6k_KhN4HBmsfZu8L7s,288
2
+ gsc/auth.py,sha256=3llpbV5YxHZE2NEDb8UcPMjv5sHAn_EPmrR8YmF2i3U,5748
3
+ gsc/benchmarks.py,sha256=MQGP2z6cHUsxfht49ZFliF4KtgqU0wCNUKzZUn2Oxck,1197
4
+ gsc/client.py,sha256=oI1MMbJ92YndJokp2xSMBbIThRe_Dt7-OgayXi9aJCQ,3553
5
+ gsc/formatters.py,sha256=D26b8gaYPxJjwXfYBUPX6fdGrcenRpkTyAa3z9tL3is,1414
6
+ gsc/models.py,sha256=k5Eq3kBAPNqagx9sKsrf1n3z7AC5cOTAPCf80ubtQkw,5270
7
+ gsc/cli/__init__.py,sha256=BGVDA7zJPdZjd980o8pbmhb3WsflV5Bik34DWA5mOzE,108
8
+ gsc/cli/auth_cmd.py,sha256=PQhg7Ag2-Mx6WRKekeLHsK4PGlwZMJxdChHxW-Gue0A,4374
9
+ gsc/cli/genai.py,sha256=6mgdFTZKYIkTqVp-Qpi_YtYJeEzLgTzgZjI44_ZBlg4,9363
10
+ gsc/cli/inspect_cmd.py,sha256=X58EOl_CMz9L0nE_OgGoY0grY13j0VRmsuWDWXSyEkA,791
11
+ gsc/cli/main.py,sha256=yMKjZOhlmhbQkvJi2uFpFrBPetCfw2RwDadCIQGrUzk,1444
12
+ gsc/cli/multimodal.py,sha256=faMKyUUJV8M5b2XWg80PnYEfWZqHeu301ZYcfOZbiQU,7633
13
+ gsc/cli/query.py,sha256=Q_8GoAf38A94NkY1et9DNjAHZdz-CRuAVYy48l5DglQ,3261
14
+ gsc/cli/sitemaps.py,sha256=pgRZpqoQSaP-HDiIDyM3yflIfefnaqCLq09YUufVoxM,2009
15
+ gsc/cli/sites.py,sha256=8tc7b9CTY8l1Q0lQYe0ojcjCMltzpNQCXSq4wP5qSYA,1710
16
+ gsc/data/seo-benchmarks.json,sha256=aIrlvOVfU1gp-gMwFZVCX-yY2nnzkgCYZxTblvkDAYA,2194
17
+ gsc_cli-0.2.0.dist-info/METADATA,sha256=LSlAvxOID7VHcXDoeQJh58HWx3vc1nImWHUVQS-GKGg,7422
18
+ gsc_cli-0.2.0.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
19
+ gsc_cli-0.2.0.dist-info/entry_points.txt,sha256=NGr8BSED4-sSqouJm6BQRJAIoFHgeCDSDYGNfqZ96EQ,41
20
+ gsc_cli-0.2.0.dist-info/licenses/LICENSE,sha256=isCMsWwkyorD4qbJ86GpLLzkQNXSzd1wgAR38BpOPDI,1068
21
+ gsc_cli-0.2.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.32.4
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ gsc = gsc.cli.main:cli
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 SEO Consult
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.