Skip to main content

Python SDK for the Polaris market data API

Project description

polaris-py

Python SDK for the Polaris API, optimized for notebook workflows and trading scripts. Documentation can be found at https://polaris.supply/docs

Install

Install the published 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

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.

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

  • health(): Check API availability.
  • catalog(source=None, market=None): Browse supported sources and markets.
  • list_snapshots(source=..., market=..., from_=..., to=..., limit=1000): List available snapshot files for a time range.

Historical data

  • replay(source=..., market=..., from_=..., to=..., standard=True, parallel=False): Stream historical events for backfills, notebooks, or replay-style processing.
  • events(source=..., market=..., from_=..., to=...): Return standardized historical events as a list.
  • trades(source=..., market=..., from_=..., to=...): Return standardized trade events as a list.
  • raw(source=..., market=..., from_=..., to=..., limit=1000): Return raw source payloads as a list.
  • ohlcv(source=..., market=..., from_=..., to=..., interval=..., format=None): Aggregate OHLCV bars from standardized trade data.

For historical event queries, standard=True is the default. Pass standard=False when you explicitly want raw schema payloads through replay(...). Methods that take from_ and to accept ISO 8601 strings, datetime, date, or Unix epoch microseconds.

Example:

from polaris_data import PolarisClient

with PolarisClient(api_key="polaris_key_your_key") as client:
    catalog = client.catalog()
    print(catalog)

    rows = client.events(
        source="binance",
        market="BTC-USDT",
        from_="2024-01-01T00:00:00Z",
        to="2024-01-01T01:00:00Z",
    )
    print(len(rows))

Example response shape:

{
    "sources": [
        {"id": "binance", "markets": ["BTC-USDT"]},
        {"id": "hyperliquid", "markets": ["BTC", "ETH"]},
    ]
}

Local dataset storage

Standardized snapshots and local day files are stored under the shared Polaris app-data root so the Python SDK and CLI can reuse the same files.

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/

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(...), and default/tradingview ohlcv(...) now prefer /snapshots + /snapshots/download and read from local day 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 daily snapshots, replay(...), events(...), trades(...), and ohlcv(...) now raise instead of falling back.

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

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.7.0.tar.gz (55.9 kB view details)

Uploaded Source

Built Distribution

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

polaris_data-0.7.0-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: polaris_data-0.7.0.tar.gz
  • Upload date:
  • Size: 55.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for polaris_data-0.7.0.tar.gz
Algorithm Hash digest
SHA256 38402acc643e575531e2a1717332b48d6151b3a033f7a6443d6dfd1422d789ec
MD5 095b4a1ad09115d8f21ca51b60a5ee11
BLAKE2b-256 9f1cd244a126741d00fd241f10757a3261f95543226844014f7c9f95ab8f97f3

See more details on using hashes here.

File details

Details for the file polaris_data-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: polaris_data-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for polaris_data-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 53a4a62526d75f84f0b6e97607b510dec8fb029f7e717697307463c2f06122cb
MD5 7c79992966baf26bcbdfa0cccf290719
BLAKE2b-256 9b8a35ec89bc5a83e8ecffab7a85521d5b2198c157507e2d5f1bc8b3f201add5

See more details on using hashes here.

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