gridflow-python-mediator¶
Generic mediator pattern with pipeline behaviors for cross-cutting concerns.
Installation¶
pip install gridflow-python-mediator
Public API¶
Class |
Purpose |
|---|---|
|
Request/response dispatcher |
|
Protocol for pipeline behaviors |
|
Logs request handling |
|
Times request execution |
|
Validates Pydantic models before dispatch |
Usage¶
from gridflow_python_mediator import Mediator
from gridflow_python_mediator.behaviors import LoggingBehavior, ValidationBehavior
mediator = Mediator()
mediator.add_pipeline_behavior(LoggingBehavior())
mediator.add_pipeline_behavior(ValidationBehavior())
mediator.register_handler(MyRequest, MyHandler())
result = await mediator.send(MyRequest(data="test"))
Pipeline behavior protocol¶
class MyBehavior:
async def handle(self, request, next):
# pre-processing
result = await next(request)
# post-processing
return result