Python client library for ThetaData market data APIs
Actively maintained. Last release 13 days ago. A safe choice.
pip install thetadatathetadata-python
Python client library for accessing ThetaData market data APIs over gRPC.
This package provides a ThetaClient for querying US stock, option, and index market data from ThetaData. Results can be returned as either Polars or Pandas DataFrames.
Features
- Direct client access to ThetaData services
- Stock, option, and index endpoints
- Return data as Polars or Pandas DataFrames
- Built-in response decompression
- Simple authentication with a credentials file or explicit credentials
Requirements
- Python 3.12+
- An active ThetaData subscription
Installation
pip install thetadata
Authentication
You can authenticate in three ways.
1. Default credentials file
By default, ThetaClient() looks for ./creds.txt.
File format:
email@example.com
your-password
from thetadata import ThetaClient
client = ThetaClient()
2. Explicit credentials
from thetadata import ThetaClient
client = ThetaClient(email="email@example.com", password="your-password")
3. Environment variable
Set THETADATA_CREDENTIALS_FILE to point to your credentials file.
export THETADATA_CREDENTIALS_FILE=/path/to/creds.txt
$env:THETADATA_CREDENTIALS_FILE = "C:\path\to\creds.txt"
Quick Start
Default Polars output
from datetime import date
from thetadata import ThetaClient
client = ThetaClient()
bars = client.stock_history_eod(
symbol="AAPL",
start_date=date(2024, 1, 2),
end_date=date(2024, 1, 5),
)
print(bars)
Pandas output
from datetime import date
from thetadata import ThetaClient
client = ThetaClient(dataframe_type="pandas")
quotes = client.stock_history_quote(
symbol="AAPL",
date=date(2024, 1, 2),
interval="1m",
)
print(quotes.head())
Reuse authentication across clients
from thetadata import ThetaClient
polars_client = ThetaClient(dataframe_type="polars")
pandas_client = ThetaClient(
existing_authorized_client=polars_client,
dataframe_type="pandas",
)