Skip to main content

Python SDK for the Polaris market data API

Project description

Polaris SDK

The official Rust and Python SDKs for the Polaris API, implemented by one shared Rust engine. The crates.io package and Rust crate are both named polaris-data; the PyPI distribution is also polaris-data and imports as polaris_data.

The workspace contains:

  • crates/polaris-data: public async and blocking Rust APIs.
  • crates/polaris-python: private PyO3 extension module.
  • python/polaris_data: typed, handwritten Python compatibility facade.

Documentation can be found at https://polaris.supply/docs

Install

Install the Python SDK from PyPI:

pip install polaris-data

If you use uv, install it into a project with:

uv add polaris-data

Or install it into the active environment with:

uv pip install polaris-data

Install the Rust SDK from crates.io:

cargo add polaris-data

Python wheels always include the Rust core. CPython 3.9+ is supported through PyO3's stable ABI; there is no pure-Python runtime fallback.

Quickstart

from polaris_data import PolarisClient

with PolarisClient(api_key="polaris_key_your_key") as client:
    row_count = sum(
        1
        for _ in client.replay(
            source="binance",
            market="BTC-USDT",
            from_="2024-01-01T00:00:00Z",
            to="2024-01-01T01:00:00Z",
        )
    )
    print(f"Replayed {row_count} rows")

If api_key is omitted, the client reads POLARIS_API_KEY from the environment.

The equivalent async Rust workflow is:

use futures_util::StreamExt;
use polaris_data::{PolarisClient, ReplayQuery};

#[tokio::main]
async fn main() -> Result<(), polaris_data::PolarisError> {
    let client = PolarisClient::builder().build()?;
    let mut rows = client
        .replay(ReplayQuery {
            source: "binance".into(),
            market: "BTC-USDT".into(),
            from: Some("2024-01-01T00:00:00Z".into()),
            to: Some("2024-01-01T01:00:00Z".into()),
            allow_gaps: false,
        })
        .await?;

    while let Some(row) = rows.next().await {
        println!("{:?}", row?);
    }
    Ok(())
}

For synchronous Rust applications use polaris_data::blocking::PolarisClient. It owns a Tokio runtime and returns PolarisError::BlockingInAsyncRuntime when called from an active Tokio runtime, instead of panicking.

PolarisClient API

PolarisClient is the main sync client for the SDK:

PolarisClient(
    api_key=None,
    base_url="https://api.polaris.supply",
    timeout=30.0,
    dataset_root=None,
)

Use it to inspect available data and query historical market data.

Discovery

Method Returns Use case
health() API health/status payload Connectivity checks and startup validation
catalog(source=None, market=None, q=None) Source/market metadata, including normalized instrument fields Discover supported datasets, markets, instrument metadata, and time coverage

Access patterns

Method Returns Use case
replay(source=..., market=..., from_=None, to=None, standard=True, allow_gaps=False, parallel=False) Iterator of historical events Backfills, notebooks, and replay-style processing without materializing everything up front
raw(source=..., market=..., from_=None, to=None, limit=1000) List of raw source payloads Inspect exchange-native payloads and compare raw vs standardized schemas

Standardized Data Schemas

Method Returns Use case
events(source=..., market=..., from_=None, to=None, allow_gaps=False) List of standardized historical events General-purpose historical analysis when you want the normalized event stream in memory
trades(source=..., market=..., from_=None, to=None, allow_gaps=False) List of standardized trade events Trade-level analytics, execution studies, and derived bar calculations
l2_snapshots(source=..., market=..., from_=None, to=None, allow_gaps=False) List of standardized orderbook snapshot rows Order book reconstruction and microstructure analysis
funding_rates(source=..., market=..., from_=None, to=None, allow_gaps=False) List of funding-rate point series rows Perpetual funding studies and carry modeling
mark_prices(source=..., market=..., from_=None, to=None, allow_gaps=False) List of mark-price point series rows Basis analysis, mark tracking, and liquidation-related research
ohlcv(source=..., market=..., from_=None, to=None, interval=..., format=None, allow_gaps=False) Aggregated OHLCV bars Charting, bar-based strategies, and downstream TA workflows
volume(source=..., market=..., from_=None, to=None, interval=..., allow_gaps=False) Bucketed trade volume series Volume profiling and participation analysis
vwap(source=..., market=..., from_=None, to=None, interval=..., allow_gaps=False) Bucketed VWAP series Execution benchmarking and price smoothing
volatility(source=..., market=..., from_=None, to=None, interval=..., method="log_returns", allow_gaps=False) Bucketed realized volatility series Risk modeling and intraperiod volatility analysis
bbo(source=..., market=..., from_=None, to=None, allow_gaps=False) Best bid/offer quote series Spread tracking, quote analytics, and top-of-book monitoring
depth_metrics(source=..., market=..., from_=None, to=None, depth_pct=0.01, slippage_notional=10000.0, allow_gaps=False) Derived depth, spread, imbalance, and slippage metrics Liquidity analysis and market impact estimation

