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:
    row_count = 0
    for row in client.replay(
        exchange="binance",
        asset="BTC-USDT",
        from_="2024-01-01T00:00:00Z",
        to="2024-01-01T01:00:00Z",
    ):
        row_count += 1

    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)

Authenticated endpoints:

  • replay(exchange=..., asset=..., from_=..., to=..., standard=True) (iterator over /events or /raw)
  • trades(exchange=..., asset=..., from_=..., to=..., limit=1000) (collects all pages)
  • events(exchange=..., asset=..., from_=..., to=..., limit=1000) (collects all pages)
  • raw(exchange=..., asset=..., from_=..., to=..., limit=1000) (collects all pages)
  • 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.

Dataset replay (recommended)

For row-by-row iteration without managing file paths, use replay(...):

from polaris_data import PolarisClient

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

replay(...) checks the local replay cache first, then fetches paginated rows and caches them as NDJSON if needed. Replay cache is enabled by default and stored under:

  • macOS: ~/Library/Caches/polaris/datasets/replay
  • Linux: ~/.cache/polaris/datasets/replay
  • Windows: %LOCALAPPDATA%\\polaris\\datasets\\replay

Set POLARIS_DATASET_DOWNLOAD_DIR to override the base directory globally. 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.4.0.tar.gz (31.0 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.4.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: polaris_data-0.4.0.tar.gz
  • Upload date:
  • Size: 31.0 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.4.0.tar.gz
Algorithm Hash digest
SHA256 eeaa33adc69336dc2a20914a2787e02192cb05a31241c3c6c1b6fe0c27ff5988
MD5 046fa45aa4f5b8fa3397c63771b573e5
BLAKE2b-256 23fde7ed0a28c7ba97031b32be158158a374f369c3e8b20b6a199ed8b1e5a702

See more details on using hashes here.

File details

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

File metadata

  • Download URL: polaris_data-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 10.1 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.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 655cbc64878ac436fc022dfc17f1cc4df92e64ed81016e0baf30448f66a317e3
MD5 7d3482c6e879f2595b61458c42ea1586
BLAKE2b-256 b8309afd7dfd0155c809a613fcbcc21bd90bff202811774e13a362a8c6ddc017

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