Skip to main content
The official Python SDK for the Data Legion API. Includes sync and async clients, Pydantic v2 response models, and full type hints.

Installation

Requires Python 3.11+.

Authentication

Get an API key by signing up for free; it’s available in your dashboard as soon as you sign up. The same key works across the API, SDKs, MCP server, and CLI.

Person

Enrichment

Look up a person by email, phone, name, LinkedIn, or other identifiers.
Text comes back lowercase; pass titlecase=True for title case.

Bulk Enrichment

Enrich up to 50 people in one request. Each item takes the same identifiers as enrich(), plus an optional metadata dict echoed back with its result; keyword arguments are defaults every item can override.
Query people with exactly one of three inputs (0.15.0+; see Person Search): filters keyed by the record’s own field names, a SQL SELECT against the people table as sql, or a query object as es_query. SQL must start with SELECT and must not include a LIMIT clause; pass limit as a parameter. The older query argument still works and is deprecated.
For the next page, send the same query with the previous page’s next_cursor as cursor (0.13.0+). The last page has no next_cursor. Each record returned costs a credit, so cap how many you collect.
Location fields (city, state, state_code) come with contact data; on a plan without it, a filter on them is refused with a 400.

Count

How many people a search would match, rounded, with no records returned (0.15.0+). Counts are free and work with no credits left; fields that identify one record are refused. See Person Search Count.

Discover (Beta)

Find people using natural language.
Discover pages the same way (0.14.0+): send the same query with the previous page’s next_cursor as cursor.

Company

Enrichment

Look up a company by domain, name, ticker, or LinkedIn.

Search

Query companies with filters, sql or es_query, exactly one, as for people; client.company.count() takes the same.
Page with cursor as for people (0.13.0+).

Discover (Beta)

Find companies using natural language.
Discover pages with cursor as for people (0.14.0+).

Utility Endpoints

Utility endpoints are free and don’t consume credits.

Clean Fields

Hash Email

Validate Data

Report a Data Issue

Found something wrong in a record? Report it against its legion_id. See Report a Data Issue for the issue_type/issue_level rules.
Company records use client.utility.report_company() with the same parameters.

Async Client

The AsyncDataLegion client has the same interface but all methods are async.

Response Metadata

After each request, response metadata is available on the client.
On search/discover, total_count_status tells you how the response total was derived: exact (true count), estimate (on broad queries where the exact count runs out of time: the matches counted by then, a lower bound, so read it as “at least”), or page (count unavailable; total is the offset plus the rows returned). search_warning carries the Search-Warning header when a search flags one of its filters, and says what to change or what was searched instead.

Field Filtering

Control which fields are returned in the response.

Error Handling

The SDK raises a typed exception for each error status. Every one inherits from DataLegionError, and the classes for 400, 403, 404, 408 and 5xx also inherit from APIError.
The client doesn’t retry. On a 429, client.retry_after holds the seconds to wait.

Sandbox

Pass sandbox=True to build and test without spending credits. Enrichment, Search, Bulk Enrichment and Discover (Beta) then call the sandbox and return sample records with every field a real record has; the utilities, which are free, call the real API.

Configuration

You can also pass a custom httpx client for advanced configuration:

Resources