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 (uv)

uv sync --group dev

Useful commands:

uv run python
uv lock

Quickstart

from polaris_data import PolarisClient

with PolarisClient(api_key="polaris_key_your_key") as client:
    local_files = client.download_snapshots(
        exchange="binance",
        asset="BTC-USDT",
        from_="2024-01-01T00:00:00Z",
        to="2024-01-02T00:00:00Z",
    )
    print(local_files[0].path)

    row_count = sum(
        1
        for _ in client.replay(
            exchange="binance",
            asset="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.

Supported input time types

Methods that take from_ and to accept:

  • ISO 8601 strings ("2024-01-01T00:00:00Z")
  • datetime.datetime
  • datetime.date
  • Unix epoch microseconds (int/float)

Methods

Open endpoints:

  • health()
  • catalog(exchange=None, asset=None)
  • list_snapshots(exchange=..., asset=..., from_=..., to=..., limit=1000)
  • list_local_snapshots(exchange=None, asset=None, date=None)
  • iter_local_events(exchange=..., asset=..., from_=None, to=None)

Authenticated endpoints:

  • download_snapshots(exchange=..., asset=..., from_=..., to=..., force=False)
  • replay(exchange=..., asset=..., from_=..., to=..., standard=True) (snapshot-first iterator over standardized events or /raw)
  • trades(exchange=..., asset=..., from_=..., to=..., limit=1000) (collects all pages)
  • events(exchange=..., asset=..., from_=..., to=..., limit=1000) (snapshot-first list for standardized events)
  • raw(exchange=..., asset=..., from_=..., to=..., limit=1000) (prefers format=file, falls back to paginated JSON)
  • ohlcv(exchange=..., asset=..., from_=..., to=..., interval=..., format=None)

For event/data endpoints, standard=True is the default. Pass standard=False when you explicitly need raw schema payloads.

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 events, replay(...) and events(...) 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:
    client.download_snapshots(
        exchange="binance",
        asset="BTC-USDT",
        from_="2024-01-01T00:00:00Z",
        to="2024-01-03T00:00:00Z",
    )

    for row in client.replay(
        exchange="binance",
        asset="BTC-USDT",
        from_="2024-01-01T00:00:00Z",
        to="2024-01-01T01:00:00Z",
    ):
        print(row)

For notebook and local analysis workflows, use the local helpers directly:

from polaris_data import PolarisClient

with PolarisClient() as client:
    local_entries = client.list_local_snapshots(exchange="binance", asset="BTC-USDT")
    print(local_entries[0].path)

    rows = list(
        client.iter_local_events(
            exchange="binance",
            asset="BTC-USDT",
            from_="2024-01-01T00:00:00Z",
            to="2024-01-01T01:00:00Z",
        )
    )
    print(len(rows))

If the requested standardized range cannot be satisfied from daily snapshots, the SDK falls back to the legacy /events?format=file flow.

Legacy replay cache

replay_cache_enabled and replay_cache_dir are kept for legacy replay behavior, including standard=False raw replays and standardized fallback-to-/events cases. The default legacy replay cache path is:

  • <dataset_root>/cache/replay

Use replay_cache_enabled=False to disable caching, or replay_cache_dir=... to set a custom path.

Error handling

from polaris_data import PolarisClient, RateLimitedError, UnauthorizedError

client = PolarisClient()

try:
    client.replay(
        exchange="binance",
        asset="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.5.0.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.

polaris_data-0.5.0-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: polaris_data-0.5.0.tar.gz
  • Upload date:
  • Size: 40.1 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.5.0.tar.gz
Algorithm Hash digest
SHA256 c78e4896dec2b0c1523f1c6d5680edbf49229f909819f84bc5b3d429550912ef
MD5 b1016887af3d729596dd82daa35da87d
BLAKE2b-256 c56b6d1a89be489fd64ede7947294c56972ffc025c480a2c95b9d8f7fbeb37c2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: polaris_data-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 16.8 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.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5a2098560d408c35f0f1c2a7e3a9be104b93f019258b668bbd096a60113e3cb7
MD5 a25fc3af4b347b947af2b957bc3f2bb2
BLAKE2b-256 d0889e4a7cd4bc9ceb06abda96a9887c7c13c25c575c564771547f5f6b94474c

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