Skip to main content

This is a fork from Diator, a Python library for implementing CQRS pattern in your applications. The original project is apparently abandoned.

Project description

Test Package version Supported Python versions

SiKei - CQRS Library for Python

Docs | PyPI

SiKei is a Python library for implementing CQRS pattern in your Python applications forked from Diator (https://akhundmurad.github.io/diator/). It provides a set of abstractions and utilities to help you separate your read and write concerns, allowing for better scalability, performance, and maintainability of your application.

Features :bulb:

Differences from original project :wrench:

  • Added support to RabbitMQ based on work from Fran Martin.
  • Added support to Dependency Injector from ETS Labs.
  • Migration to Pydantic based on work from 0xSecure.
  • Some incompatibilities in modules names and project organization to better integrate with my setup (easy to adapt from legacy projects)

Installation :triangular_ruler:

Install the SiKei library with pip

pip install sikei

There are also several installation options:

  • To use Redis as Message Broker

    pip install sikei[redis]
    
  • Or Azure Service Bus

    pip install sikei[azure]
    

Simple Example :hammer_and_wrench:

Minimal example of sikei usage:

import asyncio
from dataclasses import dataclass, field
from di import Container, bind_by_type
from di.dependent import Dependent
from sikei.events import EventMap, Event, EventEmitter
from sikei.container.di import DIContainer
from sikei.mediator import Mediator
from sikei.requests import Request, RequestHandler, RequestMap


@dataclass(frozen=True, kw_only=True)
class JoinMeetingCommand(Request):
    meeting_id: int
    user_id: int
    is_late: bool = field(default=False)


class JoinMeetingCommandHandler(RequestHandler[JoinMeetingCommand, None]):
    def __init__(self, meeting_api) -> None:
        self._meeting_api = meeting_api
        self._events: list[Event] = []

    @property
    def events(self) -> list[Event]:
        return self._events

    async def handle(self, request: JoinMeetingCommand) -> None:
        self._meeting_api.join(request.meeting_id, request.user_id)
        if request.is_late:
            self._meeting_api.warn(request.user_id)


def setup_di() -> DIContainer:
    external_container = Container()

    external_container.bind(
        bind_by_type(
            Dependent(JoinMeetingCommandHandler, scope="request"),
            JoinMeetingCommandHandler,
        )
    )

    container = DIContainer()
    container.attach_external_container(external_container)

    return container


async def main() -> None:
    container = setup_di()

    request_map = RequestMap()
    request_map.bind(JoinMeetingCommand, JoinMeetingCommandHandler)

    event_emitter = EventEmitter(
        event_map=EventMap(), container=container, message_broker=None
    )

    mediator = Mediator(
        request_map=request_map,
        event_emitter=event_emitter,
        container=container,
    )

    await mediator.send(JoinMeetingCommand(user_id=1, meeting_id=1, is_late=True))


if __name__ == "__main__":
    asyncio.run(main())

Further reading :scroll:

License

This project is licensed under the terms of the MIT license.

UV

Using UV to sync, build and publish

uv sync
uv build
uv publish

Inform __token__ and use token created at pypi.org

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

sikei-0.2.2.tar.gz (18.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sikei-0.2.2-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file sikei-0.2.2.tar.gz.

File metadata

  • Download URL: sikei-0.2.2.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.5

File hashes

Hashes for sikei-0.2.2.tar.gz
Algorithm Hash digest
SHA256 7669feeab990eedd1335feceb325e4f8c65a35b05e2bbaa3b47d84bf41b1bba6
MD5 ac55a5fd6521b4a48d2084408b578753
BLAKE2b-256 4e08be7d926db54bbd86362415d1f0038d566ca730e3d545a082c106ab9291f0

See more details on using hashes here.

File details

Details for the file sikei-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: sikei-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.5

File hashes

Hashes for sikei-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4f92d8865251e6fe00ce4583e784fd2cdc2f9c0061230b9da93320e65be2a24d
MD5 fdd922a7e34992e522faf4a77a9adfa7
BLAKE2b-256 adac0e324c269b981c9b85c3bfcb277403ce5c22367868aedb5465957c949a62

See more details on using hashes here.

Supported by

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