Skip to main content

q/kdb+ IPC client library with Arrow-native Python interoperability

Project description

qroissant

qroissant is a minimal q/kdb+ IPC client library with first-class support for the Apache Arrow ecosystem.

  • Lightweight — qroissant is a minimal library weighing in at less than 4 MiB with no required dependencies.
  • Fast — qroissant is written in Rust, a safe and high-performance systems programming language. Moreover, qroissant uses your system resources to the best extent possible by leveraging zero-copy, multithreading, and other vectorization techniques such as SIMD.
  • Modular — qroissant relies heavily on the Apache Arrow PyCapsule Interface for communicating with other libraries from the Apache Arrow ecosystem with zero-copy. This includes pyarrow, polars, duckdb, pandas, datafusion, and more.
  • Type hints — qroissant provides type annotations for all of its functionality.

Installation

pip install qroissant

Requires Python 3.10+. Wheels are available for Linux (x86_64, aarch64), macOS (universal2), and Windows (x86_64).


Quick start

Connect and query

import qroissant as q

endpoint = q.Endpoint.tcp("localhost", 5000)

with q.Connection(endpoint) as conn:
    result = conn.query("select from trade where date = .z.d")
    print(result)  # Table

To Arrow / Polars / PyArrow

Decoded values implement the Arrow PyCapsule protocol — pass them straight to any Arrow-aware library:

import polars as pl
import pyarrow as pa

with q.Connection(endpoint) as conn:
    table = conn.query("select from trade")

# zero-copy — no intermediate Python objects
df = pl.from_arrow(table)
pa_table = pa.RecordBatch.from_batches([pa.record_batch(table)])

Async

import asyncio
import qroissant as q

async def main():
    endpoint = q.Endpoint.tcp("localhost", 5000)
    async with q.AsyncConnection(endpoint) as conn:
        result = await conn.query("1 + 1")
        print(result)  # Atom → 2

asyncio.run(main())

Connection pool

pool_opts = q.PoolOptions(
    max_size=10,
    min_idle=2,
    checkout_timeout_ms=5_000,
    test_on_checkout=True,
)

with q.Pool(endpoint, pool=pool_opts) as pool:
    pool.prewarm()                        # open idle connections eagerly
    result = pool.query("count trade")    # checked out and returned automatically
    print(pool.metrics())                 # PoolMetrics(connections=2, idle=2, …)

Streaming raw response

For large results you can stream the raw IPC bytes before decoding:

with q.Connection(endpoint) as conn:
    with conn.query("select from trade", raw=True) as resp:
        print(resp.header)        # MessageHeader(size=…, compression=…)
        value = resp.decode()     # decode on demand

Standalone encode / decode

# decode an IPC payload you already have
payload: bytes = ...
value = q.decode(payload)

# encode a value back to IPC bytes
frame = q.encode(value, message_type=q.MessageType.SYNCHRONOUS)

Value types

Every conn.query() call returns a Value subclass:

q type Python type Arrow export
scalar (atom) Atom __arrow_c_array__
typed list Vector __arrow_c_array__
mixed list List __arrow_c_array__
dictionary Dictionary __arrow_c_array__ (StructArray)
table Table __arrow_c_stream__

Decode options

Control how IPC data is projected into Arrow:

opts = (
    q.DecodeOptions.builder()
    .with_symbol_interpretation(q.SymbolInterpretation.DICTIONARY)  # dict-encode symbols
    .with_temporal_nulls(True)          # map q null sentinels → None
    .with_treat_infinity_as_null(True)  # map ±∞ → None
    .with_parallel(True)                # decode table columns in parallel
    .build()
)

with q.Connection(endpoint, options=opts) as conn:
    result = conn.query("select from trade")

Endpoints

# TCP
endpoint = q.Endpoint.tcp(
    "localhost", 5000,
    username="user",
    password="pass",
    timeout_ms=3_000,
)

# Unix domain socket
endpoint = q.Endpoint.unix(
    "/tmp/qroissant.sock",
    username="user",
    password="pass",
)

Error handling

from qroissant import (
    QroissantError,   # base class
    DecodeError,      # malformed IPC payload
    ProtocolError,    # bad frame header
    TransportError,   # socket / IO failure
    QRuntimeError,    # q process returned an error
    PoolError,        # pool management failure
    PoolClosedError,  # operation on a closed pool
)

try:
    result = conn.query("invalid expression")
except q.QRuntimeError as e:
    print(f"q error: {e}")
except q.TransportError as e:
    print(f"connection lost: {e}")

Architecture

qroissant is organized as a Rust workspace with strict crate boundaries:

crates/
├── qroissant-core       # q protocol, value types, encode/decode
├── qroissant-transport  # sync & async TCP/Unix socket connections
├── qroissant-arrow      # zero-copy Arrow projection
├── qroissant-kernels    # SIMD / nightly-sensitive hot paths
└── qroissant-python     # PyO3 bindings (the _native extension module)

The Python package at python/qroissant/ re-exports everything from the compiled _native extension. The .pyi stub files in that directory define the public API contract.


Development

# Install Python dependencies
uv sync --group dev --group docs

# Build the Rust extension (required before running Python tests)
uv run maturin develop

# Run tests
uv run pytest
cargo test --workspace

# Lint and format
uv run ruff check python/ tests/
cargo fmt --all

Transport integration tests require a q binary. Set Q_BIN to the path of your q executable before running pytest.


License

Apache 2.0 — see LICENSE.

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

