Python CQRS Dispatcher
CQRS dispatcher that integrates python-cqrs-core with gridflow-python-mediator for type-safe command/query dispatch.
Installation
pip install python-cqrs-dispatcher
Features
- Type-Safe Dispatch: Separate command/query dispatch methods
- Handler Registry: Track registered handlers
- Pipeline Behaviors: Built-in support via mediator
- Bulk Registration: Register multiple handlers at once
- Auto-Discovery: Auto-register handlers from modules
Usage
Basic Setup
from python_cqrs_dispatcher import CQRSDispatcher
from python_cqrs_core import BaseCommand, ICommandHandler
class CreateUserCommand(BaseCommand):
name: str
email: str
class CreateUserHandler(ICommandHandler[CreateUserCommand, int]):
async def handle(self, command: CreateUserCommand) -> int:
# Create user logic
return user_id
# Setup dispatcher
dispatcher = CQRSDispatcher()
dispatcher.register_command_handler(
CreateUserCommand,
CreateUserHandler()
)
# Dispatch command
cmd = CreateUserCommand(name="John", email="john@example.com")
user_id = await dispatcher.send_command(cmd)
With Queries
from python_cqrs_core import BaseQuery, IQueryHandler
class GetUserQuery(BaseQuery):
user_id: int
class GetUserHandler(IQueryHandler[GetUserQuery, User]):
async def handle(self, query: GetUserQuery) -> User:
return await db.get_user(query.user_id)
dispatcher.register_query_handler(GetUserQuery, GetUserHandler())
query = GetUserQuery(user_id=1)
user = await dispatcher.send_query(query)
Bulk Registration
from python_cqrs_dispatcher import register_handlers
handlers = [
(CreateUserCommand, CreateUserHandler()),
(UpdateUserCommand, UpdateUserHandler()),
(GetUserQuery, GetUserHandler()),
(ListUsersQuery, ListUsersHandler()),
]
register_handlers(dispatcher, handlers)
Pipeline Behaviors
from gridflow_python_mediator import LoggingBehavior, TimingBehavior
# Add behaviors (execute before all handlers)
dispatcher.add_pipeline_behavior(LoggingBehavior().handle)
dispatcher.add_pipeline_behavior(TimingBehavior().handle)
Auto-Registration
from python_cqrs_dispatcher import auto_register_handlers
import my_app.handlers
# Auto-discover and register all handlers
auto_register_handlers(dispatcher, my_app.handlers)
API Reference
CQRSDispatcher
Type-safe CQRS dispatcher.
Methods:
register_command_handler(command_type, handler)
Register command handler.
Parameters:
command_type(Type[ICommand]): Command classhandler(ICommandHandler): Handler instance
register_query_handler(query_type, handler)
Register query handler.
Parameters:
query_type(Type[IQuery]): Query classhandler(IQueryHandler): Handler instance
async send_command(command) -> Any
Dispatch command.
Parameters:
command(ICommand): Command to dispatch
Returns:
- Command result
async send_query(query) -> Any
Dispatch query.
Parameters:
query(IQuery): Query to dispatch
Returns:
- Query result
add_pipeline_behavior(behavior)
Add pipeline behavior.
Parameters:
behavior(Callable): Behavior function
Helper Functions
register_handlers(dispatcher, handlers)
Bulk register handlers.
Parameters:
dispatcher(CQRSDispatcher): Dispatcher instancehandlers(List[Tuple[Type, Any]]): Handler tuples
auto_register_handlers(dispatcher, module)
Auto-discover and register handlers.
Parameters:
dispatcher(CQRSDispatcher): Dispatcher instancemodule(Module): Python module to scan
Dependencies
python-cqrs-core>=0.1.0gridflow-python-mediator>=0.1.0
License
MIT
Metadata
Release files for python-cqrs-dispatcher 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| python_cqrs_dispatcher-0.1.1.tar.gz | 6.4 kB | With provenance | Details for python_cqrs_dispatcher-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| python_cqrs_dispatcher-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for python_cqrs_dispatcher-0.1.1-py3-none-any.whl |
Total release size: 11.6 kB
Release files / python_cqrs_dispatcher-0.1.1.tar.gz
| Download URL | python_cqrs_dispatcher-0.1.1.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6aeb42bbeb035fa508b76da655be9f480ee1ba6501d2aa26582292039bfda446
|
|
BLAKE2b-256 checksum How to use checksums |
7515b459340624445300a618f401fb50d8455a92bbf8817959b6430900ce290a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 30, 2026.
Transparency logRelease files / python_cqrs_dispatcher-0.1.1-py3-none-any.whl
| Download URL | python_cqrs_dispatcher-0.1.1-py3-none-any.whl |
|---|---|
| Size | 5.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5cdd9691fcb2590303354e3bf18adbdbbfa8de39ec08c605b4c1d1d3fc1146fc
|
|
BLAKE2b-256 checksum How to use checksums |
af8f3b33608f7a5fe5eeeffaa8a8f7fe94f47af58e47be2d62c7f6d9cd2fd417
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 30, 2026.
Transparency logSecurity for python-cqrs-dispatcher 0.1.1
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for python_cqrs_dispatcher-0.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 30, 2026.
Transparency logA 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.