Skip to main content

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

Metadata

Release files for meator 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for meator 2.0.1
File Size Uploaded
meator-2.0.1.tar.gz 7.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for meator 2.0.1
File Interpreter ABI Platform
meator-2.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 21.3 kB

Release files / meator-2.0.1.tar.gz

Download URL meator-2.0.1.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
82f1b0aededcaa985191c4aa66788e95fb40fecbf765565001aeca5cb1a2557f
BLAKE2b-256 checksum
How to use checksums
1632c33cd5516f8bbb0ccd20308a242326230057a690acd9f3fa2904e67fe7df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.4 Linux/6.9.9-arch1-1

Release files / meator-2.0.1-py3-none-any.whl

Download URL meator-2.0.1-py3-none-any.whl
Size 14.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a86851c8248830fd96f199382a16ceda3088c0903be645a6675ebbfcf2cab796
BLAKE2b-256 checksum
How to use checksums
be5e2fee9a3432c2a72721927d4373d729655582a855274bf3f7cdead70295ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.4 Linux/6.9.9-arch1-1
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page