Skip to main content

qx-cqrs

CQRS and Mediator implementation for the Qx framework. Dispatches commands, queries, domain events, integration events, and notifications through a composable pipeline of behaviors.

What lives here

  • qx.cqrs.Mediator — central dispatcher. Resolves handlers via the DI container; supports three registration modes: decorator scan, explicit register(), and type-based lookup.
  • qx.cqrs.Command / Query — base Pydantic models for all messages. Command[TResult] mutates state; Query[TResult] is read-only.
  • qx.cqrs.command_handler / query_handler / event_handler — decorators that bind a handler class to its message type.
  • qx.cqrs.Behavior — single-method interface (handle(request, next)) for pipeline stages.
  • Built-in behaviors: LoggingBehavior, TracingBehavior, MetricsBehavior, IdempotencyBehavior, ExceptionTranslationBehavior, TransactionBehavior, ValidationBehavior, RetryBehavior, AuthorizationBehavior.
  • qx.cqrs.compose — assemble a BehaviorChain from an ordered list of behaviors.

Usage

from qx.cqrs import Command, Mediator, command_handler
from qx.core import Result

class CreateUserCommand(Command[UserDto]):
    email: str
    name: str

@command_handler(CreateUserCommand)
class CreateUserHandler:
    def __init__(self, repo: UserRepository, uow: UnitOfWork) -> None: ...

    async def handle(self, cmd: CreateUserCommand) -> Result[UserDto]:
        result = User.register(cmd.email, cmd.name)
        ...
        return Result.success(dto)

# Bootstrap
mediator = Mediator(container)
mediator.register_decorated("myapp.application")

# Dispatch (in a route or test)
result = await mediator.send(CreateUserCommand(email="a@b.com", name="Ada"), scope=scope)

Pipeline composition

from qx.cqrs import compose, LoggingBehavior, TracingBehavior, ExceptionTranslationBehavior

pipeline = compose(
    LoggingBehavior(),
    TracingBehavior(tracer),
    ExceptionTranslationBehavior(),
)
mediator = Mediator(container, pipeline=pipeline)

Design rules

  • Handlers return Result[T] — they never raise. ExceptionTranslationBehavior converts unexpected exceptions to InfrastructureError before they escape the pipeline.
  • Commands and queries are plain Pydantic models; validation happens automatically before handle() is called.
  • The mediator resolves handlers lazily per send() call so the DI scope for that request is used correctly.

Metadata

Release files for qx-cqrs 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-cqrs 1.1.0
File Size Uploaded Provenance Actions
qx_cqrs-1.1.0.tar.gz 19.3 kB Without provenance Details for qx_cqrs-1.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 37.5 kB

Release files / qx_cqrs-1.1.0.tar.gz

Download URL qx_cqrs-1.1.0.tar.gz
Size 19.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7f1df31bc62e678253bc0364c58d3f477c08ad009d091dc1485080861fce19e8
BLAKE2b-256 checksum
How to use checksums
113f231d790a5cc9d4ac75147eac291942e1afaab216f9726b58517e9026f49b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

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

Download URL qx_cqrs-1.1.0-py3-none-any.whl
Size 18.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
16201c614f53bc34490bc9067a39216fbab8bf8f42c73fa74e44ab8e9533b5bc
BLAKE2b-256 checksum
How to use checksums
418a6ffe2a00bf59103d8f90c6eb8b3427dd5abb72916b51ddef48645531c659
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Security for qx-cqrs 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