web-auditor 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.
- web_auditor-0.1.0/.gitignore +6 -0
- web_auditor-0.1.0/CHANGELOG.md +13 -0
- web_auditor-0.1.0/LICENSE +21 -0
- web_auditor-0.1.0/PKG-INFO +214 -0
- web_auditor-0.1.0/README.md +194 -0
- web_auditor-0.1.0/pyproject.toml +44 -0
- web_auditor-0.1.0/src/web_auditor/__init__.py +42 -0
- web_auditor-0.1.0/src/web_auditor/_client.py +212 -0
- web_auditor-0.1.0/src/web_auditor/_errors.py +102 -0
- web_auditor-0.1.0/src/web_auditor/_object.py +38 -0
- web_auditor-0.1.0/src/web_auditor/_operations.py +44 -0
- web_auditor-0.1.0/src/web_auditor/_resources.py +402 -0
- web_auditor-0.1.0/src/web_auditor/_version.py +1 -0
- web_auditor-0.1.0/src/web_auditor/py.typed +0 -0
- web_auditor-0.1.0/src/web_auditor/webhooks.py +65 -0
- web_auditor-0.1.0/tests/__init__.py +0 -0
- web_auditor-0.1.0/tests/conftest.py +62 -0
- web_auditor-0.1.0/tests/test_client.py +172 -0
- web_auditor-0.1.0/tests/test_contract.py +117 -0
- web_auditor-0.1.0/tests/test_package.py +9 -0
- web_auditor-0.1.0/tests/test_resources.py +188 -0
- web_auditor-0.1.0/tests/test_webhooks.py +51 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 — 2026-09-24
|
|
4
|
+
|
|
5
|
+
First release of the official Python client.
|
|
6
|
+
|
|
7
|
+
- Every public API operation: URL audits, monitors (with `wait` and `report_pdf`), batches, report shares, webhook endpoints and
|
|
8
|
+
deliveries, usage, status and the check catalogue.
|
|
9
|
+
- Monitors: `monitors.run` / `list_runs`, with run `regressions` and the `monitor.*` webhook events.
|
|
10
|
+
- Site audits (with the site-level `report` and `site_audit.*` events): `site_audits.create/retrieve/list/list_pages/cancel/wait`.
|
|
11
|
+
- Brand audits: `brand_audits.create/retrieve/list/wait` (mentions, citations and share of voice vs competitors).
|
|
12
|
+
- Automatic retries with backoff and `Retry-After`, idempotency keys on every POST, typed errors, auto-pagination.
|
|
13
|
+
- `web_auditor.webhooks.construct_event` / `verify_signature` for `WA-Signature`.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Enfection
|
|
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,214 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: web-auditor
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Official Python client for the Web Auditor public API: AI-visibility (AEO/GEO) audits of web pages.
|
|
5
|
+
Project-URL: Documentation, https://api.web-auditor.enfection.com/docs
|
|
6
|
+
Author: Enfection
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Keywords: aeo,ai-search,api,geo,seo,web-auditor
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Typing :: Typed
|
|
15
|
+
Requires-Python: >=3.9
|
|
16
|
+
Requires-Dist: httpx<1,>=0.25
|
|
17
|
+
Provides-Extra: test
|
|
18
|
+
Requires-Dist: pytest>=8; extra == 'test'
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# Web Auditor Python SDK
|
|
22
|
+
|
|
23
|
+
The official Python client for the [Web Auditor public API](https://api.web-auditor.enfection.com/docs): audit how
|
|
24
|
+
well a page can be found, read and cited by AI answer engines.
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install web-auditor
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Requires Python 3.9+.
|
|
31
|
+
|
|
32
|
+
## Quick start
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from web_auditor import WebAuditor
|
|
36
|
+
|
|
37
|
+
client = WebAuditor(api_key="wa_test_…") # or set WEB_AUDITOR_API_KEY
|
|
38
|
+
|
|
39
|
+
audit = client.url_audits.create(url="https://example.com/pricing")
|
|
40
|
+
audit = client.url_audits.wait(audit.id)
|
|
41
|
+
|
|
42
|
+
print(audit.status, audit.report.score)
|
|
43
|
+
for check in audit.report.checks:
|
|
44
|
+
if check.status == "fail":
|
|
45
|
+
print(check.id, check.fix)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Test keys (`wa_test_…`) return a realistic sample report immediately and cost nothing — build your integration with
|
|
49
|
+
one, then switch to a live key.
|
|
50
|
+
|
|
51
|
+
Responses are `ApiObject`s: dicts that also allow attribute access (`audit.report.score` or
|
|
52
|
+
`audit["report"]["score"]`). `to_dict()` returns plain dicts.
|
|
53
|
+
|
|
54
|
+
## What's covered
|
|
55
|
+
|
|
56
|
+
| Resource | Methods |
|
|
57
|
+
|---|---|
|
|
58
|
+
| `client.url_audits` | `create`, `retrieve`, `list`, `cancel`, `artifacts`, `report_pdf`, `wait` |
|
|
59
|
+
| `client.url_audit_batches` | `create`, `retrieve`, `list`, `cancel`, `wait` |
|
|
60
|
+
| `client.report_shares` | `create`, `list`, `revoke` |
|
|
61
|
+
| `client.site_audits` | `create`, `retrieve`, `list`, `list_pages`, `cancel`, `wait` |
|
|
62
|
+
| `client.brand_audits` | `create`, `retrieve`, `list`, `wait` |
|
|
63
|
+
| `client.monitors` | `create`, `retrieve`, `list`, `update`, `pause`, `resume`, `delete`, `run`, `list_runs` |
|
|
64
|
+
| `client.webhook_endpoints` | `create`, `retrieve`, `list`, `delete`, `send_test_event`, `rotate_secret` |
|
|
65
|
+
| `client.webhook_deliveries` | `list`, `retrieve`, `replay` |
|
|
66
|
+
| `client.usage`, `client.status` | `retrieve` |
|
|
67
|
+
| `client.checks` | `list` |
|
|
68
|
+
|
|
69
|
+
### GEO probes and batches
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
audit = client.url_audits.create(
|
|
73
|
+
url="https://example.com/pricing",
|
|
74
|
+
geo={"engines": ["chatgpt", "gemini"], "prompt_count": 3},
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
batch = client.url_audit_batches.create(urls=["https://example.com/a", "https://example.com/b"])
|
|
78
|
+
batch = client.url_audit_batches.wait(batch.id)
|
|
79
|
+
for member in batch.audits:
|
|
80
|
+
print(member.url, member.status, member.score)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Site audits
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
site = client.site_audits.create(url="https://example.com/docs/", max_pages=50)
|
|
87
|
+
site = client.site_audits.wait(site.id)
|
|
88
|
+
for page in client.site_audits.list_pages(site.id).auto_paging_iter():
|
|
89
|
+
print(page.url, page.status, page.audit and page.audit.score)
|
|
90
|
+
|
|
91
|
+
print(site.report.score)
|
|
92
|
+
for issue in site.report.top_issues:
|
|
93
|
+
print(issue.id, issue.failed, issue.examples)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Pages are found from sitemaps, respect robots.txt and are audited one at a time per site, a few seconds apart.
|
|
97
|
+
|
|
98
|
+
### Brand audits
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
brand = client.brand_audits.create(
|
|
102
|
+
brand="Acme Payroll",
|
|
103
|
+
domain="acmepayroll.com",
|
|
104
|
+
category="payroll software for small businesses",
|
|
105
|
+
competitors=[{"name": "Gusto", "domain": "gusto.com"}],
|
|
106
|
+
)
|
|
107
|
+
brand = client.brand_audits.wait(brand.id)
|
|
108
|
+
print(brand.report.summary.brand.share_of_voice, brand.report.summary.gaps)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Monitors
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
monitor = client.monitors.create(url="https://example.com/pricing", cadence="weekly", score_drop_threshold=5)
|
|
115
|
+
client.monitors.update(monitor.id, geo=None) # only the fields you pass change; None clears geo
|
|
116
|
+
client.monitors.pause(monitor.id)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Each run is compared with the previous completed run; `run.regressions` lists what got worse (and the `monitor.regression_detected` webhook announces it).
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
for run in client.monitors.list_runs(monitor.id).auto_paging_iter():
|
|
123
|
+
for regression in run.regressions or []:
|
|
124
|
+
print(run.id, regression.type) # score_drop, ai_bot_blocked, schema_removed, citation_lost, render_regression
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Pagination
|
|
128
|
+
|
|
129
|
+
`list()` returns one page (`page.data`, `page.has_more`); `auto_paging_iter()` walks all of them:
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
for audit in client.url_audits.list(status="completed").auto_paging_iter():
|
|
133
|
+
print(audit.id, audit.url)
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Errors, retries and idempotency
|
|
137
|
+
|
|
138
|
+
Network errors, `429` and `5xx` responses are retried twice (`max_retries=`) with backoff, honouring `Retry-After`.
|
|
139
|
+
A `Retry-After` longer than a minute — such as a site's hourly audit limit — is raised straight away so you can
|
|
140
|
+
decide. Every POST sends an `Idempotency-Key` (pass `idempotency_key=` to choose it), so a retry can never start a
|
|
141
|
+
second audit.
|
|
142
|
+
|
|
143
|
+
```python
|
|
144
|
+
from web_auditor import InsufficientCreditsError, RateLimitError, WebAuditorError
|
|
145
|
+
|
|
146
|
+
try:
|
|
147
|
+
client.url_audits.create(url="https://example.com")
|
|
148
|
+
except InsufficientCreditsError:
|
|
149
|
+
...
|
|
150
|
+
except RateLimitError as error:
|
|
151
|
+
print(error.code, error.retry_after) # rate_limited | host_rate_limit | concurrent_audit_limit
|
|
152
|
+
except WebAuditorError as error:
|
|
153
|
+
print(error.status, error.code, error.message, error.request_id)
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
| Exception | When |
|
|
157
|
+
|---|---|
|
|
158
|
+
| `InvalidRequestError` / `ConflictError` | 400, 409 (`param` names the field) |
|
|
159
|
+
| `AuthenticationError` | 401 |
|
|
160
|
+
| `InsufficientCreditsError` | 402 |
|
|
161
|
+
| `PermissionDeniedError` | 403 |
|
|
162
|
+
| `NotFoundError` | 404 |
|
|
163
|
+
| `RateLimitError` | 429 |
|
|
164
|
+
| `APIError` | 5xx |
|
|
165
|
+
| `APIConnectionError` / `APITimeoutError` | the API couldn't be reached |
|
|
166
|
+
| `PollTimeoutError` | `wait()` ran out of time (`error.last` is the latest state) |
|
|
167
|
+
|
|
168
|
+
## Webhooks
|
|
169
|
+
|
|
170
|
+
Verify every delivery with the endpoint's signing secret, over the **raw** request body:
|
|
171
|
+
|
|
172
|
+
```python
|
|
173
|
+
from web_auditor import webhooks
|
|
174
|
+
|
|
175
|
+
@app.post("/webhooks/web-auditor")
|
|
176
|
+
def receive(request):
|
|
177
|
+
try:
|
|
178
|
+
event = webhooks.construct_event(request.body, request.headers.get("WA-Signature"), WEBHOOK_SECRET)
|
|
179
|
+
except webhooks.WebhookSignatureError:
|
|
180
|
+
return Response(status=400)
|
|
181
|
+
if event.type == "url_audit.completed":
|
|
182
|
+
...
|
|
183
|
+
return Response(status=204)
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Deliveries can arrive more than once (retries and replays keep the same `event.id`), so deduplicate on it.
|
|
187
|
+
|
|
188
|
+
## Configuration
|
|
189
|
+
|
|
190
|
+
```python
|
|
191
|
+
WebAuditor(
|
|
192
|
+
api_key="wa_live_…",
|
|
193
|
+
base_url="https://api.web-auditor.enfection.com", # or WEB_AUDITOR_BASE_URL
|
|
194
|
+
timeout=60,
|
|
195
|
+
max_retries=2,
|
|
196
|
+
http_client=None, # your own httpx.Client (proxies, custom transport)
|
|
197
|
+
)
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
`WebAuditor` can be used as a context manager to close its connections.
|
|
201
|
+
|
|
202
|
+
## Development
|
|
203
|
+
|
|
204
|
+
```bash
|
|
205
|
+
pip install -e '.[test]'
|
|
206
|
+
pytest
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
`tests/test_contract.py` checks the SDK against `../openapi.json`, which the backend regenerates with
|
|
210
|
+
`python manage.py export_public_openapi`.
|
|
211
|
+
|
|
212
|
+
## License
|
|
213
|
+
|
|
214
|
+
MIT — see [LICENSE](LICENSE). Release notes are in [CHANGELOG.md](CHANGELOG.md).
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# Web Auditor Python SDK
|
|
2
|
+
|
|
3
|
+
The official Python client for the [Web Auditor public API](https://api.web-auditor.enfection.com/docs): audit how
|
|
4
|
+
well a page can be found, read and cited by AI answer engines.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
pip install web-auditor
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
Requires Python 3.9+.
|
|
11
|
+
|
|
12
|
+
## Quick start
|
|
13
|
+
|
|
14
|
+
```python
|
|
15
|
+
from web_auditor import WebAuditor
|
|
16
|
+
|
|
17
|
+
client = WebAuditor(api_key="wa_test_…") # or set WEB_AUDITOR_API_KEY
|
|
18
|
+
|
|
19
|
+
audit = client.url_audits.create(url="https://example.com/pricing")
|
|
20
|
+
audit = client.url_audits.wait(audit.id)
|
|
21
|
+
|
|
22
|
+
print(audit.status, audit.report.score)
|
|
23
|
+
for check in audit.report.checks:
|
|
24
|
+
if check.status == "fail":
|
|
25
|
+
print(check.id, check.fix)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Test keys (`wa_test_…`) return a realistic sample report immediately and cost nothing — build your integration with
|
|
29
|
+
one, then switch to a live key.
|
|
30
|
+
|
|
31
|
+
Responses are `ApiObject`s: dicts that also allow attribute access (`audit.report.score` or
|
|
32
|
+
`audit["report"]["score"]`). `to_dict()` returns plain dicts.
|
|
33
|
+
|
|
34
|
+
## What's covered
|
|
35
|
+
|
|
36
|
+
| Resource | Methods |
|
|
37
|
+
|---|---|
|
|
38
|
+
| `client.url_audits` | `create`, `retrieve`, `list`, `cancel`, `artifacts`, `report_pdf`, `wait` |
|
|
39
|
+
| `client.url_audit_batches` | `create`, `retrieve`, `list`, `cancel`, `wait` |
|
|
40
|
+
| `client.report_shares` | `create`, `list`, `revoke` |
|
|
41
|
+
| `client.site_audits` | `create`, `retrieve`, `list`, `list_pages`, `cancel`, `wait` |
|
|
42
|
+
| `client.brand_audits` | `create`, `retrieve`, `list`, `wait` |
|
|
43
|
+
| `client.monitors` | `create`, `retrieve`, `list`, `update`, `pause`, `resume`, `delete`, `run`, `list_runs` |
|
|
44
|
+
| `client.webhook_endpoints` | `create`, `retrieve`, `list`, `delete`, `send_test_event`, `rotate_secret` |
|
|
45
|
+
| `client.webhook_deliveries` | `list`, `retrieve`, `replay` |
|
|
46
|
+
| `client.usage`, `client.status` | `retrieve` |
|
|
47
|
+
| `client.checks` | `list` |
|
|
48
|
+
|
|
49
|
+
### GEO probes and batches
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
audit = client.url_audits.create(
|
|
53
|
+
url="https://example.com/pricing",
|
|
54
|
+
geo={"engines": ["chatgpt", "gemini"], "prompt_count": 3},
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
batch = client.url_audit_batches.create(urls=["https://example.com/a", "https://example.com/b"])
|
|
58
|
+
batch = client.url_audit_batches.wait(batch.id)
|
|
59
|
+
for member in batch.audits:
|
|
60
|
+
print(member.url, member.status, member.score)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Site audits
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
site = client.site_audits.create(url="https://example.com/docs/", max_pages=50)
|
|
67
|
+
site = client.site_audits.wait(site.id)
|
|
68
|
+
for page in client.site_audits.list_pages(site.id).auto_paging_iter():
|
|
69
|
+
print(page.url, page.status, page.audit and page.audit.score)
|
|
70
|
+
|
|
71
|
+
print(site.report.score)
|
|
72
|
+
for issue in site.report.top_issues:
|
|
73
|
+
print(issue.id, issue.failed, issue.examples)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Pages are found from sitemaps, respect robots.txt and are audited one at a time per site, a few seconds apart.
|
|
77
|
+
|
|
78
|
+
### Brand audits
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
brand = client.brand_audits.create(
|
|
82
|
+
brand="Acme Payroll",
|
|
83
|
+
domain="acmepayroll.com",
|
|
84
|
+
category="payroll software for small businesses",
|
|
85
|
+
competitors=[{"name": "Gusto", "domain": "gusto.com"}],
|
|
86
|
+
)
|
|
87
|
+
brand = client.brand_audits.wait(brand.id)
|
|
88
|
+
print(brand.report.summary.brand.share_of_voice, brand.report.summary.gaps)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Monitors
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
monitor = client.monitors.create(url="https://example.com/pricing", cadence="weekly", score_drop_threshold=5)
|
|
95
|
+
client.monitors.update(monitor.id, geo=None) # only the fields you pass change; None clears geo
|
|
96
|
+
client.monitors.pause(monitor.id)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Each run is compared with the previous completed run; `run.regressions` lists what got worse (and the `monitor.regression_detected` webhook announces it).
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
for run in client.monitors.list_runs(monitor.id).auto_paging_iter():
|
|
103
|
+
for regression in run.regressions or []:
|
|
104
|
+
print(run.id, regression.type) # score_drop, ai_bot_blocked, schema_removed, citation_lost, render_regression
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Pagination
|
|
108
|
+
|
|
109
|
+
`list()` returns one page (`page.data`, `page.has_more`); `auto_paging_iter()` walks all of them:
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
for audit in client.url_audits.list(status="completed").auto_paging_iter():
|
|
113
|
+
print(audit.id, audit.url)
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Errors, retries and idempotency
|
|
117
|
+
|
|
118
|
+
Network errors, `429` and `5xx` responses are retried twice (`max_retries=`) with backoff, honouring `Retry-After`.
|
|
119
|
+
A `Retry-After` longer than a minute — such as a site's hourly audit limit — is raised straight away so you can
|
|
120
|
+
decide. Every POST sends an `Idempotency-Key` (pass `idempotency_key=` to choose it), so a retry can never start a
|
|
121
|
+
second audit.
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
from web_auditor import InsufficientCreditsError, RateLimitError, WebAuditorError
|
|
125
|
+
|
|
126
|
+
try:
|
|
127
|
+
client.url_audits.create(url="https://example.com")
|
|
128
|
+
except InsufficientCreditsError:
|
|
129
|
+
...
|
|
130
|
+
except RateLimitError as error:
|
|
131
|
+
print(error.code, error.retry_after) # rate_limited | host_rate_limit | concurrent_audit_limit
|
|
132
|
+
except WebAuditorError as error:
|
|
133
|
+
print(error.status, error.code, error.message, error.request_id)
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
| Exception | When |
|
|
137
|
+
|---|---|
|
|
138
|
+
| `InvalidRequestError` / `ConflictError` | 400, 409 (`param` names the field) |
|
|
139
|
+
| `AuthenticationError` | 401 |
|
|
140
|
+
| `InsufficientCreditsError` | 402 |
|
|
141
|
+
| `PermissionDeniedError` | 403 |
|
|
142
|
+
| `NotFoundError` | 404 |
|
|
143
|
+
| `RateLimitError` | 429 |
|
|
144
|
+
| `APIError` | 5xx |
|
|
145
|
+
| `APIConnectionError` / `APITimeoutError` | the API couldn't be reached |
|
|
146
|
+
| `PollTimeoutError` | `wait()` ran out of time (`error.last` is the latest state) |
|
|
147
|
+
|
|
148
|
+
## Webhooks
|
|
149
|
+
|
|
150
|
+
Verify every delivery with the endpoint's signing secret, over the **raw** request body:
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
from web_auditor import webhooks
|
|
154
|
+
|
|
155
|
+
@app.post("/webhooks/web-auditor")
|
|
156
|
+
def receive(request):
|
|
157
|
+
try:
|
|
158
|
+
event = webhooks.construct_event(request.body, request.headers.get("WA-Signature"), WEBHOOK_SECRET)
|
|
159
|
+
except webhooks.WebhookSignatureError:
|
|
160
|
+
return Response(status=400)
|
|
161
|
+
if event.type == "url_audit.completed":
|
|
162
|
+
...
|
|
163
|
+
return Response(status=204)
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Deliveries can arrive more than once (retries and replays keep the same `event.id`), so deduplicate on it.
|
|
167
|
+
|
|
168
|
+
## Configuration
|
|
169
|
+
|
|
170
|
+
```python
|
|
171
|
+
WebAuditor(
|
|
172
|
+
api_key="wa_live_…",
|
|
173
|
+
base_url="https://api.web-auditor.enfection.com", # or WEB_AUDITOR_BASE_URL
|
|
174
|
+
timeout=60,
|
|
175
|
+
max_retries=2,
|
|
176
|
+
http_client=None, # your own httpx.Client (proxies, custom transport)
|
|
177
|
+
)
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
`WebAuditor` can be used as a context manager to close its connections.
|
|
181
|
+
|
|
182
|
+
## Development
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
pip install -e '.[test]'
|
|
186
|
+
pytest
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
`tests/test_contract.py` checks the SDK against `../openapi.json`, which the backend regenerates with
|
|
190
|
+
`python manage.py export_public_openapi`.
|
|
191
|
+
|
|
192
|
+
## License
|
|
193
|
+
|
|
194
|
+
MIT — see [LICENSE](LICENSE). Release notes are in [CHANGELOG.md](CHANGELOG.md).
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "web-auditor"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Official Python client for the Web Auditor public API: AI-visibility (AEO/GEO) audits of web pages."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "Enfection" }]
|
|
14
|
+
keywords = ["web-auditor", "aeo", "geo", "seo", "ai-search", "api"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 4 - Beta",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Typing :: Typed",
|
|
21
|
+
]
|
|
22
|
+
dependencies = ["httpx>=0.25,<1"]
|
|
23
|
+
|
|
24
|
+
[project.optional-dependencies]
|
|
25
|
+
test = ["pytest>=8"]
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
Documentation = "https://api.web-auditor.enfection.com/docs"
|
|
29
|
+
|
|
30
|
+
[tool.hatch.version]
|
|
31
|
+
path = "src/web_auditor/_version.py"
|
|
32
|
+
|
|
33
|
+
[tool.hatch.build.targets.wheel]
|
|
34
|
+
packages = ["src/web_auditor"]
|
|
35
|
+
|
|
36
|
+
[tool.pytest.ini_options]
|
|
37
|
+
testpaths = ["tests"]
|
|
38
|
+
|
|
39
|
+
[tool.ruff]
|
|
40
|
+
line-length = 120
|
|
41
|
+
target-version = "py39"
|
|
42
|
+
|
|
43
|
+
[tool.ruff.lint]
|
|
44
|
+
select = ["E", "F", "I", "UP", "B"]
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Official Python client for the Web Auditor public API."""
|
|
2
|
+
|
|
3
|
+
from . import webhooks
|
|
4
|
+
from ._client import Page, WebAuditor
|
|
5
|
+
from ._errors import (
|
|
6
|
+
APIConnectionError,
|
|
7
|
+
APIError,
|
|
8
|
+
APITimeoutError,
|
|
9
|
+
AuthenticationError,
|
|
10
|
+
ConflictError,
|
|
11
|
+
InsufficientCreditsError,
|
|
12
|
+
InvalidRequestError,
|
|
13
|
+
NotFoundError,
|
|
14
|
+
PermissionDeniedError,
|
|
15
|
+
PollTimeoutError,
|
|
16
|
+
RateLimitError,
|
|
17
|
+
WebAuditorError,
|
|
18
|
+
)
|
|
19
|
+
from ._object import ApiObject
|
|
20
|
+
from ._resources import NOT_GIVEN
|
|
21
|
+
from ._version import __version__
|
|
22
|
+
|
|
23
|
+
__all__ = [
|
|
24
|
+
"APIConnectionError",
|
|
25
|
+
"APIError",
|
|
26
|
+
"APITimeoutError",
|
|
27
|
+
"ApiObject",
|
|
28
|
+
"AuthenticationError",
|
|
29
|
+
"ConflictError",
|
|
30
|
+
"InsufficientCreditsError",
|
|
31
|
+
"InvalidRequestError",
|
|
32
|
+
"NOT_GIVEN",
|
|
33
|
+
"NotFoundError",
|
|
34
|
+
"Page",
|
|
35
|
+
"PermissionDeniedError",
|
|
36
|
+
"PollTimeoutError",
|
|
37
|
+
"RateLimitError",
|
|
38
|
+
"WebAuditor",
|
|
39
|
+
"WebAuditorError",
|
|
40
|
+
"__version__",
|
|
41
|
+
"webhooks",
|
|
42
|
+
]
|