Skip to main content

Lightweight serverless HTAP engine — Python bindings for the Rhei Rust library

Project description

rhei-engine

Python bindings for the Rhei HTAP engine -- lightweight, serverless Hybrid Transactional/Analytical Processing.

All engine methods are async and compatible with asyncio and anyio.

Install

pip install rhei-engine
# or
uv add rhei-engine

Note: the package is published as rhei-engine on PyPI (the rhei name was already taken), but the import name is rhei:

import rhei  # not "import rhei_engine"

Build from source

cd python
uv sync
uv run maturin develop

Quick start

import anyio
import rhei

async def main():
    async with await rhei.open(oltp_path="my.db") as engine:
        # Create table and register for CDC replication
        await engine.execute("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, age INTEGER)")
        await engine.register_table(
            rhei.TableSchema("users", [("id", "int64"), ("name", "utf8"), ("age", "int64")], ["id"])
        )

        # Write (routed to OLTP)
        await engine.execute("INSERT INTO users VALUES (1, 'Alice', 30)")

        # Batch write (single transaction, ~35K rows/sec)
        await engine.execute_batch([
            "INSERT INTO users VALUES (2, 'Bob', 25)",
            "INSERT INTO users VALUES (3, 'Charlie', 35)",
        ])

        # Sync CDC to OLAP
        result = await engine.sync_now()
        print(result)  # SyncResult(events=3, inserted=3, ...)

        # Query (auto-routed: aggregates -> OLAP, point queries -> OLTP)
        batches = await engine.query("SELECT AVG(age) FROM users")  # list[pyarrow.RecordBatch]
        print(batches[0].to_pydict())

anyio.run(main)

API

Method Description
rhei.open(**kwargs) Async factory (non-blocking init)
HtapEngine(config) Sync constructor
engine.execute(sql) Write statement (OLTP)
engine.execute_batch(stmts) Batch writes in single transaction
engine.query(sql) Auto-routed query -> list[pyarrow.RecordBatch]
engine.query_olap(sql) Force OLAP query
engine.sync_now() Sync CDC events to OLAP
engine.register_table(schema) Register table for replication
engine.add_column(t, c, type) Add column + rebuild CDC triggers
engine.drop_column(t, c) Drop column
engine.initial_sync(table) Bulk OLTP -> OLAP load
engine.shutdown() Cleanup (resources released on GC)

License

Apache-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

rhei_engine-1.5.0-cp314-cp314-manylinux_2_39_x86_64.whl (47.1 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.39+ x86-64

File details

Details for the file rhei_engine-1.5.0-cp314-cp314-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for rhei_engine-1.5.0-cp314-cp314-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 ea145e61aba2caa0793f86a1e94f78271e910c9d0c5590f5011a19aeeb4315f6
MD5 d22929f875bde1b4f351c2c7add37b8d
BLAKE2b-256 afb175c4a5788873ba9ae1a74e97a9ac360045d0f9db9227a5d0d6c8bd20410d

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