mediatpy

Mediator implementation in Python


Keywords
mediator
Install
pip install mediatpy==0.2.1

Documentation

pre-commit Code style: black Imports: isort Checked with mypy security: bandit Upload Python Package Coverage Status Documentation Status PyPI version

Introduction

This library is a port of Mediatr in Python.

For more information and usage instructions, see the documentation.

Usage

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())