Skip to main content
The Python SDK targets CPython 3.9+ and mirrors the ergonomics of the Node and Rust clients. It opens a persistent TCP control connection to the EventDBX control socket, performs a Noise XX handshake by default, and exchanges Cap’n Proto messages for aggregate reads/writes.

Feature highlights

  • Synchronous TCP client that speaks the same Cap’n Proto control protocol as eventdbxjs.
  • Noise XX (+ PSK) transport enabled by default; opt out with no_noise=True / EVENTDBX_NO_NOISE=1 for test labs.
  • Mutation helpers for create, apply, patch, archive, and restore, plus per-call publish target routing.
  • Read helpers for list, events, get, select, and verify with pagination and sorting.
  • Snapshot and schema/tenant admin helpers (create_snapshot, list_snapshots, tenant_schema_publish, tenant_assign, quotas, etc.).

Install

pycapnp depends on Cap’n Proto system libraries. Install them first (brew install capnp on macOS or apt-get install capnproto libcapnp-dev on Debian/Ubuntu) before running pip install.

Connect and configure

EventDBXClient performs the handshake during construction and is a context manager; exit the block to close the socket. payload_json and metadata_json accept serialized JSON strings. When verbose=True (default) mutation methods return stored JSON blobs; set verbose=False to receive boolean acknowledgements.

Runtime configuration

Pass these values from your environment into EventDBXClient as shown above. Only EVENTDBX_NO_NOISE is read automatically when no_noise is omitted.

Manage authentication and tenancy

Tokens and tenant identifiers are required when constructing the client. Create separate client instances per tenant or per control token. The same socket is reused for all calls until the context exits or close() is invoked.

Retry configuration

Transport-level failures (socket resets, Cap’n Proto decode errors, etc.) can be retried automatically. Retries are disabled by default (attempts = 1); opt in by passing retry:
Only transport errors are retried; logical API errors surface immediately.

Publish targets

Select which plugins receive a write, override payload mode, and bump priority per call:
Omit publish_targets to fan out to every enabled plugin using their configured payload mode.

Write aggregates and events

create seeds a snapshot and first event atomically, apply appends events, patch issues RFC 6902 operations against historical payloads, and archive/restore toggle write access while preserving history.

Read aggregates and events

Use next_cursor to resume pagination. list returns aggregate snapshots; events returns full envelopes.

Filters, sorting, and pagination

Filters use the same SQL-like grammar as the server (field = value AND other_field > 10). Sort fields accept names such as aggregate_id, aggregate_type, version, created_at, updated_at, and archived. You can pass a string ("created_at:desc,aggregate_id:asc") or a list of AggregateSortOption objects. When sorting by timestamps, shorthand cursors (ts:<aggregate_type>:<aggregate_id>) can be used with cursor.

Snapshots and admin helpers

  • Snapshots: create_snapshot, list_snapshots, and get_snapshot handle point-in-time copies.
  • Schema & tenant admin: list_schemas / replace_schemas, tenant_schema_publish, tenant_assign / tenant_unassign, and quota helpers wrap control-plane maintenance flows.

Noise transport

Noise XX with a token-derived PSK is enabled by default. Disable it only for controlled testing by passing no_noise=True (or setting EVENTDBX_NO_NOISE). Production deployments should keep Noise on.

Development & testing

If pycapnp fails to build, install the Cap’n Proto toolchain first and retry the pip install.