Pymediator
Provides a lightweight and extensible implementation of the Mediator pattern in Python, specifically designed for systems that follow the CQRS (Command Query Responsibility Segregation) pattern. Its architecture allows for a clear separation of command and query logic, making it ideal for clean architectures and event-driven systems.
Install
pip install pymediator
Usage
from dataclases import dataclass
from pymediator import Mediator as _Mediator, SingletonRegistry
registry: SingletonRegistry = SingletonRegistry()
@dataclass
class SumRequest:
x: int | float
y: int | float
class SumHandler:
def handle(self, request: SumRequest) -> int | float:
return request.x + request.y
registry.register(SumRequest, SumHandler)
class Mediator(_Mediator):
def __init__(self) -> None:
super().__init__(registry=SingletonRegistry())
mediator: Mediator = Mediator()
mediator.send(SumRequest(x=3, y=8)) # Output: 11
Recommended use
# my_app/application/queries/sum.py
from dataclases import dataclass
@dataclass
class SumRequest:
x: int | float
y: int | float
class SumHandler:
def handle(self, request: SumRequest) -> int | float:
return request.x + request.y
# my_app/infrastructure/mediator.py
from pymediator import SingletonRegistry
from my_app.application.queries.sum import SumRequest, SumHandler
registry: SingletonRegistry = SingletonRegistry()
registry.register(SumRequest, SumHandler)
# my_app/infrastructure/console.py
import sys
from my_app.application.queries.sum import SumRequest
@inject
def main(x: int, y: int, mediator: Mediator = Provide[AppContainer.mediator]) -> None:
print(mediator.send(SumRequest(x=x, y=y)))
if __name__ == "__main__":
num1: int = int(sys.argv[1])
num2: int = int(sys.argv[2])
main(num1, num2)
Metadata
Release files for pymediator 0.3.0
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 |
|---|---|---|---|---|
| pymediator-0.3.0.tar.gz | 6.6 kB | Without provenance | Details for pymediator-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pymediator-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for pymediator-0.3.0-py3-none-any.whl |
Total release size: 13.1 kB
Release files / pymediator-0.3.0.tar.gz
| Download URL | pymediator-0.3.0.tar.gz |
|---|---|
| Size | 6.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e6f223bd7e54057127c3dcfe8f13fe7dc52d1f7b48f46639b1f0087639b32eb7
|
|
BLAKE2b-256 checksum How to use checksums |
f93d9ec7a167aef3f1a74592a1e284ab08014580cd396fffe86160ab5049a263
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.4 CPython/3.10.15 Linux/6.5.0-1025-azure
|
Release files / pymediator-0.3.0-py3-none-any.whl
| Download URL | pymediator-0.3.0-py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0f51be647ca9a5d3b5cba759738ce7899734c373f75cc1dcadd7f10d3f723e0e
|
|
BLAKE2b-256 checksum How to use checksums |
7a64034391599147df80c496e57619066f63e11b52e89ec03b392e3ad307aef3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.4 CPython/3.10.15 Linux/6.5.0-1025-azure
|
Security for pymediator 0.3.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.