david-data is the official Python client for the David API. It wraps every endpoint, handles auth and retries, and unwraps responses into plain Python objects.
Install
Authenticate
Pass your key directly, or set theDAVID_DATA_API_KEY environment variable and omit it.
Quickstart
Every data call is keyed by ascenario_id. Pick a scenario from the library, then pull from it.
list of records for collections, a dict for single objects.
Set a default scenario
Repeatingscenario_id= everywhere gets old. Set it once on the client and omit it; override per call when needed.
scenario_id (and no default) raises a clear error instead of guessing.
What you can pull
| Resource | Methods |
|---|---|
dd.prices | get, snapshot, market_snapshot, tickers |
dd.financials | income_statements, balance_sheets, cash_flow_statements, all_statements, metrics, segments, as_reported, kpi_metrics, screener, line_items |
dd.company | list, facts, tickers, ciks |
dd.news / dd.filings | list, get / list, items, types |
dd.earnings / dd.analyst | list, calendar / estimates, notes |
dd.insiders / dd.institutional | trades, transactions / holdings, investors |
dd.index_funds / dd.corporate_actions | list |
dd.macro | series, interest_rates, banks |
dd.events | timeline |
dd.scenarios | list, get, validation |
"2024-01-01") or datetime.date objects.
DataFrames
Convert any result to a pandas DataFrame withto_df (needs the [pandas] extra):
Errors & retries
Every exception subclassesDavidDataError. The client automatically retries 429 and transient 5xx responses with exponential backoff (honoring Retry-After); tune with max_retries=.
| Exception | Raised on |
|---|---|
AuthenticationError | 401 invalid or missing key |
PermissionDeniedError | 403 not allowed |
NotFoundError | 404 unknown scenario, ticker, or id |
BadRequestError | 400 invalid parameters |
RateLimitError | 429 rate limit exceeded (.retry_after) |
ServerError | 5xx server error |
APIConnectionError / APITimeoutError | network failure / timeout |
Escape hatch
Any endpoint not yet wrapped is reachable directly:Client options
| Option | Default | Description |
|---|---|---|
api_key | DAVID_DATA_API_KEY | Your API key. |
scenario_id | none | Default scenario for every data call. |
base_url | https://api.davidhf.com | API root (or DAVID_DATA_BASE_URL). |
timeout | 30.0 | Per-request timeout in seconds. |
max_retries | 3 | Retries for 429 and transient 5xx. |