CQRS dispatcher integrating python-cqrs-core with gridflow-python-mediator
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python_cqrs_dispatcher-0.1.1.tar.gz.
File metadata
- Download URL: python_cqrs_dispatcher-0.1.1.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6aeb42bbeb035fa508b76da655be9f480ee1ba6501d2aa26582292039bfda446
|
|
| MD5 |
845e0efc2568c48e491b5ff58f303c0f
|
|
| BLAKE2b-256 |
7515b459340624445300a618f401fb50d8455a92bbf8817959b6430900ce290a
|
Provenance
The following attestation bundles were made for python_cqrs_dispatcher-0.1.1.tar.gz:
Publisher:
publish-pypi.yml on firstunicorn/python-web-toolkit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
python_cqrs_dispatcher-0.1.1.tar.gz -
Subject digest:
6aeb42bbeb035fa508b76da655be9f480ee1ba6501d2aa26582292039bfda446 - Sigstore transparency entry: 1200097758
- Sigstore integration time:
-
Permalink:
firstunicorn/python-web-toolkit@89cb11be555f384b7154be09a8bccc29cfc66b73 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/firstunicorn
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@89cb11be555f384b7154be09a8bccc29cfc66b73 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file python_cqrs_dispatcher-0.1.1-py3-none-any.whl.
File metadata
- Download URL: python_cqrs_dispatcher-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5cdd9691fcb2590303354e3bf18adbdbbfa8de39ec08c605b4c1d1d3fc1146fc
|
|
| MD5 |
fff0c6a0176515dea82a1ae0e2b827da
|
|
| BLAKE2b-256 |
af8f3b33608f7a5fe5eeeffaa8a8f7fe94f47af58e47be2d62c7f6d9cd2fd417
|
Provenance
The following attestation bundles were made for python_cqrs_dispatcher-0.1.1-py3-none-any.whl:
Publisher:
publish-pypi.yml on firstunicorn/python-web-toolkit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
python_cqrs_dispatcher-0.1.1-py3-none-any.whl -
Subject digest:
5cdd9691fcb2590303354e3bf18adbdbbfa8de39ec08c605b4c1d1d3fc1146fc - Sigstore transparency entry: 1200098145
- Sigstore integration time:
-
Permalink:
firstunicorn/python-web-toolkit@89cb11be555f384b7154be09a8bccc29cfc66b73 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/firstunicorn
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@89cb11be555f384b7154be09a8bccc29cfc66b73 -
Trigger Event:
workflow_dispatch
-
Statement type: