Skip to main content

ThetaDataDx

thetadatadx (Python)

The Python SDK for ThetaData market data. Pull US stock, option, index, and rate data three ways (point-in-time history, real-time streaming, and whole-universe flat files), all from a single authenticated client. Connects straight to ThetaData; nothing to install and run locally, no local proxy.

PyPI License Python Discord

Features

  • Complete coverage: stocks, options, indices, and rates across 81 typed endpoints.
  • Three access modes, one client: point-in-time history, real-time streaming, and bulk flat-file downloads.
  • Optional bulk fetch: with config.bulk_fetch = "auto", a large history pull runs as several concurrent requests within your account's concurrent-request allowance and is merged back into the rows one request returns. It is off by default, because which splits work depends on what the server accepts. See Bulk Downloads.
  • DataFrames built in: every result chains straight to Polars, pandas, or Arrow over a zero-copy boundary.
  • Typed all the way down: every tick is a typed object with attribute access and IDE completion, not a dict.
  • No terminal to run: a direct connection to ThetaData; nothing to install and babysit locally.

Install

pip install thetadatadx-py

pip install thetadatadx-py[polars]   # Polars DataFrames
pip install thetadatadx-py[pandas]   # pandas DataFrames (Arrow-backed)
pip install thetadatadx-py[arrow]    # raw pyarrow.Table
pip install thetadatadx-py[all]      # every optional adapter

Binary wheels ship for Linux x64 (glibc), macOS arm64 (Apple Silicon), and Windows x64, and require no Rust toolchain. Wheels use CPython's stable ABI (abi3), so one wheel per platform covers Python 3.12 and up; on Linux x64 the free-threaded (3.14t) build runs with the GIL disabled and is selected automatically by pip. Any other platform installs from the source distribution, which needs a Rust toolchain.

Quick start

from thetadatadx import Client

# Pass your API key directly. Use market_data_type="STAGE" to target staging.
client = Client(api_key="td1_...")

# First-order Greeks for every strike on SPY's 2026-06-18 expiry, as of 2024-03-15
greeks = client.market_data.option_history_greeks_first_order("SPY", "20260618", date="20240315")

df = greeks.to_polars()
print(df.select(["strike", "right", "delta", "theta", "vega"]).head())

Other ways to construct the client:

from thetadatadx import Client, Credentials, Config

# API key from the THETADATA_API_KEY environment variable, or from a .env file
client = Client.from_env()
client = Client.from_dotenv(".env")

# Email and password, inline
client = Client(email="you@example.com", password="your_password")

# Full control: build a typed Credentials + Config (custom hosts, timeouts)
client = Client(Credentials.from_file("creds.txt"), Config.production())

Every market-data method returns a typed list. Iterate it, index it, or convert it to a dataframe:

eod = client.market_data.stock_history_eod("AAPL", "20240101", "20240301")
for tick in eod:
    print(f"{tick.date}: O={tick.open:.2f} H={tick.high:.2f} "
          f"L={tick.low:.2f} C={tick.close:.2f} V={tick.volume}")

bars = client.market_data.stock_history_ohlc("AAPL", date="20240315", interval="1m")   # 1-minute bars
exps = client.market_data.option_list_expirations("SPY")
strikes = client.market_data.option_list_strikes("SPY", exps[0])

DataFrames

Every result converts directly to a dataframe, with no row-by-row iteration:

greeks.to_polars()   # polars.DataFrame
greeks.to_pandas()   # pandas.DataFrame   (pip install thetadatadx-py[pandas])
greeks.to_arrow()    # pyarrow.Table      (zero-copy)
greeks.to_list()     # list[GreeksTick]

The .to_arrow() terminal hands the underlying Arrow buffers to pyarrow over the Arrow C Data Interface (zero-copy at the boundary), so the table plugs straight into DuckDB, polars, cuDF, or Arrow Flight:

import duckdb

table = client.market_data.stock_history_eod("AAPL", "20240101", "20240301").to_arrow()
con = duckdb.connect()
con.register("eod", table)                 # zero-copy into DuckDB
con.sql("SELECT AVG(close) FROM eod").show()

List endpoints (stock_list_symbols, option_list_expirations, …) return a StringList with the same terminals; the single column is named by the endpoint (symbol, expiration, …). Empty results still convert to a zero-row frame with the full typed schema.

For multi-day backfills, stream the response instead of buffering it. The builders of the history, at-time and flat-file endpoints, and of option_list_contracts, expose .stream(handler) / .stream_async(handler) beside the buffered .list() / .list_async() every builder has; the handler is called once per chunk with the same typed list a whole result returns, whose frames lead with each row's root when the response carries roots, and the previous chunk is freed before the next is fetched, so peak memory stays flat regardless of total size:

def on_chunk(ticks):
    for t in ticks:
        ...   # write to Parquet, push to a bus, accumulate stats

(client.market_data.option_history_quote_builder("QQQ", "20260515").date("20260515")
    .interval("tick")
    .strike_range(5)
    .stream(on_chunk))

