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.

Install (uv)

uv sync --group dev

Useful commands:

uv run python
uv lock

Quickstart

from polaris_data import PolarisClient

with PolarisClient.new("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()
  • exchanges()
  • assets(exchange)
  • timerange(exchange, asset)
  • dataset_size(exchange, asset, from_, to)
  • catalog()
  • dataset_preview(..., standard=False)
  • ohlcv_preview(..., interval, limit=None, format=None)

Authenticated endpoints:

  • dataset_download_url(..., standard=False)
  • replay(..., standard=False) (stream rows from dataset download URL)
  • download_dataset(..., standard=False, destination=None, filename=None, overwrite=False, decompress=True, keep_compressed=False)
  • trades_page(..., limit=1000, cursor=None)
  • iter_trades(...)
  • collect_all_trades(...)
  • stream_events(..., standard=False)
  • collect_events(..., standard=False)
  • iter_ohlcv(..., interval)
  • ohlcv(..., interval, format=None)

Dataset replay (recommended)

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

from polaris_data import PolarisClient

with PolarisClient.new("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 and caches the dataset if needed. Replay cache is enabled by default and initialized when the client is created.

Optional: persist dataset files

For safety, file downloads are disabled by default. Enable them explicitly when you want to save files locally:

from polaris_data import PolarisClient

with PolarisClient.new("polaris_key_your_key", allow_dataset_downloads=True) as client:
    file_path = client.download_dataset(
        exchange="binance",
        asset="BTC-USDT",
        from_="2024-01-01T00:00:00Z",
        to="2024-01-01T01:00:00Z",
    )
    print(file_path)

download_dataset(...) decompresses .zst files by default and returns the decompressed file path (for example .jsonl). Set decompress=False to keep the original .zst, or keep_compressed=True to keep both files.

Default download directories:

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

You can override this with dataset_download_dir=... on the client or destination=... on a single download_dataset(...) call. Set POLARIS_DATASET_DOWNLOAD_DIR to override the default directory globally. Replay cache defaults to a replay/ subdirectory under dataset_download_dir. Use replay_cache_enabled=False to disable replay caching, or replay_cache_dir=... to move it.

Error handling

from polaris_data import PolarisClient, RateLimitedError, UnauthorizedError

client = PolarisClient.anonymous()

try:
    client.collect_events("binance", "BTC-USDT", "2024-01-01T00:00:00Z", "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.1.2.tar.gz (30.7 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.1.2-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: polaris_data-0.1.2.tar.gz
  • Upload date:
  • Size: 30.7 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.1.2.tar.gz
Algorithm Hash digest
SHA256 17ed29ff23b252ff4d4a705d42bef4e593165665ee181e8f3903d7daa4e6dd71
MD5 5c4be3c6ccdc128194b9c381672dde7e
BLAKE2b-256 9b1abdc54439ee75b5521d8aa1443e897657b5af4e1e26f46e8faec7ae910e01

See more details on using hashes here.

File details

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

File metadata

  • Download URL: polaris_data-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 10.2 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.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a299ebfdfe2a09328f81fff33d9e85b4c7b7b63bc316983d9979d5b1be1495ce
MD5 84f3bcf5e93f477cb751bb4dc89df446
BLAKE2b-256 40bc3a98d70b77e82fdf179ed17eb8e9ce3457c244568974bf536856832168f0

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