For parameter details, response shapes, and end-to-end examples, see the Python SDK docs.

Local dataset storage

Standardized snapshots are stored under the shared Polaris app-data root so the Python SDK and CLI can reuse the same files. Legacy materialized day files are also recognized when present.

Default roots:

  • macOS: ~/Library/Application Support/polaris
  • Linux: $XDG_DATA_HOME/polaris or ~/.local/share/polaris
  • Windows: %APPDATA%\\polaris

Within that root, the SDK uses the same layout as the CLI:

<root>/
  data/
  daily/
  tmp/
  cache/
  locks/

Standardized snapshot downloads are stored under:

<root>/data/<tier>/<source>/<market>/<YYYY-MM-DD>/<opaque-key>.jsonl.zst

The opaque key is the flat upstream snapshot identifier, for example:

standard-aster-ASTERUSDT-2026-06-01-00

which is stored on disk as:

<root>/data/standard/aster/ASTERUSDT/2026-06-01/standard-aster-ASTERUSDT-2026-06-01-00.jsonl.zst

Compatible materialized day files, when present, are stored under:

<root>/daily/<source>/<market>/<YYYY-MM-DD>.jsonl.zst

Pass dataset_root=... to PolarisClient(...) to override the root explicitly. POLARIS_ROOT overrides the shared root globally. POLARIS_DATASET_DOWNLOAD_DIR is still accepted as a deprecated compatibility override.

Snapshot-first replay

For standardized historical data, replay(...), events(...), trades(...), vwap(...), volatility(...), bbo(...), depth_metrics(...), l2_snapshots(...), volume(...), and default/tradingview ohlcv(...) now prefer /snapshots plus daily bulk /download?source=...&market=...&date=...&mode=json manifests, and reuse local snapshot files when they already exist:

from polaris_data import PolarisClient

with PolarisClient(api_key="polaris_key_your_key") as client:
    for row in client.replay(
        source="binance",
        market="BTC-USDT",
        from_="2024-01-01T00:00:00Z",
        to="2024-01-01T01:00:00Z",
    ):
        print(row)

If the requested standardized range cannot be satisfied from available standardized snapshots, replay(...), events(...), trades(...), vwap(...), volatility(...), bbo(...), depth_metrics(...), l2_snapshots(...), volume(...), and ohlcv(...) raise by default instead of falling back. Pass allow_gaps=True on standardized methods to return only covered data and receive a warning with the missing intervals.

Error handling

from polaris_data import PolarisClient, RateLimitedError, UnauthorizedError

client = PolarisClient()

try:
    client.replay(
        source="binance",
        market="BTC-USDT",
        from_="2024-01-01T00:00:00Z",
        to="2024-01-01T01:00:00Z",
    )
except UnauthorizedError:
    print("API key is required")
except RateLimitedError as err:
    print(f"Rate limited. Reset at: {err.reset_at}")

Tests

uv run pytest
cargo test --workspace

Build and inspect the native Python wheel with:

uv run --with maturin maturin build --release

Python and Rust are versioned independently. Python releases use python-vX.Y.Z tags and publish polaris-data to PyPI; Rust releases use rust-vX.Y.Z tags and publish polaris-data to crates.io.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

polaris_data-0.9.0.tar.gz (57.3 kB view details)

Uploaded Source

Built Distributions

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

polaris_data-0.9.0-cp39-abi3-win_arm64.whl (2.8 MB view details)

Uploaded CPython 3.9+Windows ARM64

polaris_data-0.9.0-cp39-abi3-win_amd64.whl (3.0 MB view details)

Uploaded CPython 3.9+Windows x86-64

polaris_data-0.9.0-cp39-abi3-musllinux_1_2_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ x86-64

