Python SDK Specification
Examples on this page match PyPI desearch-py==1.2.1. Do not call extract() on this release. Use web_crawl or REST GET /web/extract.
First AI Search call, with the same fields as the Search API guide: Extract API · Auth and API keys.
Install
Pin the version used in these examples:
Construct the client
Pass the raw API key from the environment. Do not hardcode production keys.
Do not pass streaming into ai_search. That argument is not in the current signature. For REST streaming, use the Streaming AI Search guide.
Extract / crawl
On 1.2.1, the extract family is web_crawl only:
Do not show or call desearch.extract(...) until PyPI ships it with evidence. REST alternative: GET /web/extract on the Extract API page.
Billing metadata
Read request cost from response headers. JSON object bodies may also include cost_usd, usage_count, service, and currency.
| Header | Meaning |
|---|---|
X-Desearch-Cost-Usd | Request cost in USD |
X-Desearch-Usage-Count | Billable usage units |
X-Desearch-Service | Pricing service key |
X-Desearch-Currency | Currency code |
Arrays, text responses, and streaming responses keep their body shape. Use headers for those. This page does not list dollar rates.
Errors
- Missing or invalid key:
401. - Validation failure:
4xxwith the API message. 429or5xx: retry with backoff.
Do not invent error JSON schemas beyond the API Reference.
Parity with JavaScript
| Capability | Python 1.2.1 | JavaScript 1.5.1 |
|---|---|---|
| AI Search | ai_search(...) | aiSearch({...}) |
| Extract page content | REST /web/extract or web_crawl | extract({...}) |
| Streaming helpers | Not on this package. Use REST (streaming guide) | Same |
| Billing fields on a JSON object | Read body and headers | Same |
| Billing on a stream | Headers only | Headers only |
| People Search (Python 1.4.0, JavaScript 1.6.0) | x_profile_search(...), youtube_creator_search(...), linkedin_profile_search(...), tiktok_creator_search(...) | xProfileSearch({...}), youtubeCreatorSearch({...}), linkedinProfileSearch({...}), tiktokCreatorSearch({...}) |
| Wait for a People Search task | wait_for_people_task(task_id) | waitForPeopleTask(task) |
| Read every People Search result | iter_people_results(task_id) | iterPeopleResultPages({ task_id }) |
People Search metadata labels (Python 1.5.0, JavaScript 1.7.0) | metadata={...} on the search methods and list_people_tasks | metadata: {...} in the search request and in listPeopleTasks |
| People Search result fields (Python 1.6.1, JavaScript 1.8.1) | task.completion_reason, score.unverified_criteria, person.enrichment | task.completion_reason, unverifiedCriteria(person.score), person.attributes?.enrichment |
| Company Search and Company Enrich (Python 1.10.0, JavaScript 1.11.0) | company_search(...), company_enrich(...) | companySearch({...}), companyEnrich({...}) |
| Wait for a company task, read every company | wait_for_company_task(task_id), iter_company_results(task_id) | waitForCompanyTask(task), iterCompanyResults({ task_id }) |
Other methods already on this package
Web search:
X search:
People Search (1.4.0 and later)
People Search methods ship in desearch-py 1.4.0, metadata labels in 1.5.0, the result fields in 1.6.0, and is_disqualifier on each criteria check in 1.6.1. The examples above match 1.2.1.
1.6.1 is not on PyPI yet. Until it is, install it from GitHub:
Once 1.6.1 is on PyPI, pip install "desearch-py>=1.6.1" works the same way. You can also call the People Search REST endpoints directly with any HTTP client: see People Search.
A search runs in the background. Start it, wait for it, then read or export the people it found:
| Method | Route |
|---|---|
x_profile_search, youtube_creator_search, linkedin_profile_search, tiktok_creator_search | POST /desearch/people/search/{x,youtube,linkedin,tiktok} (billed) |
list_people_tasks | GET /desearch/people/tasks |
get_people_task | GET /desearch/people/tasks/{task_id} |
get_people_results | GET /desearch/people/tasks/{task_id}/results |
pause_people_task, resume_people_task, cancel_people_task | POST /desearch/people/tasks/{task_id}/pause, /resume, /cancel |
export_people_results | GET /desearch/people/tasks/{task_id}/export |
list_people_profiles | GET /desearch/people/profiles |
export_people_profiles | GET /desearch/people/profiles/export |
wait_for_people_task | Polls get_people_task until the task ends |
iter_people_results | Follows next_cursor on get_people_results |
Search methods take query, count, min_score, exclude, and filters (XProfileSearchFilters, YouTubeCreatorSearchFilters, LinkedInProfileSearchFilters, TikTokCreatorSearchFilters, or a dict), plus metadata from 1.5.0 (below). idempotency_key is sent as the Idempotency-Key header. A 409 from pause, resume, or cancel raises PeopleTaskConflictError. A timeout in wait_for_people_task raises PeopleTaskTimeoutError; the search keeps running. Flow, filters, and billing: People Search.
Read why a search ended and what each result confirms (1.6.0 and later)
desearch-py 1.6.0 types the result fields, and 1.6.1 adds is_disqualifier on each check. The GitHub install above is 1.6.1.
completion_reasonisNonewhile the search runs.coverage_limitedisTruewhen a budget stopped it beforecount.score.criteria_checksholds onePeopleCriterionCheckper criterion (criterion,verdict,quote,source_url,reason,is_disqualifier).score.unverified_criteriareturns the checks that are notmet, plus the disqualifiers that aremet. A check withoutis_disqualifier, scored before the field existed, counts as a disqualifier when its criterion names one, such asdisqualifyorexclude.person.enrichmentandperson.enrichment_errorreadattributes["enrichment"]andattributes["enrichment_error"].
What each field means: the Reading results section of People Search.
Label searches with metadata (1.5.0 and later)
desearch-py 1.5.0 adds metadata to the four search methods and to list_people_tasks. Use it to tag each search with your own labels, such as the campaign, workspace, or customer it belongs to, and to list those searches later. The search itself never uses the labels.
The GitHub install above is 1.6.1, so it includes metadata.
task.metadatais{}for a search without labels.- A search takes up to 10 keys. Keys are 1 to 40 characters of
a-z,0-9,_,., or-, and values are strings of up to 200 characters. The SDK does not check them; the API answers422, raised asDesearchAPIError. list_people_taskssends each pair as ametadata.<key>=<value>query parameter, and a task must match all of them exactly. Pass up to 3 pairs (the API answers400otherwise), and pass the samemetadatawith eachcursorwhen you page.- This
metadatais the task's labels. It is not the cost wrapper thatinclude_metadata=Truereturns.
Company Search (1.10.0 and later)
Company Search and Company Enrich methods ship in desearch-py 1.10.0. 1.10.0 is not on PyPI yet. Until it is, install it from GitHub:
Once 1.10.0 is on PyPI, pip install "desearch-py>=1.10.0" works the same way. You can also call the Company Search REST endpoints directly with any HTTP client: see Company Search.
A task runs in the background. Start it, wait for it, then read or export the companies it delivered:
Company Enrich takes domains or URLs instead of a description:
| Method | Route |
|---|---|
company_search, company_enrich | POST /desearch/companies/search, POST /desearch/companies/enrich (billed) |
list_company_tasks | GET /desearch/companies/tasks |
get_company_task | GET /desearch/companies/tasks/{task_id} |
get_company_results | GET /desearch/companies/tasks/{task_id}/results |
pause_company_task, resume_company_task, cancel_company_task | POST /desearch/companies/tasks/{task_id}/pause, /resume, /cancel |
export_company_results | GET /desearch/companies/tasks/{task_id}/export |
wait_for_company_task | Polls get_company_task until the task ends |
iter_company_results | Follows next_cursor on get_company_results and yields each Company |
company_searchtakesquery,count,min_score,exclude,roles,infer_emails,verify_emails,filters(CompanySearchFiltersor adictwithcountriesandrequire), andmetadata.company_enrichtakesdomains,roles,infer_emails,verify_emails, andmetadata.idempotency_keyis sent as theIdempotency-Keyheader.list_company_taskstakestype(searchorenrich),status,limit,cursor, and ametadatafilter of up to 3 pairs. People Search tasks are not listed there.- Results are
Companymodels withemails(CompanyEmail, each with aCompanyEmailVerification),phones,socials,pages,people(CompanyPerson),primary_email,primary_contact,contact_coverage,enrichment,score(CompanyScore,Nonefor Company Enrich), andfound_by.score.unverified_criteriaworks as onPeopleScore. - A company is published before every stage has run and is filled in later.
iter_company_resultsreturns each company as it is when read, so read afterwait_for_company_taskreturns to get the final version. - A 409 from pause, resume, or cancel raises
CompanyTaskConflictError, with.detailand the current.task. A timeout inwait_for_company_taskraisesCompanyTaskTimeoutError; the task keeps running.
Flow, result fields, and billing: Company Search.