This library is a port of Mediatr in Python.
For more information and usage instructions, see the documentation.
pip install mediatpy
import asyncio
from mediatpy import Request, RequestHandler, Mediator
class MyResponse:
pass
class MyRequest(Request[MyResponse]):
pass
mediator = Mediator()
@mediator.request_handler
class MyRequestHandler(RequestHandler[MyRequest, MyResponse]):
async def handle(self, request: MyRequest) -> MyResponse:
return MyResponse()
async def main():
request = MyRequest()
response = await mediator.send(request)
assert isinstance(response, MyResponse)
if __name__ == '__main__':
asyncio.run(main())