Skip to main content

Rustegon Python driver

The official Python driver of the Rustegon document database: an asyncio API and a blocking facade over the same core. Specification: docs/specifications/python-driver.md. Requires Python 3.11 or later (tested on CPython 3.14). Published on PyPI: pip install rustegon.

Quick start

from rustegon import RustegonClient, Filter, Updates

# DEC-014: host, port, user, password, database. A default single node is plain text (ADR-034).
with RustegonClient("rustegon://app_user:secret@localhost:7700/shop") as client:
    orders = client.get_database().get_collection("orders")
    orders.insert_one({"_id": 1, "status": "paid", "total": 12})
    for order in orders.find(Filter.eq("status", "paid")):
        print(order)
    orders.update_one(Filter.id(1), Updates.set("status", "shipped"))

The same with asyncio:

import asyncio
from rustegon import AsyncRustegonClient, ClientSettings, Credential, Filter, Updates


async def main() -> None:
    settings = ClientSettings(
        hosts=[("db1.example.com", 7700)],
        credential=Credential.scram("app_user", "secret"),  # or Credential.api_key / Credential.x509
        tls_ca_file="/etc/rustegon/ca.crt",  # any TLS option turns TLS on
        database="shop",
    )
    async with AsyncRustegonClient(settings) as client:
        orders = client.get_database().get_collection("orders")
        async for order in orders.find(Filter.gte("total", 10)).limit(20):
            print(order)

        async def pay(txn) -> None:  # re-run on conflicts (transactions.md §5)
            await txn.get_collection("orders").update_one(Filter.id(1), Updates.set("status", "paid"))

        await client.with_transaction(pay)


asyncio.run(main())

Documents are dict (field order = insertion order) or dataclasses (get_collection("orders", Order), markers in rustegon.mapping). Values: int int64, float, Decimal decimal128, timezone-aware datetime, bytes, uuid.UUID, ObjectId, Vector, … (python-driver.md §7). Errors are rustegon.errors.RustegonException subclasses with code, retryable and trace_id; reads and idempotent writes are retried once by default.

Development

cd drivers/python
python -m venv .venv && .venv/Scripts/python -m pip install -e . --group dev   # .venv/bin on Linux
.venv/Scripts/python -m ruff check . && .venv/Scripts/python -m ruff format --check .
.venv/Scripts/python -m mypy                                                     # --strict (pyproject)
RUSTEGON_BIN_DIR=<dir with rustegon and rustegond> .venv/Scripts/python -m pytest
python scripts/generate.py            # regenerate src/rustegon/_pb and _error_table.py (PD-171)

Without RUSTEGON_BIN_DIR (default <repo>/target/debug) the server tests are skipped (they fail under CI=true). The conformance runner writes RUSTEGON_CONFORMANCE_RESULTS (default build/conformance-results.json), compared with the .NET and Java results by scripts/ci-local.sh (AC-DRV-003). Server binaries must follow ADR-034 (plain text by default, init --tls).

Metadata

Release files for rustegon 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rustegon 0.1.0
File Size Uploaded Provenance Actions
rustegon-0.1.0.tar.gz 143.4 kB Without provenance Details for rustegon-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for rustegon 0.1.0
File Interpreter ABI Platform Actions
rustegon-0.1.0-py3-none-any.whl Python 3 none any Details for rustegon-0.1.0-py3-none-any.whl

Total release size: 317.3 kB

Release files / rustegon-0.1.0.tar.gz

Download URL rustegon-0.1.0.tar.gz
Size 143.4 kB
Tags Source
SHA-256 checksum
How to use checksums
86ee3dd94b38457ccde673f8c86a9eaefeee497a87650bd7e1dfabf79149af53
BLAKE2b-256 checksum
How to use checksums
9b85c98e4709e556a781be713412906eddda4b0abf92d58eda53ad03b3a0687d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / rustegon-0.1.0-py3-none-any.whl

Download URL rustegon-0.1.0-py3-none-any.whl
Size 173.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a37ff0cdd94cf4c9dbda5f00f5ca6595317b206b776840acbd6c03c86f25b089
BLAKE2b-256 checksum
How to use checksums
bbf3a61bd4e33f3e28013156ce7655c604f8124fbf9ec9433e328e62c3389c22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Security for rustegon 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page