leadveyor 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.
- leadveyor-0.1.0/.gitignore +6 -0
- leadveyor-0.1.0/LICENSE +21 -0
- leadveyor-0.1.0/PKG-INFO +227 -0
- leadveyor-0.1.0/README.md +202 -0
- leadveyor-0.1.0/pyproject.toml +46 -0
- leadveyor-0.1.0/src/leadveyor/__init__.py +59 -0
- leadveyor-0.1.0/src/leadveyor/_base_client.py +437 -0
- leadveyor-0.1.0/src/leadveyor/_client.py +237 -0
- leadveyor-0.1.0/src/leadveyor/_errors.py +160 -0
- leadveyor-0.1.0/src/leadveyor/_object.py +103 -0
- leadveyor-0.1.0/src/leadveyor/_pagination.py +146 -0
- leadveyor-0.1.0/src/leadveyor/_resource.py +18 -0
- leadveyor-0.1.0/src/leadveyor/_version.py +1 -0
- leadveyor-0.1.0/src/leadveyor/models.py +1052 -0
- leadveyor-0.1.0/src/leadveyor/py.typed +0 -0
- leadveyor-0.1.0/src/leadveyor/resources/__init__.py +21 -0
- leadveyor-0.1.0/src/leadveyor/resources/api_keys.py +128 -0
- leadveyor-0.1.0/src/leadveyor/resources/billing.py +178 -0
- leadveyor-0.1.0/src/leadveyor/resources/contacts.py +176 -0
- leadveyor-0.1.0/src/leadveyor/resources/crm.py +218 -0
- leadveyor-0.1.0/src/leadveyor/resources/destinations.py +334 -0
- leadveyor-0.1.0/src/leadveyor/resources/events.py +90 -0
- leadveyor-0.1.0/src/leadveyor/resources/facebook.py +154 -0
- leadveyor-0.1.0/src/leadveyor/resources/hubspot.py +218 -0
- leadveyor-0.1.0/src/leadveyor/resources/inbounds.py +186 -0
- leadveyor-0.1.0/src/leadveyor/resources/leads.py +212 -0
- leadveyor-0.1.0/src/leadveyor/resources/pipedrive.py +216 -0
- leadveyor-0.1.0/src/leadveyor/resources/places.py +90 -0
- leadveyor-0.1.0/src/leadveyor/resources/profiles.py +528 -0
- leadveyor-0.1.0/src/leadveyor/resources/reports.py +94 -0
- leadveyor-0.1.0/src/leadveyor/resources/sources.py +198 -0
- leadveyor-0.1.0/src/leadveyor/resources/templates.py +90 -0
- leadveyor-0.1.0/src/leadveyor/resources/usage.py +56 -0
- leadveyor-0.1.0/src/leadveyor/resources/workspaces.py +176 -0
- leadveyor-0.1.0/src/leadveyor/webhooks.py +139 -0
leadveyor-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Leadveyor
|
|
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.
|
leadveyor-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: leadveyor
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Official Python client for the Leadveyor API: lead scoring, sources, webhooks.
|
|
5
|
+
Project-URL: Homepage, https://leadveyor.com
|
|
6
|
+
Project-URL: Documentation, https://leadveyor.com/docs/sdk/python
|
|
7
|
+
Project-URL: API reference, https://leadveyor.com/docs/api
|
|
8
|
+
Author-email: Leadveyor <support@leadveyor.com>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: api,crm,lead scoring,leads,leadveyor,sdk,webhooks
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Framework :: AsyncIO
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Requires-Python: >=3.9
|
|
20
|
+
Requires-Dist: httpx<1,>=0.23.0
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Requires-Dist: mypy>=1.10; extra == 'dev'
|
|
23
|
+
Requires-Dist: pytest>=7; extra == 'dev'
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# Leadveyor SDK for Python
|
|
27
|
+
|
|
28
|
+
[](https://pypi.org/project/leadveyor/) [](https://github.com/leadveyor/leadveyor-python/actions/workflows/tests.yml)
|
|
29
|
+
|
|
30
|
+
Official client for the [Leadveyor API](https://leadveyor.com/docs/api): send messages, get scored leads, manage profiles, sources and webhooks. Python 3.9+, sync and async, typed. One dependency: [httpx](https://www.python-httpx.org).
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install leadveyor
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Quick start
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from leadveyor import Leadveyor
|
|
40
|
+
|
|
41
|
+
lv = Leadveyor() # reads LEADVEYOR_API_KEY; or Leadveyor("lv_live_…")
|
|
42
|
+
|
|
43
|
+
inbound = lv.inbounds.create(
|
|
44
|
+
text="Hi, we need catering for 80 guests on 12 March in Richmond. Budget around $6k.",
|
|
45
|
+
wait=True, # wait for scoring instead of getting a webhook later
|
|
46
|
+
)
|
|
47
|
+
lead = inbound.leads[0] if inbound.leads else None
|
|
48
|
+
if lead:
|
|
49
|
+
print(lead.evaluation.tier, lead.evaluation.score)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Create API keys in the [console](https://console.leadveyor.com) → API keys. `lv_test_…` keys work on test data only.
|
|
53
|
+
|
|
54
|
+
### Async
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
import asyncio
|
|
58
|
+
from leadveyor import AsyncLeadveyor
|
|
59
|
+
|
|
60
|
+
async def main() -> None:
|
|
61
|
+
async with AsyncLeadveyor() as lv:
|
|
62
|
+
inbound = await lv.inbounds.create(text="Hi, need a plumber tomorrow", wait=True)
|
|
63
|
+
async for lead in lv.leads.list(tier="hot"):
|
|
64
|
+
print(lead.id, lead.evaluation.score)
|
|
65
|
+
|
|
66
|
+
asyncio.run(main())
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Resources
|
|
70
|
+
|
|
71
|
+
Methods are named like the [TypeScript SDK](https://leadveyor.com/docs/sdk), in snake_case. Path IDs are positional; everything else is a keyword argument with the API's own field name (`externalId=`, `sourceId=`), so the [API reference](https://leadveyor.com/docs/inbounds) applies as is.
|
|
72
|
+
|
|
73
|
+
| | Methods |
|
|
74
|
+
|---|---|
|
|
75
|
+
| `lv.inbounds` | `create`, `list`, `retrieve`, `reprocess` |
|
|
76
|
+
| `lv.leads` | `list`, `retrieve`, `list_evaluations`, `record_outcome`, `clear_outcome` |
|
|
77
|
+
| `lv.contacts` | `list`, `retrieve`, `update`, `list_leads` |
|
|
78
|
+
| `lv.profiles` | `list`, `create`, `retrieve`, `delete`, `validate`, `generate`, `generate_criterion`, `save_draft`, `update_draft`, `discard_draft`, `publish`, `activate`, `list_versions`, `retrieve_version` |
|
|
79
|
+
| `lv.templates` | `list`, `retrieve` |
|
|
80
|
+
| `lv.sources` | `list`, `create`, `retrieve`, `update`, `delete` |
|
|
81
|
+
| `lv.destinations` | `list`, `create`, `retrieve`, `update`, `delete`, `rotate_secret`, `test`, `list_deliveries`, `retry_delivery` |
|
|
82
|
+
| `lv.events` | `list`, `retrieve` |
|
|
83
|
+
| `lv.workspaces` | `list`, `create`, `retrieve`, `update` |
|
|
84
|
+
| `lv.api_keys` | `list`, `create`, `revoke` |
|
|
85
|
+
| `lv.billing` | `retrieve`, `checkout`, `change_plan`, `portal`, `set_spend_limit` |
|
|
86
|
+
| `lv.usage` | `retrieve`: this period's leads against the plan |
|
|
87
|
+
| `lv.reports` | `retrieve`, `compare_workspaces` |
|
|
88
|
+
| `lv.evaluate()` | Score a message without saving anything |
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
# Record what happened to a lead — this is what teaches scoring what "good" means
|
|
92
|
+
lv.leads.record_outcome("lead_2Ph6Tc9Ks4Wm1Lx7Qv3Nb8Dr", status="won", amount=6200)
|
|
93
|
+
|
|
94
|
+
# Send a form submission; safe to repeat with the same externalId
|
|
95
|
+
lv.inbounds.create(fields={"name": "Ann Lee", "email": "ann@example.com", "guests": 80}, externalId="form-4711")
|
|
96
|
+
|
|
97
|
+
# Profile documents are passed as a dict
|
|
98
|
+
lv.profiles.create(document, publish=True)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
An argument you leave out is not sent. `None` is sent as JSON `null` (for example `lv.billing.set_spend_limit(spendLimitUsd=None)` removes the limit).
|
|
102
|
+
|
|
103
|
+
## Responses
|
|
104
|
+
|
|
105
|
+
Responses are dicts whose fields can also be read as attributes:
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
lead = lv.leads.retrieve("lead_…") # leadveyor.models.Lead
|
|
109
|
+
lead.evaluation.tier # "hot"
|
|
110
|
+
lead["evaluation"]["score"] # 90
|
|
111
|
+
lead.to_dict() # plain dicts
|
|
112
|
+
json.dumps(lead) # works: it is a dict
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Every object has a class in `leadveyor.models` (`Lead`, `Inbound`, `Profile`, `Source` …) with type annotations, so editors and mypy know the fields. A field the API left out reads as `None`.
|
|
116
|
+
|
|
117
|
+
## Pagination
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
# This page
|
|
121
|
+
page = lv.leads.list(tier="hot", limit=50)
|
|
122
|
+
page.data, page.has_more, page.next_cursor
|
|
123
|
+
|
|
124
|
+
# Every item; next pages are fetched as you go
|
|
125
|
+
for lead in lv.leads.list(outcome="none"):
|
|
126
|
+
print(lead.id, lead.evaluation.score)
|
|
127
|
+
|
|
128
|
+
# Up to N items as a list
|
|
129
|
+
recent = lv.events.list(type="lead.*").to_list(limit=500)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Async: `await lv.leads.list()` is the first page, `async for lead in lv.leads.list()` goes through every item, `await lv.leads.list().to_list(limit=500)`.
|
|
133
|
+
|
|
134
|
+
## Webhooks
|
|
135
|
+
|
|
136
|
+
Verify the `Leadveyor-Signature` header against the **raw** request body:
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
from flask import Flask, request
|
|
140
|
+
from leadveyor import SignatureVerificationError, Webhook
|
|
141
|
+
|
|
142
|
+
app = Flask(__name__)
|
|
143
|
+
|
|
144
|
+
@app.post("/leadveyor-webhook")
|
|
145
|
+
def leadveyor_webhook():
|
|
146
|
+
try:
|
|
147
|
+
event = Webhook.construct_event(
|
|
148
|
+
request.get_data(), # raw bytes
|
|
149
|
+
request.headers.get("Leadveyor-Signature"),
|
|
150
|
+
os.environ["LEADVEYOR_WEBHOOK_SECRET"], # whsec_…
|
|
151
|
+
)
|
|
152
|
+
except SignatureVerificationError:
|
|
153
|
+
return "", 400
|
|
154
|
+
if event.type == "lead.scored":
|
|
155
|
+
save_lead(event.data.object) # leadveyor.models.Lead
|
|
156
|
+
return "", 200
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Django: `Webhook.construct_event(request.body, request.headers.get("Leadveyor-Signature"), secret)`. FastAPI: `await request.body()`.
|
|
160
|
+
|
|
161
|
+
`Webhook.verify(...)` returns a bool instead of raising. `Webhook.generate_test_header(payload, secret)` signs a payload like Leadveyor does, for your tests.
|
|
162
|
+
|
|
163
|
+
## Workspaces
|
|
164
|
+
|
|
165
|
+
A workspace key works in its own workspace. With an account-wide key (agencies, several clients) choose the workspace:
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
client = lv.with_workspace("ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde") # every request
|
|
169
|
+
lv.leads.list(workspace="ws_…") # one request
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Errors
|
|
173
|
+
|
|
174
|
+
Failed calls raise a subclass of `leadveyor.LeadveyorError`:
|
|
175
|
+
|
|
176
|
+
| Class | When |
|
|
177
|
+
|---|---|
|
|
178
|
+
| `InvalidRequestError` | 400: invalid parameters; `e.errors` lists every field problem |
|
|
179
|
+
| `AuthenticationError` | 401: missing, invalid or revoked key |
|
|
180
|
+
| `PermissionDeniedError` | 403: the key's permission or workspace doesn't allow it |
|
|
181
|
+
| `NotFoundError` | 404 |
|
|
182
|
+
| `ConflictError` | 409 |
|
|
183
|
+
| `QuotaExceededError` | 402: the plan's leads for this period are used up ([plans and limits](https://leadveyor.com/docs/plans-and-limits)); not retried |
|
|
184
|
+
| `RateLimitError` | 429, after the automatic retries |
|
|
185
|
+
| `APIError` | 5xx |
|
|
186
|
+
| `APIConnectionError` / `APITimeoutError` | the API could not be reached / no answer in time |
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
from leadveyor import NotFoundError
|
|
190
|
+
|
|
191
|
+
try:
|
|
192
|
+
lead = lv.leads.retrieve("lead_…")
|
|
193
|
+
except NotFoundError:
|
|
194
|
+
lead = None
|
|
195
|
+
# e.status_code, e.type, e.code, e.param, e.request_id (quote it to support)
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## Retries and timeouts
|
|
199
|
+
|
|
200
|
+
- 429 responses are retried for every method, honouring `Retry-After`.
|
|
201
|
+
- 5xx responses and network errors are retried for `GET`, `PUT`, `PATCH` and `DELETE`, for `evaluate()` and `profiles.validate()`, and for `inbounds.create()` **with an `externalId`** (the API returns the original inbound for a repeated ID). Other `POST`s are not retried on them, because the request may already have been applied.
|
|
202
|
+
- Two retries by default with exponential backoff.
|
|
203
|
+
|
|
204
|
+
```python
|
|
205
|
+
lv = Leadveyor(max_retries=4, timeout=30)
|
|
206
|
+
lv.evaluate(text=text, timeout=120)
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Options
|
|
210
|
+
|
|
211
|
+
| Option | Default | |
|
|
212
|
+
|---|---|---|
|
|
213
|
+
| `api_key` | `LEADVEYOR_API_KEY` | |
|
|
214
|
+
| `workspace` | — | `Leadveyor-Workspace` for account-wide keys |
|
|
215
|
+
| `base_url` | `https://core.leadveyor.com` | or `LEADVEYOR_BASE_URL` |
|
|
216
|
+
| `timeout` | `60` | seconds per attempt |
|
|
217
|
+
| `max_retries` | `2` | |
|
|
218
|
+
| `http_client` | new `httpx.Client` | your own `httpx.Client` / `httpx.AsyncClient` (proxies, tests) |
|
|
219
|
+
| `default_headers` | — | added to every request |
|
|
220
|
+
|
|
221
|
+
Per-request keyword arguments on every method: `workspace`, `timeout`, `max_retries`, `extra_headers`. `lv.with_options(timeout=5)` makes a client with changed options.
|
|
222
|
+
|
|
223
|
+
## Links
|
|
224
|
+
|
|
225
|
+
- Docs: https://leadveyor.com/docs/sdk/python
|
|
226
|
+
- API reference: https://leadveyor.com/docs/inbounds
|
|
227
|
+
- Support: support@leadveyor.com
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
# Leadveyor SDK for Python
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/leadveyor/) [](https://github.com/leadveyor/leadveyor-python/actions/workflows/tests.yml)
|
|
4
|
+
|
|
5
|
+
Official client for the [Leadveyor API](https://leadveyor.com/docs/api): send messages, get scored leads, manage profiles, sources and webhooks. Python 3.9+, sync and async, typed. One dependency: [httpx](https://www.python-httpx.org).
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install leadveyor
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick start
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from leadveyor import Leadveyor
|
|
15
|
+
|
|
16
|
+
lv = Leadveyor() # reads LEADVEYOR_API_KEY; or Leadveyor("lv_live_…")
|
|
17
|
+
|
|
18
|
+
inbound = lv.inbounds.create(
|
|
19
|
+
text="Hi, we need catering for 80 guests on 12 March in Richmond. Budget around $6k.",
|
|
20
|
+
wait=True, # wait for scoring instead of getting a webhook later
|
|
21
|
+
)
|
|
22
|
+
lead = inbound.leads[0] if inbound.leads else None
|
|
23
|
+
if lead:
|
|
24
|
+
print(lead.evaluation.tier, lead.evaluation.score)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Create API keys in the [console](https://console.leadveyor.com) → API keys. `lv_test_…` keys work on test data only.
|
|
28
|
+
|
|
29
|
+
### Async
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
import asyncio
|
|
33
|
+
from leadveyor import AsyncLeadveyor
|
|
34
|
+
|
|
35
|
+
async def main() -> None:
|
|
36
|
+
async with AsyncLeadveyor() as lv:
|
|
37
|
+
inbound = await lv.inbounds.create(text="Hi, need a plumber tomorrow", wait=True)
|
|
38
|
+
async for lead in lv.leads.list(tier="hot"):
|
|
39
|
+
print(lead.id, lead.evaluation.score)
|
|
40
|
+
|
|
41
|
+
asyncio.run(main())
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Resources
|
|
45
|
+
|
|
46
|
+
Methods are named like the [TypeScript SDK](https://leadveyor.com/docs/sdk), in snake_case. Path IDs are positional; everything else is a keyword argument with the API's own field name (`externalId=`, `sourceId=`), so the [API reference](https://leadveyor.com/docs/inbounds) applies as is.
|
|
47
|
+
|
|
48
|
+
| | Methods |
|
|
49
|
+
|---|---|
|
|
50
|
+
| `lv.inbounds` | `create`, `list`, `retrieve`, `reprocess` |
|
|
51
|
+
| `lv.leads` | `list`, `retrieve`, `list_evaluations`, `record_outcome`, `clear_outcome` |
|
|
52
|
+
| `lv.contacts` | `list`, `retrieve`, `update`, `list_leads` |
|
|
53
|
+
| `lv.profiles` | `list`, `create`, `retrieve`, `delete`, `validate`, `generate`, `generate_criterion`, `save_draft`, `update_draft`, `discard_draft`, `publish`, `activate`, `list_versions`, `retrieve_version` |
|
|
54
|
+
| `lv.templates` | `list`, `retrieve` |
|
|
55
|
+
| `lv.sources` | `list`, `create`, `retrieve`, `update`, `delete` |
|
|
56
|
+
| `lv.destinations` | `list`, `create`, `retrieve`, `update`, `delete`, `rotate_secret`, `test`, `list_deliveries`, `retry_delivery` |
|
|
57
|
+
| `lv.events` | `list`, `retrieve` |
|
|
58
|
+
| `lv.workspaces` | `list`, `create`, `retrieve`, `update` |
|
|
59
|
+
| `lv.api_keys` | `list`, `create`, `revoke` |
|
|
60
|
+
| `lv.billing` | `retrieve`, `checkout`, `change_plan`, `portal`, `set_spend_limit` |
|
|
61
|
+
| `lv.usage` | `retrieve`: this period's leads against the plan |
|
|
62
|
+
| `lv.reports` | `retrieve`, `compare_workspaces` |
|
|
63
|
+
| `lv.evaluate()` | Score a message without saving anything |
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
# Record what happened to a lead — this is what teaches scoring what "good" means
|
|
67
|
+
lv.leads.record_outcome("lead_2Ph6Tc9Ks4Wm1Lx7Qv3Nb8Dr", status="won", amount=6200)
|
|
68
|
+
|
|
69
|
+
# Send a form submission; safe to repeat with the same externalId
|
|
70
|
+
lv.inbounds.create(fields={"name": "Ann Lee", "email": "ann@example.com", "guests": 80}, externalId="form-4711")
|
|
71
|
+
|
|
72
|
+
# Profile documents are passed as a dict
|
|
73
|
+
lv.profiles.create(document, publish=True)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
An argument you leave out is not sent. `None` is sent as JSON `null` (for example `lv.billing.set_spend_limit(spendLimitUsd=None)` removes the limit).
|
|
77
|
+
|
|
78
|
+
## Responses
|
|
79
|
+
|
|
80
|
+
Responses are dicts whose fields can also be read as attributes:
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
lead = lv.leads.retrieve("lead_…") # leadveyor.models.Lead
|
|
84
|
+
lead.evaluation.tier # "hot"
|
|
85
|
+
lead["evaluation"]["score"] # 90
|
|
86
|
+
lead.to_dict() # plain dicts
|
|
87
|
+
json.dumps(lead) # works: it is a dict
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Every object has a class in `leadveyor.models` (`Lead`, `Inbound`, `Profile`, `Source` …) with type annotations, so editors and mypy know the fields. A field the API left out reads as `None`.
|
|
91
|
+
|
|
92
|
+
## Pagination
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
# This page
|
|
96
|
+
page = lv.leads.list(tier="hot", limit=50)
|
|
97
|
+
page.data, page.has_more, page.next_cursor
|
|
98
|
+
|
|
99
|
+
# Every item; next pages are fetched as you go
|
|
100
|
+
for lead in lv.leads.list(outcome="none"):
|
|
101
|
+
print(lead.id, lead.evaluation.score)
|
|
102
|
+
|
|
103
|
+
# Up to N items as a list
|
|
104
|
+
recent = lv.events.list(type="lead.*").to_list(limit=500)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Async: `await lv.leads.list()` is the first page, `async for lead in lv.leads.list()` goes through every item, `await lv.leads.list().to_list(limit=500)`.
|
|
108
|
+
|
|
109
|
+
## Webhooks
|
|
110
|
+
|
|
111
|
+
Verify the `Leadveyor-Signature` header against the **raw** request body:
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
from flask import Flask, request
|
|
115
|
+
from leadveyor import SignatureVerificationError, Webhook
|
|
116
|
+
|
|
117
|
+
app = Flask(__name__)
|
|
118
|
+
|
|
119
|
+
@app.post("/leadveyor-webhook")
|
|
120
|
+
def leadveyor_webhook():
|
|
121
|
+
try:
|
|
122
|
+
event = Webhook.construct_event(
|
|
123
|
+
request.get_data(), # raw bytes
|
|
124
|
+
request.headers.get("Leadveyor-Signature"),
|
|
125
|
+
os.environ["LEADVEYOR_WEBHOOK_SECRET"], # whsec_…
|
|
126
|
+
)
|
|
127
|
+
except SignatureVerificationError:
|
|
128
|
+
return "", 400
|
|
129
|
+
if event.type == "lead.scored":
|
|
130
|
+
save_lead(event.data.object) # leadveyor.models.Lead
|
|
131
|
+
return "", 200
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Django: `Webhook.construct_event(request.body, request.headers.get("Leadveyor-Signature"), secret)`. FastAPI: `await request.body()`.
|
|
135
|
+
|
|
136
|
+
`Webhook.verify(...)` returns a bool instead of raising. `Webhook.generate_test_header(payload, secret)` signs a payload like Leadveyor does, for your tests.
|
|
137
|
+
|
|
138
|
+
## Workspaces
|
|
139
|
+
|
|
140
|
+
A workspace key works in its own workspace. With an account-wide key (agencies, several clients) choose the workspace:
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
client = lv.with_workspace("ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde") # every request
|
|
144
|
+
lv.leads.list(workspace="ws_…") # one request
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Errors
|
|
148
|
+
|
|
149
|
+
Failed calls raise a subclass of `leadveyor.LeadveyorError`:
|
|
150
|
+
|
|
151
|
+
| Class | When |
|
|
152
|
+
|---|---|
|
|
153
|
+
| `InvalidRequestError` | 400: invalid parameters; `e.errors` lists every field problem |
|
|
154
|
+
| `AuthenticationError` | 401: missing, invalid or revoked key |
|
|
155
|
+
| `PermissionDeniedError` | 403: the key's permission or workspace doesn't allow it |
|
|
156
|
+
| `NotFoundError` | 404 |
|
|
157
|
+
| `ConflictError` | 409 |
|
|
158
|
+
| `QuotaExceededError` | 402: the plan's leads for this period are used up ([plans and limits](https://leadveyor.com/docs/plans-and-limits)); not retried |
|
|
159
|
+
| `RateLimitError` | 429, after the automatic retries |
|
|
160
|
+
| `APIError` | 5xx |
|
|
161
|
+
| `APIConnectionError` / `APITimeoutError` | the API could not be reached / no answer in time |
|
|
162
|
+
|
|
163
|
+
```python
|
|
164
|
+
from leadveyor import NotFoundError
|
|
165
|
+
|
|
166
|
+
try:
|
|
167
|
+
lead = lv.leads.retrieve("lead_…")
|
|
168
|
+
except NotFoundError:
|
|
169
|
+
lead = None
|
|
170
|
+
# e.status_code, e.type, e.code, e.param, e.request_id (quote it to support)
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Retries and timeouts
|
|
174
|
+
|
|
175
|
+
- 429 responses are retried for every method, honouring `Retry-After`.
|
|
176
|
+
- 5xx responses and network errors are retried for `GET`, `PUT`, `PATCH` and `DELETE`, for `evaluate()` and `profiles.validate()`, and for `inbounds.create()` **with an `externalId`** (the API returns the original inbound for a repeated ID). Other `POST`s are not retried on them, because the request may already have been applied.
|
|
177
|
+
- Two retries by default with exponential backoff.
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
lv = Leadveyor(max_retries=4, timeout=30)
|
|
181
|
+
lv.evaluate(text=text, timeout=120)
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Options
|
|
185
|
+
|
|
186
|
+
| Option | Default | |
|
|
187
|
+
|---|---|---|
|
|
188
|
+
| `api_key` | `LEADVEYOR_API_KEY` | |
|
|
189
|
+
| `workspace` | — | `Leadveyor-Workspace` for account-wide keys |
|
|
190
|
+
| `base_url` | `https://core.leadveyor.com` | or `LEADVEYOR_BASE_URL` |
|
|
191
|
+
| `timeout` | `60` | seconds per attempt |
|
|
192
|
+
| `max_retries` | `2` | |
|
|
193
|
+
| `http_client` | new `httpx.Client` | your own `httpx.Client` / `httpx.AsyncClient` (proxies, tests) |
|
|
194
|
+
| `default_headers` | — | added to every request |
|
|
195
|
+
|
|
196
|
+
Per-request keyword arguments on every method: `workspace`, `timeout`, `max_retries`, `extra_headers`. `lv.with_options(timeout=5)` makes a client with changed options.
|
|
197
|
+
|
|
198
|
+
## Links
|
|
199
|
+
|
|
200
|
+
- Docs: https://leadveyor.com/docs/sdk/python
|
|
201
|
+
- API reference: https://leadveyor.com/docs/inbounds
|
|
202
|
+
- Support: support@leadveyor.com
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.24"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "leadveyor"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Official Python client for the Leadveyor API: lead scoring, sources, webhooks."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.9"
|
|
13
|
+
authors = [{ name = "Leadveyor", email = "support@leadveyor.com" }]
|
|
14
|
+
keywords = ["leadveyor", "lead scoring", "leads", "crm", "api", "sdk", "webhooks"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 4 - Beta",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
21
|
+
"Typing :: Typed",
|
|
22
|
+
"Framework :: AsyncIO",
|
|
23
|
+
]
|
|
24
|
+
dependencies = ["httpx>=0.23.0,<1"]
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
Homepage = "https://leadveyor.com"
|
|
28
|
+
Documentation = "https://leadveyor.com/docs/sdk/python"
|
|
29
|
+
"API reference" = "https://leadveyor.com/docs/api"
|
|
30
|
+
|
|
31
|
+
[project.optional-dependencies]
|
|
32
|
+
dev = ["pytest>=7", "mypy>=1.10"]
|
|
33
|
+
|
|
34
|
+
[tool.hatch.build.targets.wheel]
|
|
35
|
+
packages = ["src/leadveyor"]
|
|
36
|
+
|
|
37
|
+
[tool.hatch.build.targets.sdist]
|
|
38
|
+
include = ["src/leadveyor", "README.md", "LICENSE", "pyproject.toml"]
|
|
39
|
+
|
|
40
|
+
[tool.pytest.ini_options]
|
|
41
|
+
testpaths = ["tests"]
|
|
42
|
+
|
|
43
|
+
[tool.mypy]
|
|
44
|
+
strict = true
|
|
45
|
+
python_version = "3.9"
|
|
46
|
+
files = ["src/leadveyor"]
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""Official Python client for the Leadveyor API. Docs: https://leadveyor.com/docs/sdk/python
|
|
2
|
+
|
|
3
|
+
.. code-block:: python
|
|
4
|
+
|
|
5
|
+
from leadveyor import Leadveyor
|
|
6
|
+
|
|
7
|
+
lv = Leadveyor() # reads LEADVEYOR_API_KEY
|
|
8
|
+
inbound = lv.inbounds.create(text="Hi, we need catering for 80 guests on 12 March", wait=True)
|
|
9
|
+
print(inbound.leads[0].evaluation.tier)
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from . import models
|
|
13
|
+
from ._base_client import DEFAULT_BASE_URL, NOT_GIVEN, NotGiven
|
|
14
|
+
from ._client import AsyncLeadveyor, Leadveyor
|
|
15
|
+
from ._errors import (
|
|
16
|
+
APIConnectionError,
|
|
17
|
+
APIError,
|
|
18
|
+
APITimeoutError,
|
|
19
|
+
AuthenticationError,
|
|
20
|
+
ConflictError,
|
|
21
|
+
InvalidRequestError,
|
|
22
|
+
LeadveyorError,
|
|
23
|
+
NotFoundError,
|
|
24
|
+
PermissionDeniedError,
|
|
25
|
+
QuotaExceededError,
|
|
26
|
+
RateLimitError,
|
|
27
|
+
SignatureVerificationError,
|
|
28
|
+
)
|
|
29
|
+
from ._object import LeadveyorObject
|
|
30
|
+
from ._pagination import AsyncPage, AsyncPageRequest, SyncPage
|
|
31
|
+
from ._version import __version__
|
|
32
|
+
from .webhooks import Webhook
|
|
33
|
+
|
|
34
|
+
__all__ = [
|
|
35
|
+
"Leadveyor",
|
|
36
|
+
"AsyncLeadveyor",
|
|
37
|
+
"Webhook",
|
|
38
|
+
"LeadveyorObject",
|
|
39
|
+
"SyncPage",
|
|
40
|
+
"AsyncPage",
|
|
41
|
+
"AsyncPageRequest",
|
|
42
|
+
"NOT_GIVEN",
|
|
43
|
+
"NotGiven",
|
|
44
|
+
"DEFAULT_BASE_URL",
|
|
45
|
+
"models",
|
|
46
|
+
"__version__",
|
|
47
|
+
"LeadveyorError",
|
|
48
|
+
"InvalidRequestError",
|
|
49
|
+
"AuthenticationError",
|
|
50
|
+
"PermissionDeniedError",
|
|
51
|
+
"NotFoundError",
|
|
52
|
+
"ConflictError",
|
|
53
|
+
"QuotaExceededError",
|
|
54
|
+
"RateLimitError",
|
|
55
|
+
"APIError",
|
|
56
|
+
"APIConnectionError",
|
|
57
|
+
"APITimeoutError",
|
|
58
|
+
"SignatureVerificationError",
|
|
59
|
+
]
|