specstream-client 1.3.0__tar.gz → 1.3.2__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.
- {specstream_client-1.3.0 → specstream_client-1.3.2}/PKG-INFO +1 -3
- {specstream_client-1.3.0 → specstream_client-1.3.2}/README.md +0 -2
- {specstream_client-1.3.0 → specstream_client-1.3.2}/pyproject.toml +1 -1
- {specstream_client-1.3.0 → specstream_client-1.3.2}/specstream_client/__init__.py +1 -1
- {specstream_client-1.3.0 → specstream_client-1.3.2}/specstream_client/client.py +41 -4
- {specstream_client-1.3.0 → specstream_client-1.3.2}/tests/test_http_boundary.py +9 -1
- {specstream_client-1.3.0 → specstream_client-1.3.2}/.gitignore +0 -0
- {specstream_client-1.3.0 → specstream_client-1.3.2}/LICENSE +0 -0
- {specstream_client-1.3.0 → specstream_client-1.3.2}/specstream_client/__main__.py +0 -0
- {specstream_client-1.3.0 → specstream_client-1.3.2}/specstream_client/authorization.py +0 -0
- {specstream_client-1.3.0 → specstream_client-1.3.2}/specstream_client/cli.py +0 -0
- {specstream_client-1.3.0 → specstream_client-1.3.2}/specstream_client/families.py +0 -0
- {specstream_client-1.3.0 → specstream_client-1.3.2}/specstream_client/lifecycle_commands.py +0 -0
- {specstream_client-1.3.0 → specstream_client-1.3.2}/specstream_client/py.typed +0 -0
- {specstream_client-1.3.0 → specstream_client-1.3.2}/tests/__init__.py +0 -0
- {specstream_client-1.3.0 → specstream_client-1.3.2}/tests/test_cli.py +0 -0
- {specstream_client-1.3.0 → specstream_client-1.3.2}/tests/test_client.py +0 -0
- {specstream_client-1.3.0 → specstream_client-1.3.2}/tests/test_convergence.py +0 -0
- {specstream_client-1.3.0 → specstream_client-1.3.2}/tests/test_m16_exports.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: specstream-client
|
|
3
|
-
Version: 1.3.
|
|
3
|
+
Version: 1.3.2
|
|
4
4
|
Summary: Python client for building lead lists and company lists from the live web. Every match comes with its source, priced before it runs.
|
|
5
5
|
Project-URL: Homepage, https://specstream.ai
|
|
6
6
|
Project-URL: Documentation, https://specstream.ai/docs/sdk
|
|
@@ -99,8 +99,6 @@ If the response is lost, `get_capacity_request(saved_request_key)` returns the s
|
|
|
99
99
|
- `export` and `download_export` give CSV, XLSX, JSON or HTML. `create_customer_webhook` sends signed events.
|
|
100
100
|
- Projects, members, shares and starred items have their own methods.
|
|
101
101
|
|
|
102
|
-
Kinds of thing include local businesses, companies, people, creators, products, apps, job postings, papers, clinical trials, grants, tenders, regulations, vulnerabilities, software packages, repositories, datasets, books and podcasts.
|
|
103
|
-
|
|
104
102
|
## Command line
|
|
105
103
|
|
|
106
104
|
```sh
|
|
@@ -72,8 +72,6 @@ If the response is lost, `get_capacity_request(saved_request_key)` returns the s
|
|
|
72
72
|
- `export` and `download_export` give CSV, XLSX, JSON or HTML. `create_customer_webhook` sends signed events.
|
|
73
73
|
- Projects, members, shares and starred items have their own methods.
|
|
74
74
|
|
|
75
|
-
Kinds of thing include local businesses, companies, people, creators, products, apps, job postings, papers, clinical trials, grants, tenders, regulations, vulnerabilities, software packages, repositories, datasets, books and podcasts.
|
|
76
|
-
|
|
77
75
|
## Command line
|
|
78
76
|
|
|
79
77
|
```sh
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "specstream-client"
|
|
3
|
-
version = "1.3.
|
|
3
|
+
version = "1.3.2"
|
|
4
4
|
description = "Python client for building lead lists and company lists from the live web. Every match comes with its source, priced before it runs."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.12"
|
|
@@ -4,9 +4,12 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
import json
|
|
6
6
|
import re
|
|
7
|
+
import time
|
|
7
8
|
import urllib.error
|
|
8
9
|
import urllib.request
|
|
9
10
|
from collections.abc import Callable
|
|
11
|
+
from datetime import UTC, datetime
|
|
12
|
+
from email.utils import parsedate_to_datetime
|
|
10
13
|
from typing import Any, cast
|
|
11
14
|
from urllib.parse import quote as quote_path
|
|
12
15
|
from urllib.parse import urlencode, urljoin, urlsplit
|
|
@@ -15,7 +18,7 @@ from specstream_client.authorization import require_work_authorization
|
|
|
15
18
|
from specstream_client.families import FAMILIES
|
|
16
19
|
|
|
17
20
|
DEFAULT_BASE_URL = "https://api.specstream.ai"
|
|
18
|
-
USER_AGENT = "specstream-python/1.3.
|
|
21
|
+
USER_AGENT = "specstream-python/1.3.2"
|
|
19
22
|
|
|
20
23
|
OpenFn = Callable[[urllib.request.Request, float], Any]
|
|
21
24
|
|
|
@@ -27,6 +30,29 @@ class _NoRedirect(urllib.request.HTTPRedirectHandler):
|
|
|
27
30
|
return None
|
|
28
31
|
|
|
29
32
|
|
|
33
|
+
RETRY_AFTER_MAX_S = 10.0
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _retry_after(exc: urllib.error.HTTPError) -> float | None:
|
|
37
|
+
"""Seconds to wait before the one retry of a 503 that names its Retry-After, or None."""
|
|
38
|
+
if exc.code != 503 or exc.headers is None:
|
|
39
|
+
return None
|
|
40
|
+
value = (exc.headers.get("Retry-After") or "").strip()
|
|
41
|
+
try:
|
|
42
|
+
seconds = float(value)
|
|
43
|
+
except ValueError:
|
|
44
|
+
try:
|
|
45
|
+
when = parsedate_to_datetime(value)
|
|
46
|
+
except (TypeError, ValueError):
|
|
47
|
+
return None
|
|
48
|
+
if when.tzinfo is None:
|
|
49
|
+
return None
|
|
50
|
+
seconds = (when - datetime.now(UTC)).total_seconds()
|
|
51
|
+
if not 0 <= seconds <= RETRY_AFTER_MAX_S:
|
|
52
|
+
return None
|
|
53
|
+
return seconds
|
|
54
|
+
|
|
55
|
+
|
|
30
56
|
class SpecstreamError(RuntimeError):
|
|
31
57
|
def __init__(self, message: str, status: int | None = None, body: Any = None) -> None:
|
|
32
58
|
super().__init__(message)
|
|
@@ -1595,9 +1621,20 @@ class Client:
|
|
|
1595
1621
|
payload = None if body is None else json.dumps(body, separators=(",", ":")).encode("utf-8")
|
|
1596
1622
|
req = urllib.request.Request(url, data=payload, method=method, headers=self._headers())
|
|
1597
1623
|
try:
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1624
|
+
try:
|
|
1625
|
+
with self._opener(req, self.timeout) as resp:
|
|
1626
|
+
status = getattr(resp, "status", 200)
|
|
1627
|
+
text = resp.read().decode("utf-8", "replace")
|
|
1628
|
+
except urllib.error.HTTPError as busy:
|
|
1629
|
+
wait = _retry_after(busy)
|
|
1630
|
+
if wait is None:
|
|
1631
|
+
raise
|
|
1632
|
+
# The server did nothing and names when to ask again: ask once more.
|
|
1633
|
+
busy.close()
|
|
1634
|
+
time.sleep(wait)
|
|
1635
|
+
with self._opener(req, self.timeout) as resp:
|
|
1636
|
+
status = getattr(resp, "status", 200)
|
|
1637
|
+
text = resp.read().decode("utf-8", "replace")
|
|
1601
1638
|
except urllib.error.HTTPError as exc:
|
|
1602
1639
|
text = exc.read().decode("utf-8", "replace") if exc.fp else ""
|
|
1603
1640
|
try:
|
|
@@ -29,7 +29,12 @@ def endpoint():
|
|
|
29
29
|
status, body = cases.get(
|
|
30
30
|
self.path.rsplit("/", 1)[-1], (200, '{"data":{"status":"completed"}}')
|
|
31
31
|
)
|
|
32
|
+
busy = self.path.endswith("/busy") and seen.count(self.path) == 1
|
|
33
|
+
if busy:
|
|
34
|
+
status, body = 503, '{"error":{"code":"capacity"}}'
|
|
32
35
|
self.send_response(status)
|
|
36
|
+
if busy:
|
|
37
|
+
self.send_header("Retry-After", "0")
|
|
33
38
|
self.end_headers()
|
|
34
39
|
self.wfile.write(body.encode())
|
|
35
40
|
|
|
@@ -48,7 +53,7 @@ def endpoint():
|
|
|
48
53
|
|
|
49
54
|
|
|
50
55
|
def test_error_envelopes_and_malformed_successes_are_not_deliveries(endpoint):
|
|
51
|
-
origin,
|
|
56
|
+
origin, seen = endpoint
|
|
52
57
|
client = Client("offline", base_url=origin)
|
|
53
58
|
for case in ("error", "null", "array", "empty"):
|
|
54
59
|
with pytest.raises(SpecstreamError) as failed:
|
|
@@ -59,6 +64,9 @@ def test_error_envelopes_and_malformed_successes_are_not_deliveries(endpoint):
|
|
|
59
64
|
assert unavailable.value.status == 503
|
|
60
65
|
assert unavailable.value.body == "<html>unavailable</html>"
|
|
61
66
|
assert client.get_find("valid")["status"] == "completed"
|
|
67
|
+
assert client.get_find("busy")["status"] == "completed"
|
|
68
|
+
assert seen.count("/v1/finds/html") == 1
|
|
69
|
+
assert seen.count("/v1/finds/busy") == 2
|
|
62
70
|
|
|
63
71
|
|
|
64
72
|
def test_redirect_does_not_forward_account_authority(endpoint):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|