Skip to main content

qx-events

NATS JetStream publisher/consumer, transactional outbox relay, and mediator-bridge event dispatcher for the Qx framework.

What lives here

  • qx.events.OutboxRelay — polls qx_outbox_events, publishes unpublished events to NATS JetStream, and marks them delivered. Runs as a background task alongside the HTTP server or as a standalone process. Supports optional leader election so only one relay instance publishes at a time.
  • qx.events.NatsPublisher — publishes a single IntegrationEvent to a JetStream subject derived from event_name.
  • qx.events.NatsConsumer — durable pull consumer over a JetStream stream. Used by WorkerRuntime to fetch and ack/nak messages.
  • qx.events.NatsSettings — Pydantic settings for NATS connection (URL, credentials, stream name, consumer name).
  • qx.events.EventRegistry — maps event_name strings to concrete IntegrationEvent subclasses. Required by both the relay (for serialisation) and the worker (for deserialisation).
  • qx.events.MediatorEventDispatcher — EventDispatcher implementation that routes domain events to their in-process handlers via the Mediator after a UnitOfWork commit.
  • qx.events.create_nats_connection — async factory that opens a NATS connection with retry.

Usage

Outbox relay (alongside the API server)

from qx.events import OutboxRelay, NatsPublisher, NatsSettings, EventRegistry

registry = EventRegistry()
registry.register(UserRegisteredIntegration)

publisher = NatsPublisher(nc, registry)
relay = OutboxRelay(session_factory, publisher, registry)

# Run in background
asyncio.create_task(relay.run())

Consuming events in a worker

from qx.events import NatsConsumer, NatsSettings

settings = NatsSettings(url="nats://localhost:4222", stream="events", consumer="identity-worker")
consumer = NatsConsumer(nc, settings)

# WorkerRuntime handles the fetch/ack loop
worker = WorkerRuntime(container, consumer, registry, mediator)
await worker.run()

Design rules

  • At-least-once delivery — the outbox guarantees every INSERTed event is eventually published. Consumers are expected to be idempotent (use IdempotencyStore from qx-cache).
  • Transactional outbox — UnitOfWork (in qx-db) writes events to qx_outbox_events in the same transaction as the aggregate; the relay reads and publishes asynchronously. No event is lost even if the process crashes between commit and publish.
  • Event envelope — each NATS message carries event_name, event_version, payload JSON, correlation_id, tenant_id, and OTel trace context headers for full observability continuity.

Metadata

Release files for qx-events 1.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 qx-events 1.1.0
File Size Uploaded Provenance Actions
qx_events-1.1.0.tar.gz 9.8 kB Without provenance Details for qx_events-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for qx-events 1.1.0
File Interpreter ABI Platform Actions
qx_events-1.1.0-py3-none-any.whl Python 3 none any Details for qx_events-1.1.0-py3-none-any.whl

Total release size: 20.0 kB

Release files / qx_events-1.1.0.tar.gz

Download URL qx_events-1.1.0.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
762ea581e1adcaca8f72bca50c1aaebf8e09e911c45d55d84bcae3f0e105cb53
BLAKE2b-256 checksum
How to use checksums
5096c1560ca8f28c46c659719f7c75dbc473e48e09903102ca6b7cc0226520b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / qx_events-1.1.0-py3-none-any.whl

Download URL qx_events-1.1.0-py3-none-any.whl
Size 10.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1e8fb89d408703c72806dba18bb3a63639e4b319af8a463aca79f5730bbd8176
BLAKE2b-256 checksum
How to use checksums
3d8119bb779bb31094edcd5b8ded99ee56840e5bbe8fd633bae2894e973621a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Security for qx-events 1.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.

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