blockquote-agents 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,82 @@
|
|
|
1
|
+
"""Official Blockquote client. Uses Python's standard library."""
|
|
2
|
+
import json
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from urllib.error import HTTPError
|
|
5
|
+
from urllib.parse import quote, urlencode, urlsplit
|
|
6
|
+
from urllib.request import HTTPRedirectHandler, Request, build_opener
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@dataclass
|
|
10
|
+
class Response:
|
|
11
|
+
data: object
|
|
12
|
+
status: int
|
|
13
|
+
headers: object
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class BlockquoteError(Exception):
|
|
17
|
+
def __init__(self, response):
|
|
18
|
+
super().__init__(f"Blockquote HTTP {response.status}")
|
|
19
|
+
self.data = response.data
|
|
20
|
+
self.status = response.status
|
|
21
|
+
self.headers = response.headers
|
|
22
|
+
self.retry_after = response.headers.get("Retry-After")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class _NoRedirect(HTTPRedirectHandler):
|
|
26
|
+
def redirect_request(self, req, fp, code, msg, headers, newurl):
|
|
27
|
+
return None
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class Blockquote:
|
|
31
|
+
def __init__(self, api_key=None, base_url="https://blockquote.io/api/v1", timeout=30):
|
|
32
|
+
base = urlsplit(base_url)
|
|
33
|
+
if base.scheme != "https" or not base.netloc or base.username or base.password or base.query or base.fragment:
|
|
34
|
+
raise ValueError("base_url must be an HTTPS URL without credentials, query, or fragment")
|
|
35
|
+
self.base_url = base_url.rstrip("/")
|
|
36
|
+
self.api_key = api_key
|
|
37
|
+
self.timeout = timeout
|
|
38
|
+
self._opener = build_opener(_NoRedirect())
|
|
39
|
+
|
|
40
|
+
def _request(self, path, body=None, idempotency_key=None):
|
|
41
|
+
headers = {"Accept": "application/json"}
|
|
42
|
+
if self.api_key:
|
|
43
|
+
headers["Authorization"] = f"Bearer {self.api_key}"
|
|
44
|
+
if body is not None:
|
|
45
|
+
headers["Content-Type"] = "application/json"
|
|
46
|
+
if idempotency_key:
|
|
47
|
+
headers["Idempotency-Key"] = idempotency_key
|
|
48
|
+
request = Request(self.base_url + path, headers=headers,
|
|
49
|
+
data=None if body is None else json.dumps(body).encode())
|
|
50
|
+
try:
|
|
51
|
+
raw = self._opener.open(request, timeout=self.timeout)
|
|
52
|
+
except HTTPError as error:
|
|
53
|
+
raw = error
|
|
54
|
+
with raw:
|
|
55
|
+
text = raw.read().decode("utf-8", errors="replace")
|
|
56
|
+
try:
|
|
57
|
+
data = json.loads(text)
|
|
58
|
+
except ValueError:
|
|
59
|
+
data = text
|
|
60
|
+
response = Response(data, raw.status, raw.headers)
|
|
61
|
+
if not 200 <= response.status < 300:
|
|
62
|
+
raise BlockquoteError(response)
|
|
63
|
+
return response
|
|
64
|
+
|
|
65
|
+
def start_scan(self, url, *, refresh=None, turnstile_token=None, idempotency_key=None):
|
|
66
|
+
body = {"url": url}
|
|
67
|
+
if refresh is not None:
|
|
68
|
+
body["refresh"] = refresh
|
|
69
|
+
if turnstile_token is not None:
|
|
70
|
+
body["turnstileToken"] = turnstile_token
|
|
71
|
+
return self._request("/scan", body, idempotency_key)
|
|
72
|
+
|
|
73
|
+
def get_scan(self, scan_id):
|
|
74
|
+
if not isinstance(scan_id, str) or not scan_id.strip() or scan_id in (".", ".."):
|
|
75
|
+
raise ValueError("A scan id is required")
|
|
76
|
+
return self._request("/scan/" + quote(scan_id, safe=""))
|
|
77
|
+
|
|
78
|
+
def compare_scans(self, *, from_id=None, to_id=None, url=None):
|
|
79
|
+
if (url and (from_id is not None or to_id is not None)) or (not url and (not from_id or not to_id)):
|
|
80
|
+
raise ValueError("Use url or both from_id and to_id")
|
|
81
|
+
query = {"url": url} if url else {"from": from_id, "to": to_id}
|
|
82
|
+
return self._request("/compare?" + urlencode(query))
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: blockquote-agents
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Official Blockquote Python SDK for AI visibility scans
|
|
5
|
+
License: MIT
|
|
6
|
+
Project-URL: Homepage, https://blockquote.io
|
|
7
|
+
Project-URL: Repository, https://github.com/ArneFfm/blockquote-agents
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Dynamic: license-file
|
|
12
|
+
|
|
13
|
+
# Blockquote Python SDK
|
|
14
|
+
|
|
15
|
+
Official client for [Blockquote](https://blockquote.io). Requires Python 3.10 or later. No runtime dependencies.
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
pip install blockquote-agents
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
import os
|
|
23
|
+
import uuid
|
|
24
|
+
from blockquote_agents import Blockquote, BlockquoteError
|
|
25
|
+
|
|
26
|
+
client = Blockquote(api_key=os.getenv("BLOCKQUOTE_API_KEY"))
|
|
27
|
+
started = client.start_scan("https://example.com", idempotency_key=str(uuid.uuid4()))
|
|
28
|
+
print(started.data, started.headers.get("Retry-After"))
|
|
29
|
+
# Wait for Retry-After, then read the returned id.
|
|
30
|
+
report = client.get_scan(started.data["id"])
|
|
31
|
+
comparison = client.compare_scans(from_id="BASELINE_ID", to_id="NEW_ID")
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Each call returns a `Response` with `data`, `status`, and HTTP `headers`.
|
|
35
|
+
`BlockquoteError` retains `data`, `status`, `headers`, and `retry_after`. Network errors pass through.
|
|
36
|
+
Requests time out after 30 seconds. Set `timeout` in the constructor to change this.
|
|
37
|
+
The client does not retry or poll automatically. Scans can return a cached result or pending status.
|
|
38
|
+
Reuse an idempotency key only when you repeat the same scan request.
|
|
39
|
+
|
|
40
|
+
Public report reads need no key. Account access uses an optional bearer key from [your account](https://blockquote.io/account).
|
|
41
|
+
Keys require Pro or Agency. Unattended scan creation can require a paid key with the `scan` scope.
|
|
42
|
+
Human verification still applies where required. Pass `turnstile_token` when available; the SDK does not obtain or bypass verification.
|
|
43
|
+
Pass `refresh=True` to request a fresh scan with account authentication. Scan quotas still apply.
|
|
44
|
+
Read access and comparison output follow your account plan.
|
|
45
|
+
|
|
46
|
+
See the [API reference](https://blockquote.io/api/docs) and [OpenAPI document](https://blockquote.io/api/v1/openapi.json).
|
|
47
|
+
|
|
48
|
+
Run tests from this package directory:
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
python3 -m unittest discover -s tests
|
|
52
|
+
```
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
blockquote_agents/__init__.py,sha256=2IgHidlc5tfOFRRj3lkaUvNwQ8vz-sawhH7eUts9OnU,3314
|
|
2
|
+
blockquote_agents-0.1.0.dist-info/licenses/LICENSE,sha256=Mhw__VbkCFuYx-tEHWJetFfCiqZ32FhZFflFskKDfic,1070
|
|
3
|
+
blockquote_agents-0.1.0.dist-info/METADATA,sha256=Biahmag7AunrYt85Iw3cin9Z2BHaQPPcXVC1T2s6QXU,2177
|
|
4
|
+
blockquote_agents-0.1.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
5
|
+
blockquote_agents-0.1.0.dist-info/top_level.txt,sha256=pPck6FKiGj-ONQ26c398t0Bhbo9RAaIkkxKOA_iBmgY,18
|
|
6
|
+
blockquote_agents-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Arne Kellmann
|
|
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
|
+
blockquote_agents
|