polaris_data-0.9.0-cp39-abi3-musllinux_1_2_aarch64.whl (3.6 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ ARM64

polaris_data-0.9.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

polaris_data-0.9.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.4 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

polaris_data-0.9.0-cp39-abi3-macosx_11_0_arm64.whl (3.0 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

polaris_data-0.9.0-cp39-abi3-macosx_10_12_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file polaris_data-0.9.0.tar.gz.

File metadata

  • Download URL: polaris_data-0.9.0.tar.gz
  • Upload date:
  • Size: 57.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for polaris_data-0.9.0.tar.gz
Algorithm Hash digest
SHA256 5d5bab1d2744a11519791e03559e619648cd312001e6d1c5a1591d29058418bd
MD5 c13039d937d7e9465ec54f96ad7f5558
BLAKE2b-256 cc1df17ff2fdbaa8ae37fac9e698134ec5ae78e1820b2ae283e700f4a721b213

See more details on using hashes here.

Provenance

The following attestation bundles were made for polaris_data-0.9.0.tar.gz:

Publisher: release-python.yml on polaris-data/sdks

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

File details

Details for the file polaris_data-0.9.0-cp39-abi3-win_arm64.whl.

File metadata

  • Download URL: polaris_data-0.9.0-cp39-abi3-win_arm64.whl
  • Upload date:
  • Size: 2.8 MB
  • Tags: CPython 3.9+, Windows ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for polaris_data-0.9.0-cp39-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 38eba115f9c43b204caec0b12db40d1480ffe913120b619684b0c271391f4a28
MD5 849df0fac09770ab3d7af9f7d35e7135
BLAKE2b-256 2e28885c67ce4c4aa3025c272898a27a927404d8bdd922fefe2e5411bc9663b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for polaris_data-0.9.0-cp39-abi3-win_arm64.whl:

Publisher: release-python.yml on polaris-data/sdks

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

File details

Details for the file polaris_data-0.9.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: polaris_data-0.9.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 3.0 MB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for polaris_data-0.9.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 0ad846481503b4211bad2c92c57cefa278c5ccc12d5873aacd5158a16deeb3f9
MD5 c64d57e546eee1e53e99b32c4e0874ba
BLAKE2b-256 978389258d051486f1db7a95344f18ca6d71925a39769dfaf46751608fe33375

See more details on using hashes here.

Provenance

The following attestation bundles were made for polaris_data-0.9.0-cp39-abi3-win_amd64.whl:

Publisher: release-python.yml on polaris-data/sdks

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

File details

Details for the file polaris_data-0.9.0-cp39-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for polaris_data-0.9.0-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5e8655382ad6024870971fa7e370060c22719ac4cc66328eed69bc25844ac61d
MD5 8986a50246bc8841028c0572f5d199e7
BLAKE2b-256 9593da8786cf16ee243ac59913df6acecfc707d2c70b8b331f82038cd6a2f3f9

See more details on using hashes here.

Provenance

The following attestation bundles were made for polaris_data-0.9.0-cp39-abi3-musllinux_1_2_x86_64.whl:

Publisher: release-python.yml on polaris-data/sdks

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

File details

Details for the file polaris_data-0.9.0-cp39-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for polaris_data-0.9.0-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 4008c06e85758f30f5c5c5f13258e4053298fd778cdc34ae764d38029c7c32db
MD5 77e5cf552c569c0c5590862abfb0a830
BLAKE2b-256 34044eb64e3cf9f3601aabdb68238a400e512e76e7647c1c920fc4c86f324835

See more details on using hashes here.

Provenance

The following attestation bundles were made for polaris_data-0.9.0-cp39-abi3-musllinux_1_2_aarch64.whl:

Publisher: release-python.yml on polaris-data/sdks

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

File details

Details for the file polaris_data-0.9.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for polaris_data-0.9.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 42cfdfaab070c42cbe58dc5917021ee1527b59550d03934a8a7a88b386269478
MD5 323b22c45567be4fc9e5412f31b0eaac
BLAKE2b-256 55d844fe2d15ce8f0d003cda1a0d55d09bd89aa1446677208d64aa93f84c1860

See more details on using hashes here.

Provenance

The following attestation bundles were made for polaris_data-0.9.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release-python.yml on polaris-data/sdks

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

File details

Details for the file polaris_data-0.9.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for polaris_data-0.9.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 52657aa09d30d8df03e8bb6ecee34a9ce98a9cdb5d17f58a70a36c199285e7ac
MD5 c3314620a0de640a32d38bcf7b90ad72
BLAKE2b-256 7ca304c066a7e2e56c187b2bec3de7871afa05ac8ff62b1d9a6ae8b7dba43c3b

See more details on using hashes here.

Provenance

The following attestation bundles were made for polaris_data-0.9.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release-python.yml on polaris-data/sdks

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

File details

Details for the file polaris_data-0.9.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for polaris_data-0.9.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c64711dfbaf3a8cb7a1a31fd32132b2efc6c4cc334b6f6009cde3dbc14061ea6
MD5 81b94803a876aeac2b0204eb0edd19e9
BLAKE2b-256 7c7774a0f99bc27b6314a874adfd82ab423bdc1020c29f77a23e73759a45516b

See more details on using hashes here.

Provenance

The following attestation bundles were made for polaris_data-0.9.0-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: release-python.yml on polaris-data/sdks

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

File details

Details for the file polaris_data-0.9.0-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for polaris_data-0.9.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 45f0b4c22fb0008c6164fbd22fc93c450ac46c818991146addfc46bc70ba3e10
MD5 7bf0bc0ac96cf964b8104e45a0366bee
BLAKE2b-256 b8535d84b939f1fb41658a5149f7d1a2ad4e871726c813c5a7df1b06540f1b27

See more details on using hashes here.

Provenance

The following attestation bundles were made for polaris_data-0.9.0-cp39-abi3-macosx_10_12_x86_64.whl:

Publisher: release-python.yml on polaris-data/sdks

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