qroissant-0.3.0.tar.gz (105.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

qroissant-0.3.0-cp311-abi3-win_amd64.whl (3.7 MB view details)

Uploaded CPython 3.11+Windows x86-64

qroissant-0.3.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.5 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ ARM64

qroissant-0.3.0-cp311-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (6.7 MB view details)

Uploaded CPython 3.11+macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

qroissant-0.3.0-cp310-cp310-win_amd64.whl (3.7 MB view details)

Uploaded CPython 3.10Windows x86-64

qroissant-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

qroissant-0.3.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

qroissant-0.3.0-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (6.7 MB view details)

Uploaded CPython 3.10macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

qroissant-0.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

Details for the file qroissant-0.3.0.tar.gz.

File metadata

  • Download URL: qroissant-0.3.0.tar.gz
  • Upload date:
  • Size: 105.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for qroissant-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b2114e634baefb3c851a99e2bba838c1c4f7c7546f4812561df1944b44951251
MD5 4e512f835120dab8793f16a2058bad80
BLAKE2b-256 a9ecb597cd59ec59c8fd850172cd33f7a6ff7378c4f4c9652d9515d998ca8086

See more details on using hashes here.

Provenance

The following attestation bundles were made for qroissant-0.3.0.tar.gz:

Publisher: release.yml on 3ok/qroissant

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qroissant-0.3.0-cp311-abi3-win_amd64.whl.

File metadata

  • Download URL: qroissant-0.3.0-cp311-abi3-win_amd64.whl
  • Upload date:
  • Size: 3.7 MB
  • Tags: CPython 3.11+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for qroissant-0.3.0-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 120343e541658f80f742b3e2021681d3d6f088bfe7ce4dcff6e556909f976214
MD5 4210eb09f10e6bddf4af8c6c60597329
BLAKE2b-256 5e7514072b312ce60d5255ddca49515665a96c89c29f8d9894b25caf603bbcc6

See more details on using hashes here.

Provenance

The following attestation bundles were made for qroissant-0.3.0-cp311-abi3-win_amd64.whl:

Publisher: release.yml on 3ok/qroissant

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qroissant-0.3.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for qroissant-0.3.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8048776963e58083e708d32b5888bd98a56fe142eb994fab9a93f2ac93ce8a06
MD5 e157b464b16b5d0245c38e091a8f5e6c
BLAKE2b-256 5881a7e819c21090f4934d74152b573216e109571690cf395ff4a9e25b3d4bb8

See more details on using hashes here.

Provenance

The following attestation bundles were made for qroissant-0.3.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on 3ok/qroissant

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qroissant-0.3.0-cp311-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for qroissant-0.3.0-cp311-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 c61037fc20092933d9c1dc8f0f07df6c0e8bf618f9d4982aa6fab192131c400a
MD5 e597720263a1c5b44111693e12fbf290
BLAKE2b-256 794e0179a798f796f92d60d6f8c16847c7b1cb96ac59769dcb36d42cce1c02cf

See more details on using hashes here.

Provenance

The following attestation bundles were made for qroissant-0.3.0-cp311-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl:

Publisher: release.yml on 3ok/qroissant

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qroissant-0.3.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: qroissant-0.3.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 3.7 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for qroissant-0.3.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 740683e75ccc392eaa1a717f33ddea1dfb932b2938796bdf1de2a1b2922af8be
MD5 7c86b59c4077ebaff0e56258720a228b
BLAKE2b-256 3f06d30de2223cf47d881a85ebbd226210bc2a644f29f044ddb6fb37e6675265

See more details on using hashes here.

Provenance

The following attestation bundles were made for qroissant-0.3.0-cp310-cp310-win_amd64.whl:

Publisher: release.yml on 3ok/qroissant

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qroissant-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for qroissant-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 eb005bcdf1dd356146ffcddf3c890e5514576f28159bd724bcfa7d0e90127950
MD5 2173916a831376da1da546038ee5e48f
BLAKE2b-256 81f612328733014231121bd351bd768ce8839258f9f18a58f3a15109cf51c28e

See more details on using hashes here.

Provenance

The following attestation bundles were made for qroissant-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on 3ok/qroissant

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qroissant-0.3.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for qroissant-0.3.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ee5fa3730039bb1da79aaeeb4f9b5ea684482409557793b3500d9814dcd2727d
MD5 30ac908306378c53a5c8890c9a1dd44a
BLAKE2b-256 fa5e4292ca3fb378c3e4ddf25f8372902d75aa2d6217f25bc3bac8a7568941d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for qroissant-0.3.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on 3ok/qroissant

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qroissant-0.3.0-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for qroissant-0.3.0-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 b25f386f452e27b494521cb015506082503e12da623425c28e74f7c2f0e65114
MD5 6a0e754c97ba6aeee71f30ee884d552e
BLAKE2b-256 0e8e4953b91216cc3af66ddbf8a64ace9e45acfa0250decb62571320a7bcf280

See more details on using hashes here.

Provenance

The following attestation bundles were made for qroissant-0.3.0-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl:

Publisher: release.yml on 3ok/qroissant

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qroissant-0.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for qroissant-0.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 eb01627af50efdd96acab3022116a5f852eb87c2849869739bb8ee26d3160288
MD5 ee7679dc12335adba169f701624203a5
BLAKE2b-256 809dbc3bd0549f3b5051f263b6d5385734b532f0c022da6f2fa2a5928ac585b3

See more details on using hashes here.

Provenance

The following attestation bundles were made for qroissant-0.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on 3ok/qroissant

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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