Skip to main content
The Polaris Python SDK is available on PyPI as polaris-data.

Install

If you use uv, install it into a project with:
Or install it into the active environment with:
For Pandas DataFrames or PyArrow record batches, install an optional extra:

Quickstart

Use replay(...) when you want to stream historical rows in a notebook, script, or backfill job. You can run this without an API key set, and from_ and to are optional. If you omit them, the SDK uses the most recent available window up to the last 7 days of data, or the public cutoff date for preview datasets.

Create a client

If you omit api_key, the client reads POLARIS_API_KEY from the environment.
The main constructor is:

Core methods

Use PolarisClient for discovery, historical replay, and direct query workflows. Historical row methods return single-pass generators. Iterate directly for bounded memory, or wrap a call in list(...) when you need indexing or repeated access. Close a partially consumed generator with rows.close(). BBO also accepts interval="100ms", "1s", "10s", "1m", "5m", "15m", or "1h" to emit the last quote from each non-empty UTC-aligned bucket.

Arrow batches and DataFrames

trades, funding_rates, mark_prices, bbo, and depth_metrics accept three output modes. The default "iterator" preserves the existing row dictionaries. "batches" yields bounded pyarrow.RecordBatch objects, while "dataframe" eagerly returns one Pandas DataFrame.
Columnar schemas are flat. Timestamps are timezone-aware UTC milliseconds; source, market, and trade side are categorical/dictionary columns. Additional venue-specific trade and point fields are sorted under extra.<name>. Because those keys are dynamic, trade and point queries scan the resolved local files once to infer a stable schema and reopen the same files for batch emission. Trade batches and DataFrames include stable nullable maker and taker string columns. BBO and depth metrics have fixed schemas and remain single-pass. from_ and to accept ISO 8601 strings, datetime, date, or Unix epoch milliseconds. They are optional on replay(...), events(...), trades(...), option_tickers(...), perpetual_tickers(...), raw(...), and ohlcv(...). If you omit either boundary, the SDK fills the request from the most recent available window up to the last 7 days of data, or the public cutoff date for preview datasets. For historical event queries, standard=True is the default on replay(...). Pass standard=False when you explicitly want raw schema payloads through replay. For exact execution replay, request output="batches" and materialize_orderbooks=False. These batches retain every standardized event in stored capture order and include stable replay, file, and row ordinals. Nullable legacy timestamp and v2 collector/exchange columns use millisecond Arrow timestamps. Typed columns include nullable order_id, side, and is_snapshot. With raw order-book updates, event_json preserves the complete source event and unknown payloads; with materialization enabled it contains the resulting complete-book event. Raw standard=False replay remains iterator-only. Iterator dictionaries preserve their stored envelope. Check "collector_timestamp" in event to identify v2; use that value for SDK time and treat exchange_timestamp as nullable venue provenance. See Event envelope. Orderbooks are reconstructed by default across stream, replay, events, and l2_snapshots. orderbook replaces the complete state, orderbook_delta updates listed prices, and quantity zero deletes a price. State is cleared after gaps and reconnects; deltas are skipped until another snapshot arrives. Use l2_updates(...) for raw snapshots and deltas, then feed selected updates into the exported OrderbookBuilder for application-managed flows.

Discover a market before you query it

Use catalog(...) to find the exact Polaris market ID for a venue.
If you want a high-level view of supported venues and example market IDs before you query the exact pair, start with Market Coverage.

Query events

Use events(...) when you want standardized historical event rows beyond trades alone. Omit from_ and to to query the recent default window, or pass them explicitly when you need a fixed range.

Query trades

trades(...) returns an iterator of normalized trade events. The SDK handles snapshot-backed historical reads for you. from_ and to are optional, so you can start with the recent default window and only add explicit boundaries when you need a specific range.

Query intents and RFQs

intents(...) returns typed RFQ, quote, executable-intent, and settlement observations in stored order. Use market="intents" and correlate rows by their captured rfq_id or intent_id.
See the Intents and RFQs guide for lifecycle reconstruction and the schema reference for fields.

Query option tickers

Use option_tickers(...) with an underlying market such as BTC. Omit instrument to iterate over the whole option chain, or provide an exact venue-native contract to filter the results.
Every option ticker event keeps source, the normalized underlying market, and the non-empty exact instrument separate. See Option tickers for the payload fields and realtime filtering behavior.

Query perpetual tickers

Use perpetual_tickers(...) to iterate over partial venue-published market state for a perpetual market.
The SDK exports PerpetualTickerData, LegacyPerpetualTickerEvent, PerpetualTickerEventV2, and their PerpetualTickerEvent union. Decimal values remain strings, and omitted fields are not carried forward. Generic events, replay, and realtime stream methods include these events automatically. See Perpetual tickers for all payload fields and validation rules.

Query OHLCV bars

Use ohlcv(...) when you want interval bars instead of individual trades. from_ and to are optional here as well.
If you pass format="tradingview", ohlcv(...) returns TradingView-style candle and volume arrays.

Query order book snapshots

Use l2_snapshots(...) when you need order book depth data for microstructure analysis.
For a sparse update stream, use l2_updates(...) and materialize books only when your application needs them:
update() changes native state without constructing a complete Python dictionary. snapshot() creates sorted levels only when requested. Use apply() when you need the previous update-and-materialize behavior.

Query funding rates

Use funding_rates(...) to analyze perpetual funding rates and carry modeling.

Query mark prices

Use mark_prices(...) for basis analysis, mark tracking, and liquidation-related research.

Query volume profiles

Use volume(...) for volume profiling and participation analysis.

Query VWAP series

Use vwap(...) for execution benchmarking and price smoothing.

Query volatility series

Use volatility(...) for risk modeling and intraperiod volatility analysis.

Query best bid/offer

Use bbo(...) for spread tracking, quote analytics, and top-of-book monitoring. Set changes_only=True when the consumer only needs actual top-of-book changes; the default continues to emit after every valid two-sided book update.

Query depth metrics

Use depth_metrics(...) for liquidity analysis and market impact estimation.

Local dataset storage

The SDK stores standardized snapshots and local day files under a 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 this layout:
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

Standardized historical methods—including replay(...), events(...), trades(...), option_tickers(...), perpetual_tickers(...), and default or TradingView ohlcv(...)—prefer /snapshots and /download, then read local day files when they already exist. See Snapshots for the full flow.

Authentication

Public sources (e.g. Hyperliquid BTC) work without an API key. For premium sources, raw snapshots, or extended history, set your key via the POLARIS_API_KEY environment variable or pass it directly:
See Quickstart for the full auth model.

Error handling

Notebook workflow

If you want a notebook that discovers a market, loads a DataFrame, and plots a chart, start with Jupyter Notebook.

Next steps