cernisdata 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.
- cernisdata/__init__.py +65 -0
- cernisdata/_client.py +975 -0
- cernisdata/_errors.py +132 -0
- cernisdata/_generated.py +2935 -0
- cernisdata/_types.py +100 -0
- cernisdata/_version.py +1 -0
- cernisdata/_webhooks.py +46 -0
- cernisdata/py.typed +0 -0
- cernisdata-0.1.0.dist-info/METADATA +127 -0
- cernisdata-0.1.0.dist-info/RECORD +11 -0
- cernisdata-0.1.0.dist-info/WHEEL +4 -0
cernisdata/_types.py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"""Response and input shapes. Responses are plain dicts with snake_case keys, exactly as the API sends them."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any, Generic, Literal, NotRequired, Sequence, TypedDict, TypeVar, Union
|
|
6
|
+
|
|
7
|
+
T = TypeVar("T")
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class IncludeExcludeDict(TypedDict, total=False):
|
|
11
|
+
include: str | Sequence[str]
|
|
12
|
+
exclude: str | Sequence[str]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
#: A list filter: one value, a list of values, or {"include": [...], "exclude": [...]}.
|
|
16
|
+
IncludeExclude = Union[str, Sequence[str], IncludeExcludeDict]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class Range(TypedDict, total=False):
|
|
20
|
+
"""Whole number range. Set min, max or both."""
|
|
21
|
+
|
|
22
|
+
min: int
|
|
23
|
+
max: int
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class Meta(TypedDict):
|
|
27
|
+
billing_unit: str
|
|
28
|
+
billed_units: float
|
|
29
|
+
charged_usd: str
|
|
30
|
+
price_version: str
|
|
31
|
+
#: Pass back as ``cursor`` for the next page. None on the last page.
|
|
32
|
+
next_cursor: str | None
|
|
33
|
+
retrieved_at: str
|
|
34
|
+
free_requests_remaining: int | None
|
|
35
|
+
endpoint_free_remaining: int | None
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class Envelope(TypedDict, Generic[T]):
|
|
39
|
+
"""Every endpoint answers with this envelope."""
|
|
40
|
+
|
|
41
|
+
request_id: str
|
|
42
|
+
status: Literal["completed", "pending", "failed"]
|
|
43
|
+
data: T | None
|
|
44
|
+
meta: Meta
|
|
45
|
+
#: Set while an async request is pending. Poll it with ``client.requests.wait(job_id)``.
|
|
46
|
+
job_id: NotRequired[str]
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class Page(TypedDict, Generic[T]):
|
|
50
|
+
"""``data`` of a paginated endpoint."""
|
|
51
|
+
|
|
52
|
+
total: NotRequired[int | None]
|
|
53
|
+
results: list[T]
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class FreeRequests(TypedDict):
|
|
57
|
+
limit: int
|
|
58
|
+
used: int
|
|
59
|
+
remaining: int
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class Wallet(TypedDict):
|
|
63
|
+
available_usd: str
|
|
64
|
+
cash_usd: str
|
|
65
|
+
promo_usd: str
|
|
66
|
+
held_usd: str
|
|
67
|
+
free_tier: bool
|
|
68
|
+
free_requests: FreeRequests
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class JobItem(TypedDict):
|
|
72
|
+
index: int
|
|
73
|
+
status: str
|
|
74
|
+
input: dict[str, Any]
|
|
75
|
+
data: Any
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class JobStatus(TypedDict):
|
|
79
|
+
job_id: str
|
|
80
|
+
endpoint: str
|
|
81
|
+
status: str
|
|
82
|
+
total: int
|
|
83
|
+
done: int
|
|
84
|
+
billed_units: float
|
|
85
|
+
charged_usd: str | None
|
|
86
|
+
export_url: str | None
|
|
87
|
+
items: list[JobItem]
|
|
88
|
+
next_after: int | None
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
class RequestRecord(TypedDict):
|
|
92
|
+
id: str
|
|
93
|
+
endpoint: str
|
|
94
|
+
status: str
|
|
95
|
+
http_status: int | None
|
|
96
|
+
error_code: str | None
|
|
97
|
+
free: bool
|
|
98
|
+
billed_units: float
|
|
99
|
+
charged_usd: str
|
|
100
|
+
created_at: str
|
cernisdata/_version.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.0"
|
cernisdata/_webhooks.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import hmac
|
|
5
|
+
import json
|
|
6
|
+
import time
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from ._errors import WebhookVerificationError
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _fail(message: str) -> WebhookVerificationError:
|
|
13
|
+
return WebhookVerificationError(400, {"error": {"code": "invalid_signature", "message": message}})
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def verify_webhook(
|
|
17
|
+
payload: str | bytes,
|
|
18
|
+
signature: str | None,
|
|
19
|
+
secret: str,
|
|
20
|
+
*,
|
|
21
|
+
tolerance: float = 300,
|
|
22
|
+
now: float | None = None,
|
|
23
|
+
) -> Any:
|
|
24
|
+
"""Verify a job webhook and return its parsed JSON payload.
|
|
25
|
+
|
|
26
|
+
Pass the raw request body (not re-serialized JSON), the ``CernisData-Signature`` header and your secret from
|
|
27
|
+
``client.webhooks.secret()``. Raises WebhookVerificationError. Set ``tolerance=0`` to skip the age check.
|
|
28
|
+
"""
|
|
29
|
+
body = payload.decode("utf-8") if isinstance(payload, (bytes, bytearray)) else payload
|
|
30
|
+
ts: int | None = None
|
|
31
|
+
sigs: list[str] = []
|
|
32
|
+
for part in (signature or "").split(","):
|
|
33
|
+
k, _, v = part.strip().partition("=")
|
|
34
|
+
if k == "t" and v.isdigit():
|
|
35
|
+
ts = int(v)
|
|
36
|
+
elif k == "v1" and v:
|
|
37
|
+
sigs.append(v)
|
|
38
|
+
if ts is None or not sigs:
|
|
39
|
+
raise _fail("Missing or malformed CernisData-Signature header.")
|
|
40
|
+
current = time.time() if now is None else now
|
|
41
|
+
if tolerance > 0 and abs(int(current) - ts) > tolerance:
|
|
42
|
+
raise _fail("Webhook timestamp is outside the tolerance window.")
|
|
43
|
+
expected = hmac.new(secret.encode(), f"{ts}.{body}".encode(), hashlib.sha256).hexdigest()
|
|
44
|
+
if not any(hmac.compare_digest(s, expected) for s in sigs):
|
|
45
|
+
raise _fail("Webhook signature does not match.")
|
|
46
|
+
return json.loads(body)
|
cernisdata/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: cernisdata
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK for Cernis Data: people, company, contact, signal and web data behind one API key.
|
|
5
|
+
Keywords: api,b2b data,enrichment,gtm,sdk
|
|
6
|
+
Classifier: Framework :: AsyncIO
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Typing :: Typed
|
|
9
|
+
Requires-Python: >=3.11
|
|
10
|
+
Requires-Dist: httpx<1,>=0.25
|
|
11
|
+
Provides-Extra: dev
|
|
12
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
# cernisdata
|
|
16
|
+
|
|
17
|
+
Python SDK for Cernis Data. People, company, contact, signal and web data behind one API key. Sync and async, fully typed, one dependency (httpx).
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install cernisdata
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from cernisdata import CernisData
|
|
25
|
+
|
|
26
|
+
client = CernisData() # reads CERNIS_DATA_API_KEY and CERNIS_DATA_BASE_URL (your API base URL)
|
|
27
|
+
|
|
28
|
+
page = client.people.search(job_titles=["VP Sales"], company_domains="stripe.com", limit=10)
|
|
29
|
+
for person in page["data"]["results"]:
|
|
30
|
+
print(person["full_name"], person["title"])
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
You can also pass both explicitly: `CernisData("ck_live_...", base_url="https://your-api-host")`.
|
|
34
|
+
|
|
35
|
+
## How calls work
|
|
36
|
+
|
|
37
|
+
- Namespaces: `client.people`, `client.companies`, `client.contacts`, `client.signals`, `client.web`. Methods take keyword arguments and are snake_case.
|
|
38
|
+
- Filters can be passed flat (`job_titles=...`) or as `filters={...}`. List filters take a string, a list, or `{"include": [...], "exclude": [...]}`.
|
|
39
|
+
- Every method returns the API envelope as a dict: `request_id`, `status`, `data`, `meta`.
|
|
40
|
+
|
|
41
|
+
### Async endpoints wait for you
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
found = client.contacts.email(first_name="Karri", last_name="Saarinen", company="linear.app")
|
|
45
|
+
print(found["data"])
|
|
46
|
+
|
|
47
|
+
pending = client.contacts.email(first_name="Karri", last_name="Saarinen", company="linear.app", wait=False)
|
|
48
|
+
result = client.requests.wait(pending["job_id"])
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Bulk jobs
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
job = client.contacts.email_bulk(items=[{"first_name": "Karri", "last_name": "Saarinen", "company": "linear.app"}])
|
|
55
|
+
job.wait()
|
|
56
|
+
for item in job.results():
|
|
57
|
+
print(item["index"], item["status"], item["data"])
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Pagination
|
|
61
|
+
|
|
62
|
+
Every page is a billed request, so cap it.
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
for person in client.people.iter_search(job_titles="CTO", locations="Austin", max_items=200):
|
|
66
|
+
print(person["full_name"])
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Errors
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
from cernisdata import CernisDataError, InsufficientBalanceError, RateLimitError
|
|
73
|
+
|
|
74
|
+
try:
|
|
75
|
+
client.companies.enrich(domain="stripe.com")
|
|
76
|
+
except InsufficientBalanceError as e:
|
|
77
|
+
print("Top up:", e.checkout_url)
|
|
78
|
+
except RateLimitError as e:
|
|
79
|
+
print("Retry in", e.retry_after)
|
|
80
|
+
except CernisDataError as e:
|
|
81
|
+
print(e.status, e.code, e.message, e.request_id)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Subclasses: `InvalidInputError`, `AuthenticationError`, `InsufficientBalanceError`, `PermissionDeniedError`, `NotFoundError`, `ConflictError`, `RateLimitError`, `EndpointNotAvailableError`, `TimeoutError`, `ServerError`, `APIConnectionError`, `WebhookVerificationError`.
|
|
85
|
+
|
|
86
|
+
### Retries, idempotency and timeouts
|
|
87
|
+
|
|
88
|
+
429, 5xx and network errors are retried with backoff and jitter (`max_retries=2` by default, honours `Retry-After`). Endpoint POSTs get an automatic `Idempotency-Key`, so a retry is never charged twice; pass `idempotency_key=` to choose your own. `timeout=` (seconds) per call is also sent to the API as its time budget.
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
client = CernisData(timeout=30, max_retries=4, wait_timeout=600)
|
|
92
|
+
client.companies.enrich(domain="stripe.com", timeout=10, idempotency_key="enrich-stripe")
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Async client
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
import asyncio
|
|
99
|
+
from cernisdata import AsyncCernisData
|
|
100
|
+
|
|
101
|
+
async def main():
|
|
102
|
+
async with AsyncCernisData() as client:
|
|
103
|
+
page = await client.people.search(job_titles="CTO")
|
|
104
|
+
async for person in client.people.iter_search(job_titles="CTO", max_items=50):
|
|
105
|
+
print(person["full_name"])
|
|
106
|
+
|
|
107
|
+
asyncio.run(main())
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Account
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
client.wallet() # balance and free_requests {limit, used, remaining}
|
|
114
|
+
client.usage(days=7)
|
|
115
|
+
client.requests.list(limit=20)
|
|
116
|
+
client.keys.create(name="ci", scopes=["people"])
|
|
117
|
+
client.billing.checkout(amount_usd=25)
|
|
118
|
+
client.call("company.enrich", {"domain": "stripe.com"}) # any endpoint by id
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Webhooks
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
from cernisdata import verify_webhook
|
|
125
|
+
|
|
126
|
+
event = verify_webhook(raw_body, request.headers["CernisData-Signature"], secret)
|
|
127
|
+
```
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
cernisdata/__init__.py,sha256=ydWeXlNAv5Y6LZQwNlBNhciVtbw0FpjJkB3wKwr67jI,1702
|
|
2
|
+
cernisdata/_client.py,sha256=0IZDB7METb3slYRym5fK_-sBWZJ4zJBtFKg4isGoXUw,36958
|
|
3
|
+
cernisdata/_errors.py,sha256=3VpKR_lGHgzSuRL-b-Y1dNUHvdm2vst1r_AInlyEhOE,4448
|
|
4
|
+
cernisdata/_generated.py,sha256=in53Om8RCkE3KUACpkRcQp7rbwVQVH84UcC_Z8wI4Lk,129159
|
|
5
|
+
cernisdata/_types.py,sha256=VEwrBjd1F9IvxLMxjRCq3hJezY4Pc7Om84Mi3_YYFEo,2220
|
|
6
|
+
cernisdata/_version.py,sha256=kUR5RAFc7HCeiqdlX36dZOHkUI5wI6V_43RpEcD8b-0,22
|
|
7
|
+
cernisdata/_webhooks.py,sha256=Lg1RX3UxXVzDzmXhKngnqNQB13M8WwSS0Uzs5P3Bp2Y,1662
|
|
8
|
+
cernisdata/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
+
cernisdata-0.1.0.dist-info/METADATA,sha256=CbxgZ5mtuccn0TS1E2-AcwaoGlXCmGNhvFhSt7NKC-0,4285
|
|
10
|
+
cernisdata-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
11
|
+
cernisdata-0.1.0.dist-info/RECORD,,
|