Skip to main content

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 Client 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, Client() looks for ./creds.txt.

File format:

email@example.com
your-password
from thetadata import Client

client = Client()

2. Explicit credentials

from thetadata import Client

client = Client(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 Client

client = Client()

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 Client

client = Client(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 Client

polars_client = Client(dataframe_type="polars")
pandas_client = Client(
    existing_authorized_client=polars_client,
    dataframe_type="pandas",
)

Common Examples

Stock symbols

from thetadata import Client

client = Client()
df = client.stock_list_symbols()

Stock intraday OHLC

from datetime import date, time
from thetadata import Client

client = Client()
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 Client

client = Client()
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 Client

client = Client()
df = client.index_history_eod(
    symbol="SPX",
    start_date=date(2024, 1, 2),
    end_date=date(2024, 1, 10),
)

DataFrame Output

Client 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:

  • AuthenticationError
  • NoDataFoundError

Example:

from datetime import date
from thetadata import Client
from thetadata.errors import AuthenticationError, NoDataFoundError

try:
    client = Client()
    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: str while others expect symbol: list[str].
  • Snapshot endpoints may return rapidly changing data.
  • Time-based requests use datetime.date and datetime.time values.

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

thetadata-1.0.1.tar.gz (40.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

thetadata-1.0.1-py3-none-any.whl (40.3 kB view details)

Uploaded Python 3

File details

Details for the file thetadata-1.0.1.tar.gz.

File metadata

  • Download URL: thetadata-1.0.1.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

Hashes for thetadata-1.0.1.tar.gz
Algorithm Hash digest
SHA256 dbedf3bd4b6f2ae376a5719fb951ff7c5685a060545ec84f4184296c0ed63200
MD5 75b08ee499c125b772c44b681e000968
BLAKE2b-256 73c371c1ec3138066b14dcd47b0d9c54bbd9255bfc4a5758a1d39231d7936438

See more details on using hashes here.

Provenance

The following attestation bundles were made for thetadata-1.0.1.tar.gz:

Publisher: publish.yml on AXIOMXLLC/thetadata-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file thetadata-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: thetadata-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 40.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for thetadata-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d7b37e74b1be1fa592e00a67f2f1e9446b2e0abed8d10dc660a2993e0b4af972
MD5 10b0da822d2fe9a721ff06343d92732f
BLAKE2b-256 9a1fa48bc74f3bafdb4aedc7e7c5ad084f967f45b2a81ee780d93c1a87dac7f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for thetadata-1.0.1-py3-none-any.whl:

Publisher: publish.yml on AXIOMXLLC/thetadata-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page