Streaming

Real-time quotes and trades flow through the same client. Register a callback and match on typed event classes: Trade, Quote, Ohlcvc, and OpenInterest for market data, plus one typed class per lifecycle event (Connected, LoginSuccess, Disconnected, Reconnecting, …):

import time
from thetadatadx import Contract, Quote, Trade

def on_event(event):
    match event:
        case Trade(price=px, size=sz, exchange=ex, ms_of_day=ms, sequence=seq, condition=cond, contract=c):
            print(
                f"{c.symbol} {c.expiration} {c.strike} {c.right} trade price={px:.2f} size={sz} "
                f"exchange={ex} ms_of_day={ms} sequence={seq} condition={cond}"
            )
        case Quote(bid=b, ask=a, bid_size=bs, ask_size=asz, bid_exchange=bx, ask_exchange=ax, ms_of_day=ms, contract=c):
            print(
                f"{c.symbol} {c.expiration} {c.strike} {c.right} quote bid={b:.2f} ask={a:.2f} "
                f"bid_size={bs} ask_size={asz} bid_exchange={bx} "
                f"ask_exchange={ax} ms_of_day={ms}"
            )

spy_call = Contract.option("SPY", expiration="20261218", strike="550", right="C")

with client.streaming(on_event) as session:
    session.subscribe_many([spy_call.quote(), spy_call.trade()])
    time.sleep(60)   # park the main thread while events flow into on_event

Build subscriptions with the fluent Contract API and pass them, one at a time or in bulk, to subscribe / subscribe_many. Every subscription is the same typed value, so quotes, trades, open interest, and market value across contracts mix freely in one list:

from thetadatadx import Contract, SecType

stock  = Contract.stock("AAPL")
option = Contract.option("SPY", expiration="20261218", strike="550", right="C")

with client.streaming(on_event) as session:
    session.subscribe(stock.quote())
    session.subscribe_many([option.quote(), option.trade(), option.open_interest(), option.market_value()])

The option constructor is Contract.option(symbol, *, expiration, strike, right). The leg parameters are keyword-only, so the call site always reads expiration=…, strike=…, right=… and never depends on argument order. Pair it with Contract.stock(symbol) for equities.

Or take a whole-market feed: every option trade across the universe, with no per-contract setup. The full-trade feed sends a quote and an OHLC bar before each trade, so add an Ohlcvc case to the callback to handle the bars:

from thetadatadx import Ohlcvc

def on_full_trade(event):
    match event:
        case Ohlcvc(open=o, high=h, low=lo, close=cl, volume=v, contract=c):
            print(
                f"{c.symbol} {c.expiration} {c.strike:g} {c.right} bar "
                f"o={o:.2f} h={h:.2f} l={lo:.2f} c={cl:.2f} volume={v}"
            )
        case _:
            on_event(event)   # reuse the quote/trade handling above

with client.streaming(on_full_trade) as session:
    session.subscribe(SecType.OPTION.full_trades())
    time.sleep(60)   # the callback runs on the streaming thread, so keep it fast

Watch feed health from the main thread without touching the callback. The session resolves the client's observability getters directly: millis_since_last_event() is the staleness clock (a steadily growing value is the earliest sign of a wedged link), ring_occupancy() against ring_capacity() shows how close the consumer is to falling behind, and dropped_event_count() is the cumulative tally of events shed on a full ring:

with client.streaming(on_event) as session:
    session.subscribe(SecType.OPTION.full_trades())
    while True:
        time.sleep(5)
        stale_ms = session.millis_since_last_event()   # None until the first frame
        print(
            f"stale={stale_ms}ms "
            f"ring={session.ring_occupancy()}/{session.ring_capacity()} "
            f"dropped={session.dropped_event_count()}"
        )

Prefer columns? client.stream.batches(...) is a sibling to the callback: the same subscriptions, delivered as pyarrow.RecordBatch values under a fixed schema. The reader is iterable (sync, releasing the GIL on the blocking pull) and async-iterable, and closes on context-manager exit:

# `batches(...)` starts the streaming session, so open it first, then subscribe.
with client.stream.batches(batch_size=8192) as batches:
    client.stream.subscribe(Contract.stock("AAPL").trade())
    for batch in batches:        # or: async for batch in batches
        print(batch.num_rows)

Flat files

Whole-universe files for one date. Each file the vendor serves is an endpoint like any other: option eod, trade_quote, open_interest and quote; stock eod, trade_quote and quote; index eod. Results chain through the same DataFrame terminals as history:

eod = client.market_data.stock_flat_file_eod("20260428")
df = eod.to_polars()                        # leads with each row's `symbol`

# The large files stream chunk by chunk; a download that keeps streaming has no time limit.
# Each chunk is a typed list like a whole result, its frames led by `symbol`.
(client.market_data
    .option_flat_file_trade_quote_builder("20260428")
    .stream(lambda chunk: print(len(chunk))))

Each file also writes straight to disk, exactly as the terminal writes it, through its <endpoint>_to_path companion (and _to_path_async in a coroutine), which returns the path written. format is "csv" (the default), "json", "json_legacy", "ndjson" or "html":

path = client.market_data.option_flat_file_trade_quote_to_path("20260428", "trade_quotes.csv")

Endpoint coverage

83 typed endpoints across stocks, options, indices, the market calendar, interest rates and corporate actions, plus real-time streaming.

Category Endpoints Examples
Stock 16 EOD, OHLC, trades, quotes, snapshots, at-time, flat files
Option 51 Every stock surface plus every Greeks tier in both the Black-Scholes and binomial families, open interest, contract lists
Index 10 EOD, OHLC, price, snapshots, flat files
Calendar 3 Market open/close, holidays, early closes
Interest rate 1 EOD rate history
Corporate action 2 Dividends, splits

Every endpoint is a method on client.market_data, with an *_async awaitable companion and a *_builder for the fluent form. The full per-method list with signatures lives in the API reference; Config.dev() and Config.stage() target the non-production environments.

Errors

Every call raises a typed exception under a common ThetaDataError base (AuthenticationError, RateLimitError, NotFoundError, DeadlineExceededError, InvalidParameterError, and the rest), so the same cases are catchable here exactly as they are in every other binding.

Documentation

License

Licensed under the Apache License, Version 2.0.

Metadata

Release files for thetadatadx-py 0.11.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for thetadatadx-py 0.11.0
File Size Uploaded Provenance Actions
thetadatadx_py-0.11.0.tar.gz 989.9 kB Without provenance Details for thetadatadx_py-0.11.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for thetadatadx-py 0.11.0
File Actions
thetadatadx_py-0.11.0-cp314-cp314t-manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.28+ x86-64 Details for thetadatadx_py-0.11.0-cp314-cp314t-manylinux_2_28_x86_64.whl
thetadatadx_py-0.11.0-cp312-abi3-win_amd64.whl CPython 3.12 abi3 Windows x86-64 Details for thetadatadx_py-0.11.0-cp312-abi3-win_amd64.whl
thetadatadx_py-0.11.0-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.12 abi3 Linux glibc 2.17+ x86-64 Details for thetadatadx_py-0.11.0-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
thetadatadx_py-0.11.0-cp312-abi3-macosx_11_0_arm64.whl CPython 3.12 abi3 macOS 11.0+ ARM64 Details for thetadatadx_py-0.11.0-cp312-abi3-macosx_11_0_arm64.whl

Total release size: 47.2 MB

Release files / thetadatadx_py-0.11.0.tar.gz

Download URL thetadatadx_py-0.11.0.tar.gz
Size 989.9 kB
Tags Source
SHA-256 checksum
How to use checksums
400c8e00a523be24f3122c565b72a8f8c2da302fd165b2c6470fe63ac45f16b0
BLAKE2b-256 checksum
How to use checksums
1b217e6791adf0480cfeaa162e12b2eecbed74270c07f8dc020ff89cd45031d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / thetadatadx_py-0.11.0-cp314-cp314t-manylinux_2_28_x86_64.whl

Download URL thetadatadx_py-0.11.0-cp314-cp314t-manylinux_2_28_x86_64.whl
Size 11.8 MB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
5aec2425ede2cb7c539ed7ee97c451272474466819dd432ff123ccb11b0de7d0
BLAKE2b-256 checksum
How to use checksums
862f60214161271e7df8bc7d6fa0d4b917a89ffd880e51a2637e674543958aa0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / thetadatadx_py-0.11.0-cp312-abi3-win_amd64.whl

Download URL thetadatadx_py-0.11.0-cp312-abi3-win_amd64.whl
Size 11.7 MB
Tags CPython 3.12 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
8d9cee893980e49e594dd0fb66323d3b6e465407da78713b8c0c2b96f829537c
BLAKE2b-256 checksum
How to use checksums
3b399f4cb6c75eca4081f69ca94531ee4d49d4507fd4730c184d5a8e65d99e8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / thetadatadx_py-0.11.0-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL thetadatadx_py-0.11.0-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 11.8 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
f171b91d6285d82ac0d8e9aca556363e0863059044d857f8c3a0f617bca65e6b
BLAKE2b-256 checksum
How to use checksums
818ecb2df5fda71ed1c995e9e74f67d907de66bedd3f10902a5691a11d369d1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / thetadatadx_py-0.11.0-cp312-abi3-macosx_11_0_arm64.whl

Download URL thetadatadx_py-0.11.0-cp312-abi3-macosx_11_0_arm64.whl
Size 11.1 MB
Tags CPython 3.12 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
84d778f6e45fcc1a6f218c5c65affaec1b79bb4f4f17ab7a6660189abfc2b9bd
BLAKE2b-256 checksum
How to use checksums
0c3cc9119915217e3376e3006cabe88061cea517011bf4062819a82f5f11959c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for thetadatadx-py 0.11.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page