SDKs
Python SDK
The sproutsdata package for Python: sync and async clients for every Sprouts Data API call, with typed models, paging, retries, typed errors and tools for AI models.
This edition is written for AI agents: complete, explicit and ready to paste. Give it to your agent, or point the agent at its address and it reads the page itself.
# Python SDK
> The sproutsdata package for Python: sync and async clients for every Sprouts Data API call, with typed models, paging, retries, typed errors and tools for AI models.
- Human-readable page: https://dashboard.sproutsdata.ai/docs/sdks/python
- This document: https://dashboard.sproutsdata.ai/docs/agents/sdks/python
- Index of every agent document: https://dashboard.sproutsdata.ai/llms.txt
- API base URL: https://api.sproutsdata.ai
## Summary
`sproutsdata`: the Python client for the Sprouts Data API. Sync `SproutsData` and async `AsyncSproutsData` with identical methods, pydantic models, `iter_*` generators that yield rows, safe retries, typed exceptions, and `sproutsdata.tools` (three model tools). Adapter: `langchain-sproutsdata`.
## Install
```bash
pip install sproutsdata
pip install langchain-sproutsdata
```
- Python >= 3.11. Dependencies: `httpx>=0.27,<1`, `pydantic>=2.7,<3`. `langchain-sproutsdata` depends on `langchain-core>=1.0,<2`.
## Client
```python
import os
from sproutsdata import SproutsData, AsyncSproutsData
client = SproutsData(api_key=os.environ["SPROUTS_API_KEY"])
```
- `SproutsData(*, api_key=None, base_url=None, timeout=None, max_retries=None, default_headers=None, http_client=None, on_response=None)`. All keyword-only. `AsyncSproutsData` takes the same.
- `api_key`: else env `SPROUTS_API_KEY` (deprecated fallback `SPROUTSDATA_API_KEY`, with a `DeprecationWarning`). Must match `^sk_dsp_live_[A-Za-z0-9_-]+$` (max 200); `sk_dsp_test_` refused.
- `base_url`: else env `SPROUTS_BASE_URL` (deprecated `SPROUTSDATA_BASE_URL`), else the production API. `https://` required; `http://` only for `localhost` / `127.0.0.1`.
- `timeout`: seconds per answer, default 60.0 (connect 10.0). `max_retries`: default 2. `default_headers` may not set `Origin`, `Referer` or SDK-owned headers. `http_client`: your `httpx` client (must not follow redirects; left open). `on_response(info: ResponseInfo)`.
- `client.with_options(*, timeout=None, max_retries=None, default_headers=None, on_response=None)` returns a client over the same connections.
- Context manager (`with SproutsData(...) as client:` / `async with AsyncSproutsData(...) as client:`) or `close()`.
- Per-call keyword arguments on every method: `request_id`, `timeout`; billed and keyed methods also `idempotency_key`.
- Top-level imports: the two clients, `__version__`, `RateLimitInfo`, `ResponseInfo`, `ServerSentEvent`, `ExportFile`, `ExportJob`, `ExportResult`, `LookupRef`, and every exception. Filter and sort models (`DiscoverFilters`, `TermsFilter`, `RangeFilter`, `DateFilter`, `DateBound`, `SortClause`, document filter models) are in `sproutsdata.types`.
## Methods
Signatures are keyword-only after any positional ids. Async: the same names, awaited; `iter_*` are async generators.
- `search(*, query=None, category="company", mode=None, filters=None, keyword_query=None, include_domains=None, exclude_domains=None, sort=None, lock_filters=None, partial_matches=None, fields=None, limit=None, cursor=None) -> SearchEnvelope`. `mode`: `"auto"` (server default) or `"fast"`. `category`: `company`, `person`, `patent`, `academic_report`, `news_article`, `market_report`, `trend`, `funding_round`, `job_opening`, `"auto"`.
- `iter_search(..., limit=None, max_results=None) -> Iterator[SearchHit]`.
- `similar(*, anchors, combine=None, category=None, filters=None, fields=None, limit=None, cursor=None)`; `iter_similar(..., max_results=None)`. Anchors: `str` or mapping `{value, by?, weight?}`.
- `filter_values(name, *, search=None, page=None, parent=None, level=None)`; `iter_filter_values(name, *, search=None, parent=None, level=None, max_results=None) -> Iterator[str]`.
- `document_filter_values(category, name, *, search=None, page=None)`; `iter_document_filter_values(category, name, *, search=None, max_results=None)`.
- `sorts(category)`; `coverage(*, category=None, segment=None)`; `search_export(*, items) -> ExportResult` (items: `{category, id}`).
- `entities.companies(ids, *, by="auto", fields=None)`, `entities.persons(ids, *, by="auto", fields=None)` (`by="id"` for record ids), `entities.patents(ids, *, fields=None)`, `entities.trends`, `entities.academic_reports`, `entities.news(ids, *, by=None, fields=None)`, `entities.market_reports`, `entities.fundings`, `entities.job_openings` -> `EntitiesEnvelope`.
- `relationships.find(*, query=None, relation=None, companies=None, institutions=None, institutions_combine=None, institution_type=None, connection_basis=None, exclude_current=None, include_company_context=None, limit=None, cursor=None)`; `relationships.iter_find(..., max_results=None)`.
- `relationships.reach(*, person, target_company, people=None, institution_type=None, connection_basis=None, limit=None, cursor=None)`; `relationships.iter_reach(..., max_results=None)`.
- `relationships.institutions(*, companies, institution_type=None, min_people_per_side=None, name_starts_with=None, limit=None)`; `relationships.ask(*, query, limit=None, cursor=None)`.
- `org_chart.retrieve(*, domain=None, linkedin_url=None, company_ref=None, filters=None, metrics=None, include_suspects=None)`; `org_chart.departments(...)`, `org_chart.locations(...)` (same without `metrics`); `org_chart.people(*, cell, domain=None, linkedin_url=None, company_ref=None, filters=None, include_suspects=None, limit=None, cursor=None)`; `org_chart.iter_people(..., max_results=None)`; `org_chart.taxonomy()`. Exactly one company identifier. Retired keyword arguments are refused naming their replacement.
- `runs.create(*, query, category=None, effort=None, criteria=None, enrichments=None, exclusion=None) -> RunHandle`; no idempotency key (every start is a new run). `effort`: `quick`, `basic`, `standard` (default), `detailed`, `maximum`, `auto`; legacy `minimal`, `low`, `medium`, `high`, `xhigh` accepted.
- `runs.list(*, limit=None, cursor=None)`, `runs.iter_list(*, limit=None, max_results=None)`, `runs.retrieve(run_id)`, `runs.cancel(run_id)`, `runs.wait(run_id, *, poll_interval=3.0, max_wait_seconds=900.0)`, `runs.events(run_id, *, last_event_id=None) -> Iterator[ServerSentEvent]`, `runs.results(run_id, *, limit=None, cursor=None)`, `runs.iter_results(run_id, *, limit=None, max_results=None) -> Iterator[dict]`.
- `enrichment.lookup(*, items, fields, entity=None, re_enrich=None, verify_mode=None, wait_seconds=None, idempotency_key=None)` (up to 20 items).
- `enrichment.create(*, items, fields, entity=None, re_enrich=None, verify_mode=None, name=None, idempotency_key=None) -> EnrichmentJobHandle`; `enrichment.list(*, status=None, limit=None, cursor=None)`; `enrichment.iter_list(*, status=None, limit=None, max_results=None)`; `enrichment.retrieve(job_id)`; `enrichment.cancel(job_id)`; `enrichment.wait(job_id, *, poll_interval=2.0, max_wait_seconds=1800.0)`; `enrichment.results(job_id, *, limit=None, cursor=None)`; `enrichment.iter_results(job_id, *, limit=None, max_results=None)`.
- Enrichment items (mappings): `linkedin_url`, `full_name`, `first_name`, `last_name`, `company_domain`, `company_name`, `email_hint`, `external_id`, `fields`. People fields: `EMAIL`, `PHONE`.
- `lists.list()`, `lists.create(*, name, category=None)`, `lists.rename(list_id, *, name)`, `lists.delete(list_id)`, `lists.items(list_id, *, limit=None, cursor=None)`, `lists.iter_items(list_id, *, limit=None, max_results=None)`, `lists.add_items(list_id, *, items)`, `lists.remove_items(list_id, *, items)`, `lists.export(list_id, *, offset=None, limit=None) -> ExportResult`. Up to 1,000 items per change.
- `exports.retrieve(job_id)`, `exports.download(job_id) -> str`, `exports.wait(job_id, *, poll_interval=2.0, max_wait_seconds=900.0)`.
- `history.list(*, action_type=None, from_=None, to=None, limit=None, cursor=None)`, `history.iter_list(..., max_results=None)`, `history.retrieve(run_id: str)`, `history.metrics(*, from_=None, to=None)`.
- `credits.retrieve() -> CreditsOut`, `credits.quote(*, operation, rows=None, start=None, effort=None, fields=None)`, `credits.transactions(*, limit=None, cursor=None)`, `credits.iter_transactions(*, limit=None, max_results=None)`.
- `feedback.create(*, target, subject_ref=None, sentiment=None, tags=None, comment=None, expected=None, idempotency_key=None)`, `feedback.list(*, limit=None, cursor=None)`, `feedback.iter_list(...)`, `feedback.tags()`, `feedback.votes.cast(*, request_id, level, vote, entity_category, entity_id=None, reason_code=None, text=None)`, `feedback.votes.list(*, request_id)`.
## Models and helpers
- `SearchHit`: pydantic model with `id`, `category`, `score`; record fields in `hit.model_extra` (no `hit["..."]`, no `.get`). `hit.lookup_ref() -> LookupRef | None` with `.category`, `.by`, `.value`.
- Lookup answer: `answer.get(value)` (row or `None`), `answer.missing()` (values not found), each row `.found`, `.matches`, `.records()`.
- `CreditsOut`: `balance`, `reserved`, `available`, `debt`, `status`; `can_afford(n)` compares with `available`.
- Coverage: `report.total_for(category)`.
- `ExportFile` (`csv`, `credits_charged`, `field_tier`, `rows`, `skipped`) or `ExportJob` (`job`).
## Exceptions
- `SproutsDataError` base. `ClientValidationError` (also `ValueError`). `APIResponseValidationError`. `APIConnectionError` (`reached_server`, `last_event_id`) > `APITimeoutError`. `WaitTimeoutError` (`last`). `ExportFailedError`.
- `APIStatusError` fields: `status_code`, `code`, `title`, `detail`, `next_step`, `instance`, `type`, `request_id`, `errors`, `extra`, `retry_after`, `headers`, `body`.
- Subclasses: `AuthenticationError` (401); `PermissionDeniedError` (403) > `WorkspaceRequiredError`; `InsufficientCreditsError` (402; `required_credits`, `available_credits`) > `WalletFrozenError`; `InvalidRequestError` (400/422) > `OrgChartCompanyAmbiguousError` (`candidates`), `CursorInvalidError`, `CursorExpiredError`, `PaginationDepthExceededError`; `NotFoundError` (404) > `ResultsExpiredError` (410); `ConflictError` (409) > `ListNameTakenError`; `RateLimitError` (429; `limit`, `window`, `operation`, `scope`) > `ConcurrencyLimitError`; `FeatureNotAvailableError` (501); `ServiceUnavailableError` (503) > `CreditsRefusedError`; `UpstreamTimeoutError` (504 `upstream.timeout`); `GatewayError` (408/502/504 without a code); `InternalServerError` (500).
- Branch on `exc.code`, then class. Log `request_id`.
## Retries and waits
- Up to `max_retries` (default 2), exponential backoff with jitter 0.5 s to 8 s. `Retry-After` up to 60 s waited; longer raised with `retry_after`.
- Retried with the same idempotency key (charged once): billed reads, enrichment `lookup` / `create`, `feedback.create`. `runs.create`: retried only if surely never ran (not sent, 429, 503); after 500, 504 or no answer it raises, check `runs.list()`. `lists.create` / `lists.delete` that may have arrived: raised with `reached_server=True`.
- Never retried: 400, 401, 402, 403, 404, 409, 422, 501; `quota.concurrency_exceeded`; `credits.refused`.
- Waits: runs poll from 3 s (x1.5, max 15 s, deadline 900 s); exports from 2 s (max 10 s, 900 s); enrichment from 2 s (max 30 s, 1,800 s). `max_wait_seconds=None` waits indefinitely. Deadline: `WaitTimeoutError` (`last`); work continues.
- Event streams idle for 60 s raise `APITimeoutError`.
## Tools for models
```python
from sproutsdata.tools import Toolset, AsyncToolset, definitions, openai, anthropic, TOOL_NAMES
tools = Toolset(client, max_results=10)
```
- Tools: `sprouts_search`, `sprouts_similar`, `sprouts_entity_lookup` (same names as the JS SDK; same schemas and results as the MCP server's `search`, `similar_companies`, `record_lookup`).
- `Toolset(client, *, include=None, fixed=None, defaults=None, max_results=25, baseline_filters=None)`; `max_results` 1-25.
- Methods: `tool_names`, `definitions()`, `openai(*, strict=True, api="chat")` (`api="responses"` for the Responses API), `anthropic()`, `run(name, arguments) -> dict`, `handle_openai_tool_calls(message)`, `handle_anthropic_tool_use(message)`. `AsyncToolset` mirrors it over `AsyncSproutsData`.
- Model-fixable errors return `{"error": {...}}`; 401, 403 and 402 errors are raised.
## LangChain
```python
from langchain_sproutsdata import sproutsdata_tools, SproutsDataRetriever
```
- `sproutsdata_tools(*, client=None, async_client=None, api_key=None, base_url=None, timeout=None, max_retries=None, include=None, fixed=None, defaults=None, max_results=25, baseline_filters=None) -> list[BaseTool]`.
- Tool classes: `SproutsDataSearchResults`, `SproutsDataFindSimilar`, `SproutsDataEntityLookup` (base `SproutsDataTool`).
- `SproutsDataRetriever(k=10, category="company", mode=None, partial_matches=None, filters=None, include_domains=None, exclude_domains=None, content_fields=None, include_resolved_search=True, api_key=None, base_url=None, client=None, async_client=None, timeout=None, max_retries=None)`. Each document carries the full row in `metadata["record"]`. Default mode with a category is `fast`.
## See also
- `https://dashboard.sproutsdata.ai/docs/agents/sdks/javascript`
- `https://dashboard.sproutsdata.ai/docs/agents/authentication`
- `https://dashboard.sproutsdata.ai/docs/agents/guides/pagination`
- `https://dashboard.sproutsdata.ai/docs/agents/guides/errors/codes`