Python client library for ThetaData market data APIs
Project description
thetadata-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",
)
Common Examples
Stock symbols
from thetadata import ThetaClient
client = ThetaClient()
df = client.stock_list_symbols()
Stock intraday OHLC
from datetime import date, time
from thetadata import ThetaClient
client = ThetaClient()
df = client.stock_history_ohlc(
symbol="AAPL",
date=date(2024, 1, 2),
interval="1m",
start_time=time(9, 30),
end_time=time(16, 0),
)
Option chain snapshot greeks
from datetime import date
from thetadata import ThetaClient
client = ThetaClient()
df = client.option_snapshot_greeks_all(
symbol="SPY",
expiration=date(2025, 3, 21),
strike="*",
right="both",
)
Index history
from datetime import date
from thetadata import ThetaClient
client = ThetaClient()
df = client.index_history_eod(
symbol="SPX",
start_date=date(2024, 1, 2),
end_date=date(2024, 1, 10),
)
DataFrame Output
ThetaClient supports two output modes:
dataframe_type="polars"(default)dataframe_type="pandas"
Logging
import logging
logging.basicConfig(level=logging.INFO)
This will surface library logging, including authentication and request-related messages.
Errors
The package exposes custom exceptions in thetadata.errors:
AuthenticationErrorNoDataFoundError
Example:
from datetime import date
from thetadata import ThetaClient
from thetadata.errors import AuthenticationError, NoDataFoundError
try:
client = ThetaClient()
df = client.stock_history_eod(
symbol="AAPL",
start_date=date(2024, 1, 1),
end_date=date(2024, 1, 31),
)
except AuthenticationError:
print("Authentication failed")
except NoDataFoundError:
print("No data returned for query")
Notes
- Some methods accept
symbol: strwhile others expectsymbol: list[str]. - Snapshot endpoints may return rapidly changing data.
- Time-based requests use
datetime.dateanddatetime.timevalues.
License
Apache-2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file thetadata-1.0.3.tar.gz.
File metadata
- Download URL: thetadata-1.0.3.tar.gz
- Upload date:
- Size: 40.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28143a34e45f75aae340b06da07c0b915f6b5bd548bb53d37a3263e6bb8fc677
|
|
| MD5 |
c8a83410c67f9c44f765a89ca4952df8
|
|
| BLAKE2b-256 |
9f6e54e63654d9bf7cb58e875c71fb78620c185c21129860dd2b63b27be09597
|
Provenance
The following attestation bundles were made for thetadata-1.0.3.tar.gz:
Publisher:
publish.yml on AXIOMXLLC/thetadata-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
thetadata-1.0.3.tar.gz -
Subject digest:
28143a34e45f75aae340b06da07c0b915f6b5bd548bb53d37a3263e6bb8fc677 - Sigstore transparency entry: 1413253034
- Sigstore integration time:
-
Permalink:
AXIOMXLLC/thetadata-python@c7b5eb4d3be872266b8fb462fed726e10a2aceb2 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/AXIOMXLLC
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c7b5eb4d3be872266b8fb462fed726e10a2aceb2 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file thetadata-1.0.3-py3-none-any.whl.
File metadata
- Download URL: thetadata-1.0.3-py3-none-any.whl
- Upload date:
- Size: 40.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d92d96535216b2573637dd8d1a4d35c987bc560641580567904c43088df2ef6e
|
|
| MD5 |
6279f60a7478e852a992c6b3701b3ec9
|
|
| BLAKE2b-256 |
faa1561a603132aa0eedfc6a1d81e927815d3ef81b45509cf57b0d9d071ae9e7
|
Provenance
The following attestation bundles were made for thetadata-1.0.3-py3-none-any.whl:
Publisher:
publish.yml on AXIOMXLLC/thetadata-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
thetadata-1.0.3-py3-none-any.whl -
Subject digest:
d92d96535216b2573637dd8d1a4d35c987bc560641580567904c43088df2ef6e - Sigstore transparency entry: 1413253145
- Sigstore integration time:
-
Permalink:
AXIOMXLLC/thetadata-python@c7b5eb4d3be872266b8fb462fed726e10a2aceb2 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/AXIOMXLLC
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c7b5eb4d3be872266b8fb462fed726e10a2aceb2 -
Trigger Event:
workflow_dispatch
-
Statement type: