Mirexa

Wiki Reference

Python SDK

The mirexa Python package — a separate repository speaking Mirexa's wire protocol natively, with sync and asyncio clients, pandas and polars, cluster redirects, token renewal and TLS.

mirexa is the Python client for Mirexa. It speaks the binary wire protocol directly — no HTTP gateway in between — and follows the same request rules as the Go SDK: what is retried, what is ambiguous, how redirects are followed. It lives in its own repository, versioned separately from the server: https://github.com/AmiraliOmidvar/mirexa-python. Its README is the full reference; this page is a map of what the package offers and where it differs from the Go SDK.

Everything on this page was read from the Python repository at commit 07d4a40 (package version 0.1.0.dev0, development status alpha). The server repository does not contain that code, so none of it is checked by this repository's tests. Treat the client's own README and test suite as authoritative where they differ from this page.

Installing

bash
pip install 'mirexa[pandas]'
bash
pip install 'mirexa[polars]'

Python 3.10 or newer. The one required dependency is google-crc32c (a pure-Python fallback exists). The pandas and polars extras add those libraries and NumPy.

Package Speaks Talks to
0.1.x wire protocol v2 (mirexa.PROTOCOL_VERSION) any Mirexa server whose handshake is v2

A node answering in another protocol version raises UnsupportedVersionError and is not retried.

Clients

Name What it is
mirexa.connect(addr, **options) -> Client A connected synchronous client. addr is one host:port or a list of contact points. Usable as a context manager.
mirexa.connect_async(addr, **options) -> AsyncClient The asyncio client: the same constructor and methods, as coroutines. Use one per event loop.
Client, AsyncClient The classes behind them.

The two clients are one implementation of the request rules (_core.py) with two ways of waiting; the package's test suite runs every behaviour test against both.

Connection options

Option Default Meaning
token none A token from mirexa-cli token issue. Never renewed: it has nothing newer to offer.
token_file none A file re-read on every connect, and before each renewal.
token_source none A callable returning a token, used like token_file.
permissions read/write candles and ticks, ADMIN_STREAM What an unauthenticated client asks for; only a node with authentication off accepts it.
tls False True for the system trust store, or an ssl.SSLContext.
server_hostname the address host The name the node's certificate must carry.
connect_timeout, request_timeout 10 s, 30 s
max_frame_bytes 16 MiB Floor 4 KiB.
retry_attempts, retry_base_backoff, retry_max_backoff 1000, 5 ms, 250 ms Re-sending a shed (Overloaded) request, as in the Go SDK.
reconnect_attempts, reconnect_backoff, reconnect_max_backoff 3, 100 ms, 5 s Redialling a node.
max_redirects 3 Hops one request may take.
disable_renewal False Turns automatic token renewal off.

Methods

Method Does
ingest_candles(stream, candles, durability=, mode=, overwrite=) mode: "live" (new bars, and restates stored ones), "history" (bulk back-fill), "correction" (restates stored bars only). overwrite=True writes a derived stream.
ingest_ticks(stream, ticks) Trades.
ingest_dataframe(df, stream, columns=, time_column=, tz=, ts_unit=, batch_size=, durability=, mode=, overwrite=) Candles from a pandas or polars frame, in batches of 5,000 by default.
query_candles(stream, start, end, limit=, include_gaps=, descending=, allow_stale=, rollup=, from_ticks=) CandleResult: .candles, .gaps, .to_pandas(), .gaps_frame(), .to_polars(), .gaps_polars(), .to_numpy().
query_columns(stream, start, end, columns, limit=, descending=) ColumnResult: the stamps and only the named columns as NumPy arrays.
query_ticks(stream, start, end) TickResult.
list_streams(stats=) Every node's streams, merged. Needs LIST_STREAMS.
nodes() The cluster's nodes (empty for a single node).
list_gaps(stream, start, end, open_only=, exclude_off_time=) The gap index as ranges, with a summary.
fill_gap(stream, gap_start, method, max_candles=, overwrite=) Ask the node to fill one open gap ("linear", "forward", "backward"). Never a market closure.
accept_gap(stream, gap_start, accept=) Accept or put back a derived bar's INCOMPLETE mark.
get_stream_metadata, set_stream_metadata(..., create=), add_stream_closure, remove_stream_closure, set_stream_lineage, clear_stream_lineage Stream metadata; every change needs ADMIN_STREAM.
subscribe(stream, ticks=, backfill=, start=, resume=, follow_redirects=) An iterator of Event; sub.next(timeout=) waits a bounded time.
reauthenticate() Renew the token on every open connection now.

Times may be Unix nanoseconds (int), datetime, ISO-8601 strings, pandas.Timestamp or numpy.datetime64; a naive time is UTC. A float is refused, because seconds and nanoseconds would be a guess.

pandas and polars

to_pandas() returns candles only, with a UTC DatetimeIndex; gaps are never NaN rows but a separate frame from gaps_frame() with start, end, status, reason and fillable. fillable comes from the node's own rule, so a market closure is never fillable. Polars has no index, so time is a time column of type Datetime("ns", "UTC"). to_pandas(prices="decimal") returns exact decimal.Decimal prices recovered from the stored fixed point.

Behaviour shared with the Go SDK

  • An acknowledged write is in the node's write-ahead log, fsynced, when the call returns.
  • Only Overloaded is retried, and it promises nothing was stored.
  • A connection that fails while a write is on the wire raises AmbiguousWriteError. Reconcile by reading the range back. The client never re-sends for you: a re-sent candle batch overwrites anything restated meanwhile, and a re-sent trade batch can store a trade twice.
  • A write that never left (the node had closed an idle connection) goes out fresh.
  • Reads are retried on a new connection.
  • Subscriptions report dropped batches; history and live overlap at the boundary, so dedupe by timestamp.

Where it differs from the Go SDK

Topic Python Go public package
Redirects Followed: give one or several contact points; routes are cached by partition and only move to a strictly newer epoch. An older epoch is asked again for about 1.3 s, then NodeBehindError; two nodes contradicting each other at one epoch raise RedirectLoopError. Returned as *RedirectError; not followed.
Fenced writes A write carries the partition epoch it last learned. Writes carry no epoch.
Subscriptions across moves Follow a moved partition to its new primary, resuming past the last record. ResumingSubscriber with FollowRedirects.
Listing list_streams() asks every node and raises PartialListingError (with what the others returned) if one does not answer. One node per call.
Token renewal With token_file or token_source, at two-thirds of a token's life, over the open connection. With Options.TokenSource, the same.
Not available No multi-query (QueryMultiAll); no automatic fallback to a copy when a primary is down; no spreading of reads over copies. allow_stale=True lets a copy answer only if the request lands on one. A fire_and_forget write cannot be redirected. —

Errors

All errors derive from MirexaError.

Error Meaning
RemoteError The node answered with an ERROR frame: .code, .message, .retry_after_ms, .retryable (true only for Overloaded).
OverloadedError, UnauthorizedError, SlowConsumerError, PartitionUnavailableError, DerivedStreamError, HistoryRequiredError RemoteError subclasses by code. HistoryRequiredError: the bars are older than anything stored, or between stored chunks; nothing was stored, re-send with mode="history".
ErrorCode The codes as an IntEnum, 0x0001–0x000B. See Error codes.
RetriesExhaustedError Every attempt was shed; __cause__ is the last one.
TransportError, ClientClosedError, RequestTimeoutError The connection failed or is closed, or no answer came in time.
AmbiguousWriteError A TransportError: the write's outcome is unknown.
RedirectError Another node serves the stream: .partition, .epoch, .node_id, .addr.
RedirectLoopError, NodeBehindError, PartialListingError Routing outcomes (above).
QueryStatusError, StreamNotFoundError A query answered a non-OK status.
WireFormatError and subclasses, including UnsupportedVersionError Bytes that do not decode; the connection is ended.
MappingError A column mapping (parse_mapping) that cannot be used.

Conformance with the server

The repository carries a frozen conformance suite, tests/conformance/wire-v2.json: every frame the client speaks as bytes beside their meaning, produced by the server's own Go codecs, plus malformed frames with the reason the server refuses each. The Python tests decode and re-encode every one. The same file is held in this repository at /conformance/wire-v2.json and checked by the server's internal/wire conformance tests (the client README still says the server repository carries no copy; at this commit it does). The Python suite's server tests build mirexa-server and mirexa-cli (whose token and certs commands they also use) from the directory named by MIREXA_REPO, or use prebuilt binaries from MIREXA_SERVER_BIN and MIREXA_CLI_BIN, and skip without them.

Performance

The client's README records one benchmark run (2026-10-22, client 2e9ecad, server 2fa192c, one node on a 12-core laptop under other load, so floors rather than figures): reading 20 symbols × 1 year of 1-minute candles (10.5M rows) into pandas at 5.40M rows/s, polars 5.48M, the asyncio client 6.55M, against 7.39M for the Go SDK on the same reads; bulk loading by ingest_dataframe(mode="history") at 127K rows/s, bound mostly by the node's disk syncs. See the README's Performance section for the method and caveats. Not re-measured for this page.

References

Source

  • Python client, separate repository: https://github.com/AmiraliOmidvar/mirexa-python — README.md, src/mirexa/client.py, src/mirexa/aio.py, src/mirexa/_core.py, src/mirexa/errors.py.
  • /conformance/wire-v2.json — the frozen wire conformance suite both repositories check.
  • /internal/wire — the server-side codecs the suite was produced by.

Tests

  • In the Python repository: tests/test_conformance.py, tests/test_routing.py, tests/test_cluster.py, tests/test_renewal.py, tests/test_tls.py, tests/test_async.py, tests/test_stale_reads.py (not run for this page).
  • In this repository: TestConformance_TheCodecsAgreeWithTheFrozenFixtures and TestConformance_AMutatedFixtureIsReported in /internal/wire/conformance_test.go.

Further reading

External

  • pandas documentation, pandas development team — https://pandas.pydata.org/docs/
  • Polars user guide, Polars — https://docs.pola.rs/
  • asyncio — Asynchronous I/O, Python Software Foundation — https://docs.python.org/3/library/asyncio.html