Getting started

Currently, mediatpy supports REPR pattern, pipeline, and notifications.

Also, it’s prepared for integration with third-party dependency injection containers through custom factories.

The library has been created using generics and using mypy to validate types. This means, that you will have autocomplete in editors that support it.

_images/IntelliSense.png

Installation

pip install mediatpy

Example

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