coresignal 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.
- coresignal-0.1.0/LICENSE +21 -0
- coresignal-0.1.0/PKG-INFO +561 -0
- coresignal-0.1.0/README.md +533 -0
- coresignal-0.1.0/pyproject.toml +172 -0
- coresignal-0.1.0/src/coresignal/__init__.py +45 -0
- coresignal-0.1.0/src/coresignal/_agentic_search.py +173 -0
- coresignal-0.1.0/src/coresignal/_client.py +198 -0
- coresignal-0.1.0/src/coresignal/_company_multi_source.py +785 -0
- coresignal-0.1.0/src/coresignal/_core.py +308 -0
- coresignal-0.1.0/src/coresignal/_data_requests.py +187 -0
- coresignal-0.1.0/src/coresignal/_employee_multi_source.py +779 -0
- coresignal-0.1.0/src/coresignal/_errors.py +131 -0
- coresignal-0.1.0/src/coresignal/_job_multi_source.py +511 -0
- coresignal-0.1.0/src/coresignal/_paging.py +455 -0
- coresignal-0.1.0/src/coresignal/_response.py +37 -0
- coresignal-0.1.0/src/coresignal/_version.py +3 -0
- coresignal-0.1.0/src/coresignal/py.typed +0 -0
- coresignal-0.1.0/src/coresignal/types/__init__.py +13 -0
- coresignal-0.1.0/src/coresignal/types/agentic_search.py +4 -0
- coresignal-0.1.0/src/coresignal/types/company_multi_source.py +1118 -0
- coresignal-0.1.0/src/coresignal/types/data_requests.py +21 -0
- coresignal-0.1.0/src/coresignal/types/employee_multi_source.py +806 -0
- coresignal-0.1.0/src/coresignal/types/job_multi_source.py +127 -0
- coresignal-0.1.0/src/coresignal/types/semantic_search.py +43 -0
coresignal-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Coresignal
|
|
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,561 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: coresignal
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK for the Coresignal API
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Keywords: coresignal,api,sdk,company data,employee data,job data
|
|
8
|
+
Author: Coresignal
|
|
9
|
+
Requires-Python: >=3.11
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Dist: httpx (>=0.27,<1)
|
|
23
|
+
Project-URL: Documentation, https://docs.coresignal.com
|
|
24
|
+
Project-URL: Homepage, https://coresignal.com
|
|
25
|
+
Project-URL: Repository, https://github.com/Coresignal-com/coresignal-sdk-python
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# Coresignal Python SDK
|
|
29
|
+
|
|
30
|
+
[](https://pypi.org/project/coresignal/)
|
|
31
|
+
[](https://pypi.org/project/coresignal/)
|
|
32
|
+
[](https://github.com/Coresignal-com/coresignal-sdk-python/blob/main/LICENSE)
|
|
33
|
+
|
|
34
|
+
[](https://dashboard.coresignal.com/sign-up?utm_source=sdk_readme&utm_medium=referral&utm_campaign=sdk_launch_python&utm_content=promo_banner)
|
|
35
|
+
|
|
36
|
+
The official Python SDK for the
|
|
37
|
+
[Coresignal API](https://docs.coresignal.com/?utm_source=sdk_readme&utm_medium=referral&utm_campaign=sdk_launch_python&utm_content=docs).
|
|
38
|
+
Access multi-source company, employee, and jobs data, plus Agentic Search, without writing the plumbing yourself.
|
|
39
|
+
|
|
40
|
+
- One simple function for every API request
|
|
41
|
+
- Responses in JSON
|
|
42
|
+
- Automatic retries and clear error messages
|
|
43
|
+
- Big searches and bulk record collection handled for you
|
|
44
|
+
|
|
45
|
+
## Table of contents
|
|
46
|
+
|
|
47
|
+
- [Installation](#installation)
|
|
48
|
+
- [Authentication](#authentication)
|
|
49
|
+
- [Quick start](#quick-start)
|
|
50
|
+
- [Datasets](#datasets)
|
|
51
|
+
- [Responses](#responses)
|
|
52
|
+
- [Paging](#paging)
|
|
53
|
+
- [Searching and collecting](#searching-and-collecting)
|
|
54
|
+
- [Agentic Search](#agentic-search)
|
|
55
|
+
- [Collecting many records](#collecting-many-records)
|
|
56
|
+
- [Bulk Collect](#bulk-collect)
|
|
57
|
+
- [Errors and retries](#errors-and-retries)
|
|
58
|
+
- [Versioning](#versioning)
|
|
59
|
+
- [Support](#support)
|
|
60
|
+
- [About Coresignal](#about-coresignal)
|
|
61
|
+
- [License](#license)
|
|
62
|
+
|
|
63
|
+
## Installation
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pip install coresignal
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The SDK needs Python 3.11 or newer.
|
|
70
|
+
|
|
71
|
+
## Authentication
|
|
72
|
+
|
|
73
|
+
You need a Coresignal API key.
|
|
74
|
+
[Sign up](https://dashboard.coresignal.com/sign-up?utm_source=sdk_readme&utm_medium=referral&utm_campaign=sdk_launch_python&utm_content=auth_signup)
|
|
75
|
+
for free to get one, or find it in
|
|
76
|
+
[your dashboard](https://dashboard.coresignal.com/?utm_source=sdk_readme&utm_medium=referral&utm_campaign=sdk_launch_python&utm_content=auth_dashboard).
|
|
77
|
+
|
|
78
|
+
Pass your Coresignal API key as `api_key`, or set the `CORESIGNAL_API_KEY` environment variable:
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
from coresignal import Coresignal
|
|
82
|
+
|
|
83
|
+
client = Coresignal(api_key="your-api-key")
|
|
84
|
+
client = Coresignal() # reads CORESIGNAL_API_KEY
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Create one client and reuse it: it keeps a pool of open connections. Close it with `client.close()`, or use it as a
|
|
88
|
+
context manager:
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
with Coresignal() as client:
|
|
92
|
+
...
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Quick start
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
from coresignal import Coresignal
|
|
99
|
+
|
|
100
|
+
with Coresignal() as client:
|
|
101
|
+
company = client.company_multi_source.collect("example-inc", fields=["id", "company_name", "website"])
|
|
102
|
+
print(company.data["company_name"])
|
|
103
|
+
print(company.credits_remaining)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Datasets
|
|
107
|
+
|
|
108
|
+
Each dataset has its own group on the client, with one function per endpoint. Parameters are named as in the API,
|
|
109
|
+
and a parameter you leave out is not sent, so the API's default applies. Every function also takes `timeout` and
|
|
110
|
+
`max_retries` for that one request.
|
|
111
|
+
|
|
112
|
+
Each endpoint function returns an `ApiResponse`: `.data` is the response body, and its other attributes hold what
|
|
113
|
+
came with it, such as `total_results` or `credits_remaining` (see [Responses](#responses)). The helpers that send
|
|
114
|
+
several requests, such as `iter_search_es_dsl`, `collect_many` and `search_and_collect`, return their own results.
|
|
115
|
+
|
|
116
|
+
### Multi-source Company Data
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
from coresignal.types.company_multi_source import MultiSourceCompanyFilters
|
|
120
|
+
|
|
121
|
+
companies = client.company_multi_source
|
|
122
|
+
|
|
123
|
+
# Collect one record
|
|
124
|
+
company = companies.collect(12345).data # by ID
|
|
125
|
+
company = companies.collect("example-inc").data # by shorthand name or profile URL
|
|
126
|
+
company = companies.collect(12345, fields=["id", "company_name", "website"]).data
|
|
127
|
+
company = companies.collect(12345, bundle=["core_company_data", "financial_information"]).data
|
|
128
|
+
company = companies.enrich(website="example.com").data
|
|
129
|
+
company = companies.enrich(social_url="https://social.example.com/example-inc").data
|
|
130
|
+
|
|
131
|
+
# Search with an Elasticsearch DSL query
|
|
132
|
+
query = {"match": {"company_name": "Example"}}
|
|
133
|
+
ids = companies.search_es_dsl(query).data # the IDs of the matches, a page at a time
|
|
134
|
+
ids = companies.search_es_dsl(query, items_per_page=100, sort=["id"]).data
|
|
135
|
+
previews = companies.search_es_dsl_preview(query).data # a short preview of each match
|
|
136
|
+
|
|
137
|
+
# Search with filters, as keyword arguments or as a dict
|
|
138
|
+
ids = companies.search_filter(hq_country_iso2="US", industry="Software Development").data
|
|
139
|
+
filters: MultiSourceCompanyFilters = {"hq_country_iso2": "US", "industry": "Software Development"}
|
|
140
|
+
ids = companies.search_filter(**filters).data
|
|
141
|
+
previews = companies.search_filter_preview(**filters).data
|
|
142
|
+
ids = companies.search_filter(hq_country_iso2="US", industry=None).data # US companies without an industry
|
|
143
|
+
|
|
144
|
+
# Semantic search: synonyms are added to a match_phrase on the fields the docs list
|
|
145
|
+
semantic_query = {"match_phrase": {"active_job_postings.job_posting_title": "data engineer"}}
|
|
146
|
+
found = companies.semantic_search_es_dsl(semantic_query, threshold=0.8).data
|
|
147
|
+
found["results"] # the IDs of the matches
|
|
148
|
+
found["metadata"]["synonyms_injected"] # the synonyms that were added
|
|
149
|
+
|
|
150
|
+
# Every search, page after page (see Paging)
|
|
151
|
+
for company_id in companies.iter_search_es_dsl(query):
|
|
152
|
+
...
|
|
153
|
+
for company_id in companies.iter_search_filter(**filters):
|
|
154
|
+
...
|
|
155
|
+
for company_id in companies.iter_semantic_search_es_dsl(semantic_query):
|
|
156
|
+
...
|
|
157
|
+
for preview in companies.iter_search_es_dsl_preview(query, max_pages=2):
|
|
158
|
+
...
|
|
159
|
+
for preview in companies.iter_search_filter_preview(max_pages=2, **filters):
|
|
160
|
+
...
|
|
161
|
+
|
|
162
|
+
# Search and collect the full records in one call (see Searching and collecting)
|
|
163
|
+
result = companies.search_and_collect(query, sort="_score", max_records=10)
|
|
164
|
+
result = companies.search_filter_and_collect(sort="last_updated", max_records=10, **filters)
|
|
165
|
+
|
|
166
|
+
# Collect many records (see Collecting many records)
|
|
167
|
+
collected = companies.collect_many([12345, 12346, 12347])
|
|
168
|
+
|
|
169
|
+
# Bulk Collect: the API prepares the records as files (see Bulk Collect)
|
|
170
|
+
request_id = companies.bulk_collect_ids([12345, 12346, 12347]).data["request_id"]
|
|
171
|
+
request_id = companies.bulk_collect_es_dsl(query, limit=1000).data["request_id"]
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Multi-source Employee Data
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
from coresignal.types.employee_multi_source import MultiSourceEmployeeFilters
|
|
178
|
+
|
|
179
|
+
employees = client.employee_multi_source
|
|
180
|
+
|
|
181
|
+
# Collect one record
|
|
182
|
+
employee = employees.collect(67890).data # by ID
|
|
183
|
+
employee = employees.collect("jane-doe").data # by shorthand name or profile URL
|
|
184
|
+
employee = employees.collect(67890, fields=["id", "full_name", "headline"]).data
|
|
185
|
+
employee = employees.collect(67890, bundle=["core_employee_data", "career_intelligence"]).data
|
|
186
|
+
employee = employees.enrich(social_url="https://www.example.com/in/jane-doe").data
|
|
187
|
+
|
|
188
|
+
# Search with an Elasticsearch DSL query
|
|
189
|
+
query = {"match_phrase": {"headline": "data engineer"}}
|
|
190
|
+
ids = employees.search_es_dsl(query).data
|
|
191
|
+
previews = employees.search_es_dsl_preview(query).data
|
|
192
|
+
|
|
193
|
+
# Search with filters, as keyword arguments or as a dict
|
|
194
|
+
ids = employees.search_filter(location_country="Lithuania", active_experience_title="Data Engineer").data
|
|
195
|
+
filters: MultiSourceEmployeeFilters = {"location_country": "Lithuania", "active_experience_title": "Data Engineer"}
|
|
196
|
+
ids = employees.search_filter(**filters).data
|
|
197
|
+
previews = employees.search_filter_preview(**filters).data
|
|
198
|
+
|
|
199
|
+
# Semantic search
|
|
200
|
+
semantic_query = {"match_phrase": {"active_experience_title": "data engineer"}}
|
|
201
|
+
found = employees.semantic_search_es_dsl(semantic_query).data
|
|
202
|
+
|
|
203
|
+
# Every search, page after page
|
|
204
|
+
for employee_id in employees.iter_search_es_dsl(query):
|
|
205
|
+
...
|
|
206
|
+
for employee_id in employees.iter_search_filter(**filters):
|
|
207
|
+
...
|
|
208
|
+
for employee_id in employees.iter_semantic_search_es_dsl(semantic_query):
|
|
209
|
+
...
|
|
210
|
+
for preview in employees.iter_search_es_dsl_preview(query, max_pages=2):
|
|
211
|
+
...
|
|
212
|
+
for preview in employees.iter_search_filter_preview(max_pages=2, **filters):
|
|
213
|
+
...
|
|
214
|
+
|
|
215
|
+
# Search and collect the full records in one call
|
|
216
|
+
result = employees.search_and_collect(query, sort="_score", max_records=10)
|
|
217
|
+
result = employees.search_filter_and_collect(sort="last_updated", max_records=10, **filters)
|
|
218
|
+
|
|
219
|
+
# Collect many records
|
|
220
|
+
collected = employees.collect_many([67890, 67891, "jane-doe"])
|
|
221
|
+
|
|
222
|
+
# Bulk Collect
|
|
223
|
+
request_id = employees.bulk_collect_ids([67890, 67891]).data["request_id"]
|
|
224
|
+
request_id = employees.bulk_collect_es_dsl(query, limit=1000).data["request_id"]
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### Multi-source Jobs Data
|
|
228
|
+
|
|
229
|
+
```python
|
|
230
|
+
jobs = client.job_multi_source
|
|
231
|
+
|
|
232
|
+
# Collect one record
|
|
233
|
+
job = jobs.collect(424242).data # by ID, also as a string of digits
|
|
234
|
+
job = jobs.collect(424242, fields=["id", "title", "company_name"]).data
|
|
235
|
+
|
|
236
|
+
# Search with an Elasticsearch DSL query
|
|
237
|
+
query = {"match_phrase": {"title": "product manager"}}
|
|
238
|
+
ids = jobs.search_es_dsl(query).data
|
|
239
|
+
previews = jobs.search_es_dsl_preview(query).data
|
|
240
|
+
|
|
241
|
+
# Semantic search
|
|
242
|
+
found = jobs.semantic_search_es_dsl(query).data
|
|
243
|
+
|
|
244
|
+
# Every search, page after page
|
|
245
|
+
for job_id in jobs.iter_search_es_dsl(query):
|
|
246
|
+
...
|
|
247
|
+
for job_id in jobs.iter_semantic_search_es_dsl(query):
|
|
248
|
+
...
|
|
249
|
+
for preview in jobs.iter_search_es_dsl_preview(query, max_pages=2):
|
|
250
|
+
...
|
|
251
|
+
|
|
252
|
+
# Search and collect the full records in one call
|
|
253
|
+
result = jobs.search_and_collect(query, sort="_score", max_records=10)
|
|
254
|
+
|
|
255
|
+
# Collect many records
|
|
256
|
+
collected = jobs.collect_many([424242, 424243])
|
|
257
|
+
|
|
258
|
+
# Bulk Collect
|
|
259
|
+
request_id = jobs.bulk_collect_ids([424242, 424243]).data["request_id"]
|
|
260
|
+
request_id = jobs.bulk_collect_es_dsl(query, limit=1000).data["request_id"]
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
## Responses
|
|
264
|
+
|
|
265
|
+
A function that sends one request and returns its data, such as `collect` or `search_es_dsl`, returns an
|
|
266
|
+
`ApiResponse`:
|
|
267
|
+
|
|
268
|
+
| Attribute | What it holds |
|
|
269
|
+
| --- | --- |
|
|
270
|
+
| `data` | The response body, exactly as the API sent it. |
|
|
271
|
+
| `credits_remaining` | Remaining credit balance after this request. |
|
|
272
|
+
| `credits_charged` | Credits this request deducted, or `None` when the API did not send them. |
|
|
273
|
+
| `total_results`, `total_pages` | Total number of matching results and pages. |
|
|
274
|
+
| `next_page_after` | The cursor for the next page of a search, or `None` on the last page. |
|
|
275
|
+
| `snapshot_token` | The token that keeps preview pages on one snapshot of the results. |
|
|
276
|
+
| `headers`, `status_code`, `attempts` | All headers, the status code, and how many times the request was sent. |
|
|
277
|
+
|
|
278
|
+
`data` holds plain dicts and lists. The `TypedDict` types in `coresignal.types` give editors and type checkers the
|
|
279
|
+
field names. Every field is optional. Fields named after the professional network are left out of the types, but
|
|
280
|
+
`data` still holds them. Read them with `.get()`, which type checkers see as `object`, or cast `data` to
|
|
281
|
+
`dict[str, Any]` first.
|
|
282
|
+
|
|
283
|
+
## Paging
|
|
284
|
+
|
|
285
|
+
A search returns up to 1,000 IDs per page. Each search function has an `iter_` version that follows the API's
|
|
286
|
+
`next_page_after` cursor for you:
|
|
287
|
+
|
|
288
|
+
```python
|
|
289
|
+
query = {"match": {"industry": "Software Development"}}
|
|
290
|
+
|
|
291
|
+
for company_id in client.company_multi_source.iter_search_es_dsl(query):
|
|
292
|
+
... # one ID at a time; each page is requested when the loop needs it
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
Use `pages()` to work one page at a time, with each page's headers:
|
|
296
|
+
|
|
297
|
+
```python
|
|
298
|
+
for page in client.company_multi_source.iter_search_es_dsl(query).pages():
|
|
299
|
+
print(len(page.data), page.total_results, page.credits_remaining)
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
Preview iterators page through one snapshot of the results, up to page 50. Each preview page is charged
|
|
303
|
+
([Credits](https://docs.coresignal.com/api-introduction/credits)), and without `max_pages` a preview iterator requests
|
|
304
|
+
up to 50 pages. `max_pages` limits how many pages are requested:
|
|
305
|
+
|
|
306
|
+
```python
|
|
307
|
+
for preview in client.company_multi_source.iter_search_es_dsl_preview(query, max_pages=2):
|
|
308
|
+
print(preview["company_name"])
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
## Searching and collecting
|
|
312
|
+
|
|
313
|
+
`search_and_collect` searches with an Elasticsearch DSL query and collects the full record of each match, in the order
|
|
314
|
+
of `sort`, until it has `max_records` records:
|
|
315
|
+
|
|
316
|
+
```python
|
|
317
|
+
query = {"match": {"company_name": "Example"}}
|
|
318
|
+
|
|
319
|
+
# The 10 best matches
|
|
320
|
+
result = client.company_multi_source.search_and_collect(query, sort="_score", max_records=10)
|
|
321
|
+
|
|
322
|
+
for company_id, company in result.records.items():
|
|
323
|
+
print(company_id, company["company_name"])
|
|
324
|
+
|
|
325
|
+
result.total_results # how many companies the query matched
|
|
326
|
+
result.credits_used # the credits this call used
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
- `sort` and `max_records` are required. `sort` is one field name, sent as given, such as `"_score"` for the best
|
|
330
|
+
matches first or `"id"`. A query with its own `sort` raises `ValueError`.
|
|
331
|
+
- Each record uses one `collect` request, charged like any other. A record that cannot be collected, such as one
|
|
332
|
+
removed since the search, is listed in `result.errors`, and the next match is taken instead.
|
|
333
|
+
- Requests are spaced to `requests_per_second`, 5 by default. Set it to your plan's rate limit.
|
|
334
|
+
- A `PaymentRequiredError`, `AuthenticationError`, `RateLimitError`, `TransportError`, `RequestValidationError`, a
|
|
335
|
+
third `ServerError` in a row or an error from a search request stops the run. It returns the records collected so
|
|
336
|
+
far, with the error in `result.stopped_by`, and the records that failed last are tried first when it is resumed. A
|
|
337
|
+
record whose request may have reached the API before the connection failed is listed in `result.errors` instead,
|
|
338
|
+
so a resume does not send it again.
|
|
339
|
+
- A `RequestValidationError` before any record was collected, such as for a misspelled field in `fields`, is raised.
|
|
340
|
+
- `result.resume` carries on where the run stopped, after an error or to collect the next `max_records` records. Pass
|
|
341
|
+
it with the same query and sort. It is `None` when every match was tried:
|
|
342
|
+
|
|
343
|
+
```python
|
|
344
|
+
companies = client.company_multi_source
|
|
345
|
+
collected = {}
|
|
346
|
+
|
|
347
|
+
result = companies.search_and_collect(query, sort="id", max_records=500)
|
|
348
|
+
collected.update(result.records)
|
|
349
|
+
while result.stopped_by is None and result.resume is not None: # the next 500
|
|
350
|
+
result = companies.search_and_collect(query, sort="id", max_records=500, resume=result.resume)
|
|
351
|
+
collected.update(result.records)
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
For company and employee data, `search_filter_and_collect` does the same with the filters of `search_filter` instead
|
|
355
|
+
of a query. Supported `sort` values are `"id"` and `"last_updated"`:
|
|
356
|
+
|
|
357
|
+
```python
|
|
358
|
+
result = client.company_multi_source.search_filter_and_collect(
|
|
359
|
+
sort="last_updated", max_records=100, hq_country_iso2="US", industry="Software Development"
|
|
360
|
+
)
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
## Agentic Search
|
|
364
|
+
|
|
365
|
+
`client.agentic_search.get_query_by_nl_query` turns a plain-English prompt into an Elasticsearch DSL query and counts
|
|
366
|
+
the records it matches, before collecting any. Check the count, then collect as many records as you need:
|
|
367
|
+
|
|
368
|
+
```python
|
|
369
|
+
found = client.agentic_search.get_query_by_nl_query(
|
|
370
|
+
"Software companies in Germany with more than 200 employees", entity="company"
|
|
371
|
+
)
|
|
372
|
+
print(found.total_results) # how many companies the query matches
|
|
373
|
+
|
|
374
|
+
result = client.company_multi_source.search_and_collect(found.query, sort=found.sort, max_records=100)
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
- `mode` is `"fast"`, optimized for speed and the default, or `"advanced"`, for more complex prompts and slower. Both
|
|
378
|
+
take the same arguments and return the same result.
|
|
379
|
+
- `entity` is `"employee"`, `"company"` or `"job"`, or `"auto"` to detect it from the prompt. Without it, employee
|
|
380
|
+
data is searched. `threshold`, from 0 to 1, is the minimum similarity for a synonym to be added to the search.
|
|
381
|
+
- Generating the query is charged ([Pricing](https://docs.coresignal.com/pricing)). The search that counts its
|
|
382
|
+
matches is not. If that search fails, the query is still returned, with the error in `found.search_error` and
|
|
383
|
+
`found.total_results` set to `None`.
|
|
384
|
+
- `found.query` has no sort. The field the query sorts by is in `found.sort`, or `"_score"` when it names none.
|
|
385
|
+
- `max_records=100` collects the first 100 matches in the order of `found.sort`. They are the top 100 by a field only
|
|
386
|
+
when the prompt asks for that order, such as "the 100 largest software companies in Germany by employee count".
|
|
387
|
+
Otherwise the sort is `"_score"`, which ranks records by how well they match the query, not by size, date or any
|
|
388
|
+
other field.
|
|
389
|
+
- Every sort field except `id` sorts in descending order, and `id` in ascending order. A prompt that asks for the
|
|
390
|
+
smallest, fewest or oldest records still gets the largest, most or newest first, or the `"_score"` order.
|
|
391
|
+
|
|
392
|
+
`found.entity` names the data the query searches. With `entity="auto"`, collect from the dataset it names. When the
|
|
393
|
+
account runs out of credits, top up and carry on with `resume`: running the query again would pay again for the
|
|
394
|
+
records already collected.
|
|
395
|
+
|
|
396
|
+
```python
|
|
397
|
+
from coresignal import CompanyMultiSource, EmployeeMultiSource, JobMultiSource, PaymentRequiredError
|
|
398
|
+
|
|
399
|
+
found = client.agentic_search.get_query_by_nl_query("Data engineers in Berlin", entity="auto")
|
|
400
|
+
datasets: dict[str, CompanyMultiSource | EmployeeMultiSource | JobMultiSource] = {
|
|
401
|
+
"company": client.company_multi_source,
|
|
402
|
+
"employee": client.employee_multi_source,
|
|
403
|
+
"job": client.job_multi_source,
|
|
404
|
+
}
|
|
405
|
+
dataset = datasets[found.entity]
|
|
406
|
+
|
|
407
|
+
result = dataset.search_and_collect(found.query, sort=found.sort, max_records=500)
|
|
408
|
+
if isinstance(result.stopped_by, PaymentRequiredError):
|
|
409
|
+
... # top up the account, then collect the rest
|
|
410
|
+
rest = dataset.search_and_collect(
|
|
411
|
+
found.query, sort=found.sort, max_records=500 - len(result.records), resume=result.resume
|
|
412
|
+
)
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
## Collecting many records
|
|
416
|
+
|
|
417
|
+
`collect_many` collects a list of records in the order given. Each ID is one `collect` request, charged like any
|
|
418
|
+
other:
|
|
419
|
+
|
|
420
|
+
```python
|
|
421
|
+
result = client.company_multi_source.collect_many([12345, 12346, 12347], fields=["id", "company_name"])
|
|
422
|
+
|
|
423
|
+
result.records # {12345: {...}, 12347: {...}}
|
|
424
|
+
result.errors # {12346: NotFoundError(...)}
|
|
425
|
+
result.not_collected # the IDs not tried after the run stopped
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
- Each record is collected once, even when its ID is given twice or in two forms, such as `1` and `"1"`.
|
|
429
|
+
- Pass the IDs themselves. A semantic search page's `data` holds them in `results`, so pass `page.data["results"]`. A
|
|
430
|
+
mapping or a single string raises `TypeError`.
|
|
431
|
+
- An ID that fails does not stop the others. A `PaymentRequiredError`, `AuthenticationError` or `RateLimitError` does,
|
|
432
|
+
and so does a third `ServerError` in a row: later IDs would fail the same way, so they are listed in `not_collected`.
|
|
433
|
+
- The results come back when the run ends. Collect long lists in batches, for example, one search page at a time,
|
|
434
|
+
and keep each batch's records before the next page:
|
|
435
|
+
|
|
436
|
+
```python
|
|
437
|
+
from itertools import islice
|
|
438
|
+
|
|
439
|
+
collected = {}
|
|
440
|
+
for page in islice(client.company_multi_source.iter_search_es_dsl(query).pages(), 3): # the first 3 pages
|
|
441
|
+
result = client.company_multi_source.collect_many(page.data)
|
|
442
|
+
collected.update(result.records)
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
## Bulk Collect
|
|
446
|
+
|
|
447
|
+
Bulk Collect gets many records in one request: up to 10,000 records by ID, or the records an Elasticsearch DSL query
|
|
448
|
+
matches. The API prepares them as files. Start a request on a dataset, wait for its files, then save them:
|
|
449
|
+
|
|
450
|
+
```python
|
|
451
|
+
from pathlib import Path
|
|
452
|
+
|
|
453
|
+
started = client.company_multi_source.bulk_collect_es_dsl(query, limit=1000)
|
|
454
|
+
request_id = started.data["request_id"]
|
|
455
|
+
|
|
456
|
+
for file_name in client.data_requests.wait_for_files(request_id):
|
|
457
|
+
client.data_requests.download(request_id, file_name, Path(file_name).name)
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
- `bulk_collect_ids` takes up to 10,000 IDs, each given once. `bulk_collect_es_dsl` takes the same `query` as
|
|
461
|
+
`search_es_dsl`. A request that matches more than 10,000 records fails, so set a `limit` for a broad query.
|
|
462
|
+
- Credits are deducted for the records a request matches, as the
|
|
463
|
+
[Bulk Collect](https://docs.coresignal.com/api-introduction/requests/bulk-collect) page describes.
|
|
464
|
+
- Pass `webhook_url` to get notified when the data request is ready.
|
|
465
|
+
- A `bulk_collect_es_dsl` request identical to one still in progress, with the same query, `limit` and `webhook_url`,
|
|
466
|
+
raises an `APIStatusError` with status 409. Any other repeat, a repeated `bulk_collect_ids` included, starts a new
|
|
467
|
+
request that is charged again, so a request sent again after a `TransportError` may be charged twice.
|
|
468
|
+
- `wait_for_files` checks every 10 seconds and raises `TimeoutError` after half an hour. Change that with
|
|
469
|
+
`poll_interval` and `max_wait`.
|
|
470
|
+
- `download` saves a file as the API sends it, gzip-compressed JSON, to a path or into a binary file you opened, such as
|
|
471
|
+
an `io.BytesIO`. A path gets the file only once all of it has arrived. Each file can be downloaded for 30 days.
|
|
472
|
+
|
|
473
|
+
`files` checks once, without waiting. Its `data` lists the files in `data_request_files` once the data is ready, and
|
|
474
|
+
has no `data_request_files` before that:
|
|
475
|
+
|
|
476
|
+
```python
|
|
477
|
+
check = client.data_requests.files(request_id)
|
|
478
|
+
check.data.get("data_request_files") # None until the data is ready
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
## Errors and retries
|
|
482
|
+
|
|
483
|
+
Every error from the API or the connection is a `CoresignalError`, and so is a missing or invalid API key when the
|
|
484
|
+
client is created. An invalid argument raises `ValueError`. IDs given to `collect_many` or `bulk_collect_ids` as a
|
|
485
|
+
single string, bytes, a mapping or a value that is not iterable, and a `download` destination of the wrong type, raise
|
|
486
|
+
`TypeError`. When the API answers with an error status, the error is an `APIStatusError`, with the API's own message
|
|
487
|
+
in `message`, and its `status_code`, `body` and `headers`:
|
|
488
|
+
|
|
489
|
+
| Error | Status |
|
|
490
|
+
| --- | --- |
|
|
491
|
+
| `RequestValidationError` | 400, 422 |
|
|
492
|
+
| `AuthenticationError` | 401, 403 |
|
|
493
|
+
| `PaymentRequiredError` | 402 |
|
|
494
|
+
| `NotFoundError` | 404 |
|
|
495
|
+
| `RateLimitError` | 429 |
|
|
496
|
+
| `ServerError` | 500 and above |
|
|
497
|
+
| `APIStatusError` | Any other error status |
|
|
498
|
+
|
|
499
|
+
A `TransportError` means no answer came back, for example because the connection failed.
|
|
500
|
+
|
|
501
|
+
```python
|
|
502
|
+
from coresignal import NotFoundError, PaymentRequiredError
|
|
503
|
+
|
|
504
|
+
try:
|
|
505
|
+
client.company_multi_source.collect(12345)
|
|
506
|
+
except NotFoundError:
|
|
507
|
+
print("No such company")
|
|
508
|
+
except PaymentRequiredError as error:
|
|
509
|
+
print(error.message)
|
|
510
|
+
```
|
|
511
|
+
|
|
512
|
+
A request is retried automatically only when it cannot have run: a 429 or 503 response, a refused connection, or a
|
|
513
|
+
connection timeout. The client waits 0.5 seconds before the first retry and doubles the wait each time, up to 60
|
|
514
|
+
seconds. When the API says how long to wait, the client waits that long instead; when that is more than 60 seconds,
|
|
515
|
+
the request is not retried and the error is raised at once, with the wait in `retry_after`. Any other failure is
|
|
516
|
+
raised at once, so your code decides whether to send the request again.
|
|
517
|
+
|
|
518
|
+
By default a request is retried up to 2 times, each step of a request may take up to 60 seconds, and connecting may
|
|
519
|
+
take up to 10 seconds. Change the defaults on the client, or for one request:
|
|
520
|
+
|
|
521
|
+
```python
|
|
522
|
+
client = Coresignal(timeout=30, max_retries=5)
|
|
523
|
+
client.company_multi_source.collect(12345, timeout=120, max_retries=0)
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
## Versioning
|
|
527
|
+
|
|
528
|
+
The SDK follows [Semantic Versioning](https://semver.org/):
|
|
529
|
+
|
|
530
|
+
- While the version is 0.x, a release that breaks the SDK's interface raises the minor version. From 1.0.0 on, it
|
|
531
|
+
raises the major version.
|
|
532
|
+
- The interface is the client, its endpoint groups (`CompanyMultiSource`, `EmployeeMultiSource`, `JobMultiSource`,
|
|
533
|
+
`DataRequests` and `AgenticSearch`), their functions and parameters, `ApiResponse`, `Paginator`,
|
|
534
|
+
`CollectManyResult`, `SearchAndCollectResult`, `SearchAndCollectResume`, `NlQueryResult`, the types in
|
|
535
|
+
`coresignal.types` and the error classes.
|
|
536
|
+
- What the SDK generates from the API's specification follows the API: the fields in responses, the filter keyword
|
|
537
|
+
arguments, the `bundle` values and the type names in `coresignal.types.company_multi_source`,
|
|
538
|
+
`coresignal.types.employee_multi_source` and `coresignal.types.job_multi_source`. When the API adds, removes or
|
|
539
|
+
renames one of these, the SDK changes with it without a major release.
|
|
540
|
+
- A function or parameter is removed only after it has emitted a `DeprecationWarning` that names its replacement for
|
|
541
|
+
at least one minor release.
|
|
542
|
+
- A Python version is dropped only in a minor release, after its end of life.
|
|
543
|
+
|
|
544
|
+
Every release is listed in the
|
|
545
|
+
[changelog](https://github.com/Coresignal-com/coresignal-sdk-python/blob/main/CHANGELOG.md).
|
|
546
|
+
|
|
547
|
+
## Support
|
|
548
|
+
|
|
549
|
+
Do you have questions about setting the SDK up or about our pricing?
|
|
550
|
+
[Contact us](https://coresignal.com/contact-us/?utm_source=sdk_readme&utm_medium=referral&utm_campaign=sdk_launch_python&utm_content=contact_us).
|
|
551
|
+
|
|
552
|
+
## About Coresignal
|
|
553
|
+
|
|
554
|
+
[Coresignal](https://coresignal.com/?utm_source=sdk_readme&utm_medium=referral&utm_campaign=sdk_launch_python&utm_content=homepage)
|
|
555
|
+
is a public web data provider that offers multi-source data on companies, jobs, and employees for organizations
|
|
556
|
+
worldwide in investment, sales tech, HR tech, market research, and beyond.
|
|
557
|
+
|
|
558
|
+
## License
|
|
559
|
+
|
|
560
|
+
MIT. See [LICENSE](https://github.com/Coresignal-com/coresignal-sdk-python/blob/main/LICENSE).
|
|
561
|
+
|