Metadata-Version: 2.5
Name: tickerdb
Version: 1.1.0
Summary: Market data for AI agents: point-in-time technicals, fundamentals, SEC filings, insider trades and macro. The official Python client for the TickerDB API.
Project-URL: Homepage, https://tickerdb.com
Project-URL: Documentation, https://tickerdb.com/docs
Project-URL: Repository, https://github.com/tickerdb/tickerdb-python
Project-URL: Changelog, https://github.com/tickerdb/tickerdb-python/blob/main/CHANGELOG.md
Project-URL: Issues, https://github.com/tickerdb/tickerdb-python/issues
Author-email: TickerDB <support@tickerdb.com>
License-Expression: MIT
License-File: LICENSE
Keywords: api,backtesting,crypto,etf,finance,market-data,point-in-time,sec-filings,stocks
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Office/Business :: Financial :: Investment
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: httpx>=0.24.0
Provides-Extra: dev
Requires-Dist: pandas>=1.5; extra == 'dev'
Requires-Dist: pytest>=7.0; extra == 'dev'
Requires-Dist: ruff>=0.4; extra == 'dev'
Provides-Extra: pandas
Requires-Dist: pandas>=1.5; extra == 'pandas'
Description-Content-Type: text/markdown

# TickerDB for Python

[![PyPI version](https://img.shields.io/pypi/v/tickerdb.svg)](https://pypi.org/project/tickerdb/)
[![Python versions](https://img.shields.io/pypi/pyversions/tickerdb.svg)](https://pypi.org/project/tickerdb/)

**Market data for AI agents.** Technicals, fundamentals, SEC filings, insider trades and macro, ready to search and backtest. This is the official Python client for the [TickerDB API](https://tickerdb.com/docs).

- **10,000+ tickers.** US stocks, ETFs and crypto, daily and weekly.
- **Full-market screening.** Filter every stock on any field and any date, in one call.
- **Point in time.** Each date only uses data that was public by then, without lookahead bias.
- **Direct from the SEC.** Built from SEC EDGAR filings: 10-K, 10-Q, 8-K, Form 4, 13F and N-PORT.

**Work 6.2x faster, on 55% fewer tokens.** TickerDB does the computing for you: trends, patterns and valuations for every stock, with their history, as named bands (`momentum_rsi_zone = "oversold"`) plus raw values. So there's no pipeline to build. You just ask for what you want. See the [benchmarks](https://tickerdb.com/benchmarks).

```bash
pip install "tickerdb[pandas]"
```

```python
import tickerdb

tickerdb.login()                      # once: approve in the browser, the key is saved
db = tickerdb.TickerDB()

db.summary("AAPL")["trend"]["direction"]          # 'strong_uptrend'

# Screen the whole market, as a DataFrame
db.search(
    filters=[{"field": "momentum_rsi_zone", "op": "eq", "value": "oversold"},
             {"field": "market_cap_usd", "op": "gt", "value": 10e9}],
    fields=["ticker", "sector", "momentum_rsi_value"],
).to_frame()

# Every daily bar since 2019, across pages
bars = tickerdb.frame(db.iter_ohlcv("AAPL", start="2019-01-01", order="asc"))
```

## The key

`TickerDB()` looks for a key in this order: the `api_key` argument, the `TICKERDB_API_KEY` environment variable, then the key `tickerdb.login()` saved (`~/.config/tickerdb/config.json`, on Windows `%APPDATA%\tickerdb\config.json`). You can also create a key in the [dashboard](https://tickerdb.com/dashboard/keys).

## Methods

One method per endpoint, with the endpoint's parameters as keyword arguments. Your editor shows each one's parameters and allowed values.

| Method | Endpoint | What it returns |
| --- | --- | --- |
| `summary(ticker)` | `/v1/summary/{ticker}` | One asset's full snapshot; also a past date, a date range, or band events |
| `ohlcv(ticker)` | `/v1/ohlcv/{ticker}` | Daily or weekly price bars |
| `search()` | `/v1/search` | Assets matching filters, on the latest or any past date |
| `universe(fields)` | `/v1/universe` | Chosen fields for every asset on one date |
| `history()` | `/v1/history` | Chosen fields for many assets over a date range |
| `market()` | `/v1/market` | Market and macro fields per date |
| `diff(tickers)` | `/v1/diff` | What changed for some tickers |
| `statements(ticker)`, `statement_lines()` | `/v1/statements` | Financial statements from SEC filings, point in time |
| `insiders()`, `insider_trades(insider)`, `insider_holdings(insider)` | `/v1/insiders` | Company insiders, 13F institutions, members of Congress |
| `funds()`, `fund_holdings(fund)`, `fund_holders(ticker)` | `/v1/funds` | Fund holdings from SEC N-PORT filings |
| `indexes()`, `index_members(index)` | `/v1/indexes` | Index membership on a date |
| `models()`, `model(slug)`, `model_history(slug)`, `model_holdings(slug)`, `model_trades(slug)`, `models_holdings()` | `/v1/models` | TickerDB's open-source trading models |
| `watchlist()`, `watchlist_add(tickers)`, `watchlist_remove(tickers)`, `watchlist_diff()` | `/v1/watchlist` | Your watchlist and what changed for it |
| `schema()`, `status()`, `account()` | | The field list, release times, your plan and usage |

Lists can be Python lists (`fields=["ticker", "sector"]`), dates can be `date` objects, and filters are a list of `{"field", "op", "value"}` dicts. The endpoint pages in the [docs](https://tickerdb.com/docs) describe every parameter and response.

## Results

Every method returns a `Result`: the response's JSON as a `dict`, with three additions.

```python
result = db.ohlcv("AAPL", limit=5)
result["bars"]        # the JSON, as documented
result.rows           # the rows, whatever the endpoint calls them
result.to_frame()     # the rows as a pandas DataFrame
result.usage          # {'limit': 200000, 'used': 42, 'remaining': 199958, ...}
```

## Paging

Endpoints that page have an `iter_...` twin that returns every row, fetching pages as you go:

```python
for trade in db.iter_insider_trades("jeffrey-p-bezos", start="2024-01-01"):
    ...

panel = tickerdb.frame(db.iter_history(
    tickers=["AAPL", "MSFT", "NVDA"],
    fields=["trend_direction", "momentum_rsi_zone", "fundamentals_pe_ratio"],
    timeframe="weekly", start="2019-01-01",
))
```

`max_rows=` stops early. `history()` with thousands of tickers is sent as a POST by itself.

## Fields

```python
from tickerdb import fields

fields.find("rsi zone")                        # ['momentum_rsi_zone', 'momentum_rsi_zone_prev', ...]
fields.TICKER["momentum_rsi_zone"].values      # ('deep_oversold', 'oversold', 'neutral_low', ...)
```

`fields.TICKER`, `fields.MARKET` and `fields.MODEL` list every field with its type, band values and description. `db.schema(search="bull flag")` asks the API instead, with full descriptions.

## Search builder

```python
db.query().eq("trend_direction", "strong_uptrend").gte("market_cap_usd", 2e9) \
    .member_of("sp500").select("ticker", "sector").sort("market_cap_usd").limit(50).execute()
```

## Errors

```python
try:
    db.summary("AAPL", date="2015-01-02")
except tickerdb.PlanRestrictedError as error:      # the date is before your plan's history
    print(error.message, error.upgrade_url)
except tickerdb.TickerDBError as error:            # any API error
    print(error.status_code, error.error_type, error.message)
```

`InvalidRequestError` (400), `AuthenticationError` (401), `InsufficientCreditsError` (402), `PlanRestrictedError` (403), `NotFoundError` (404), `RateLimitError` (429) and `ServiceUnavailableError` (503) all subclass `TickerDBError`. Network errors and 429, 502, 503 and 504 are retried twice before they are raised (`max_retries=`). Only successful responses cost credits.

## Async

```python
from tickerdb import AsyncTickerDB

async with AsyncTickerDB() as db:
    summary = await db.summary("AAPL")
    async for bar in db.iter_ohlcv("AAPL", start="2019-01-01"):
        ...
```

## How this library stays current

The methods and the field tables are generated from TickerDB's own OpenAPI document, which the API builds from its routes: <https://api.tickerdb.com/v1/openapi.json>. A copy is in this repository as `openapi.json`.

```bash
python scripts/generate.py --update    # fetch the newest document and regenerate
python -m pytest                       # the tests compare the library with the document
python -m pytest -m live               # a few real calls (needs a key)
```

A push to `main` with a new version in `src/tickerdb/_version.py` is published to PyPI by `.github/workflows/publish.yml`.

## Upgrading from 0.2

1.0 is a rewrite for the current API, and it breaks 0.2 code.

- Methods return the response itself, not `{"data": ..., "rate_limits": ...}`. Use `result[...]` and `result.usage`.
- `base_url` no longer includes `/v1`.
- `ForbiddenError` is now `PlanRestrictedError`; `DataUnavailableError` is `ServiceUnavailableError`.
- Field names are the API's current ones (`db.schema()` lists them).

## License

MIT
