Skip to content

Files

Latest commit

8eae6b9 · Nov 15, 2022

History

History
52 lines (33 loc) · 1.85 KB

README.md

File metadata and controls

52 lines (33 loc) · 1.85 KB

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