Skip to main content

Mediator pattern impl

Project description

Meator

image Mypy checked codecov image Ruff image

Python CQRS pattern implementation.

Docs

Installation

pip install meator

Available

  • Dispatchers:
    • Command
    • Query
  • Observers:
    • Event
  • Entities:
    • Command
    • Event
    • Query
  • Middlewares

Usecases

Command/Event/Query

from dataclasses import dataclass

from meator.dispatchers import CommandDispatcherImpl
from meator.entities import Command
from meator.interfaces import CommandHandler


@dataclass
class IntCommand(Command[int]):
    answer: int


class IntCommandHandler(CommandHandler[IntCommand, int]):
    async def __call__(self, request: IntCommand) -> int:
        return request.answer


async def main():
    c = CommandDispatcherImpl()

    c.register(IntCommand, IntCommandHandler())

    await c.handle(IntCommand(1))

Middleware

from dataclasses import dataclass

from meator.dispatchers import CommandDispatcherImpl
from meator.entities import Command, Request
from meator.interfaces import CommandHandler, Handler, Middleware


class SimpleMiddleware(Middleware):
    async def __call__(self, call_next: Handler, request: Request):
        return await call_next(request)


@dataclass
class IntCommand(Command[int]):
    answer: int


class IntCommandHandler(CommandHandler[IntCommand, int]):
    async def __call__(self, request: IntCommand) -> int:
        return request.answer


async def main():
    c = CommandDispatcherImpl(middlewares=[SimpleMiddleware()])

    c.register(IntCommand, IntCommandHandler())

    await c.handle(IntCommand(1))

Tests

  • pytest tests

Additional

Inspired by didator

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

meator-2.0.1.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

meator-2.0.1-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file meator-2.0.1.tar.gz.

File metadata

  • Download URL: meator-2.0.1.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.9.9-arch1-1

File hashes

Hashes for meator-2.0.1.tar.gz
Algorithm Hash digest
SHA256 82f1b0aededcaa985191c4aa66788e95fb40fecbf765565001aeca5cb1a2557f
MD5 b5792cfe87ce83339e0e7b3220a4e82d
BLAKE2b-256 1632c33cd5516f8bbb0ccd20308a242326230057a690acd9f3fa2904e67fe7df

See more details on using hashes here.

File details

Details for the file meator-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: meator-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.9.9-arch1-1

File hashes

Hashes for meator-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a86851c8248830fd96f199382a16ceda3088c0903be645a6675ebbfcf2cab796
MD5 8ad9cad259d95ad040dcdcbe27ddc155
BLAKE2b-256 be5e2fee9a3432c2a72721927d4373d729655582a855274bf3f7cdead70295ef

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page