You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+85-96Lines changed: 85 additions & 96 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,29 +43,29 @@
43
43
44
44
## Overview
45
45
46
-
This is a package for implementing the CQRS (Command Query Responsibility Segregation) pattern in Python applications.
47
-
It provides a set of abstractions and utilities to help separate read and write use cases, ensuring better scalability,
48
-
performance, and maintainability of the application.
46
+
An event-driven framework for building distributed systems in Python. It centers on CQRS (Command Query Responsibility Segregation) and extends into messaging, sagas, and reliable event delivery β so you can separate read and write flows, react to events from the bus, run distributed transactions with compensation, and publish events via Transaction Outbox. The result is clearer structure, better scalability, and easier evolution of the application.
49
47
50
48
This package is a fork of the [diator](https://github.com/akhundMurad/diator)
51
-
project ([documentation](https://akhundmurad.github.io/diator/)) with several enhancements:
52
-
53
-
1. Support for Pydantic [v2.*](https://docs.pydantic.dev/2.8/);
54
-
2.`Kafka` support using [aiokafka](https://github.com/aio-libs/aiokafka);
55
-
3. Added `EventMediator` for handling `Notification` and `ECST` events coming from the bus;
56
-
4. Redesigned the event and request mapping mechanism to handlers;
57
-
5. Added `bootstrap` for easy setup;
58
-
6. Added support for [Transaction Outbox](https://microservices.io/patterns/data/transactional-outbox.html), ensuring
59
-
that `Notification` and `ECST` events are sent to the broker;
10.`StreamingRequestMediator` and `StreamingRequestHandler` for handling streaming requests with real-time progress updates;
64
-
11. Parallel event processing with configurable concurrency limits;
65
-
12. Chain of Responsibility pattern support with `CORRequestHandler` for processing requests through multiple handlers in sequence;
66
-
13. Orchestrated Saga pattern support for managing distributed transactions with automatic compensation and recovery mechanisms;
67
-
14. Built-in Mermaid diagram generation, enabling automatic generation of Sequence and Class diagrams for documentation and visualization;
68
-
15. Flexible Request and Response types support - use Pydantic-based or Dataclass-based implementations, with the ability to mix and match types based on your needs.
49
+
project ([documentation](https://akhundmurad.github.io/diator/)) with several enhancements, ordered by importance:
50
+
51
+
**Core framework**
52
+
53
+
1. Redesigned the event and request mapping mechanism to handlers;
54
+
2.`EventMediator` for handling `Notification` and `ECST` events coming from the bus;
55
+
3.`bootstrap` for easy setup;
56
+
4.**Transaction Outbox**, ensuring that `Notification` and `ECST` events are sent to the broker;
57
+
5.**Orchestrated Saga** pattern for distributed transactions with automatic compensation and recovery;
58
+
6.`StreamingRequestMediator` and `StreamingRequestHandler` for streaming requests with real-time progress updates;
59
+
7.**Chain of Responsibility** with `CORRequestHandler` for processing requests through multiple handlers in sequence;
60
+
8.**Parallel event processing** with configurable concurrency limits.
61
+
62
+
**Also**
63
+
64
+
-**Typing:** Pydantic [v2.*](https://docs.pydantic.dev/2.8/) and `IRequest`/`IResponse` interfaces β use Pydantic-based, dataclass-based, or custom Request/Response implementations.
65
+
-**Broker:** Kafka via [aiokafka](https://github.com/aio-libs/aiokafka).
66
+
-**Integration:** Ready for integration with FastAPI and FastStream.
67
+
-**Documentation:** Built-in Mermaid diagram generation (Sequence and Class diagrams).
68
+
-**Protobuf:** Interface-level support for converting Notification events to Protobuf and back.
69
69
70
70
## Request Handlers
71
71
@@ -87,7 +87,7 @@ class JoinMeetingCommandHandler(RequestHandler[JoinMeetingCommand, None]):
the [documentation](https://github.com/vadikko2/cqrs/blob/master/examples/kafka_outboxed_event_producing.py)
691
748
692
-
## Transaction log tailing
693
-
694
-
If the Outbox polling strategy does not suit your needs, I recommend exploring
695
-
the [Transaction Log Tailing](https://microservices.io/patterns/data/transaction-log-tailing.html) pattern.
696
-
The current version of the python-cqrs package does not support the implementation of this pattern.
697
-
698
-
> [!TIP]
699
-
> However, it can be implemented
700
-
> using [Debezium + Kafka Connect](https://debezium.io/documentation/reference/stable/architecture.html),
701
-
> which allows you to produce all newly created events within the Outbox storage directly to the corresponding topic in
702
-
> Kafka (or any other broker).
749
+
**Transaction log tailing.** If Outbox polling does not suit you, consider [Transaction Log Tailing](https://microservices.io/patterns/data/transaction-log-tailing.html). The package does not implement it; you can use [Debezium + Kafka Connect](https://debezium.io/documentation/reference/stable/architecture.html) to tail the Outbox and produce events to Kafka.
703
750
704
751
## DI container
705
752
@@ -765,65 +812,10 @@ Complete examples can be found in:
The `python-cqrs` package implements a set of bootstrap utilities designed to simplify the initial configuration of an
794
-
application.
795
-
796
-
```python
797
-
import functools
798
-
799
-
from cqrs.events import bootstrap as event_bootstrap
800
-
from cqrs.requests import bootstrap as request_bootstrap
801
-
802
-
from app import dependencies, mapping, orm
803
-
804
-
805
-
@functools.lru_cache
806
-
defmediator_factory():
807
-
return request_bootstrap.bootstrap(
808
-
di_container=dependencies.setup_di(),
809
-
commands_mapper=mapping.init_commands,
810
-
queries_mapper=mapping.init_queries,
811
-
domain_events_mapper=mapping.init_events,
812
-
on_startup=[orm.init_store_event_mapper],
813
-
)
814
-
815
-
816
-
@functools.lru_cache
817
-
defevent_mediator_factory():
818
-
return event_bootstrap.bootstrap(
819
-
di_container=dependencies.setup_di(),
820
-
events_mapper=mapping.init_events,
821
-
on_startup=[orm.init_store_event_mapper],
822
-
)
823
-
```
824
-
825
815
## Integration with presentation layers
826
816
817
+
The framework is ready for integration with **FastAPI** and **FastStream**.
818
+
827
819
> [!TIP]
828
820
> I recommend reading the useful
829
821
> paper [Onion Architecture Used in Software Development](https://www.researchgate.net/publication/371006360_Onion_Architecture_Used_in_Software_Development).
@@ -956,8 +948,5 @@ the [documentation](https://github.com/vadikko2/cqrs/blob/master/examples/fastap
956
948
957
949
## Protobuf messaging
958
950
959
-
The `python-cqrs` package supports integration with [protobuf](https://developers.google.com/protocol-buffers/).\\
960
-
Protocol buffers are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data β
961
-
think XML, but smaller, faster, and simpler. You define how you want your data to be structured once, then you can use
962
-
special generated source code to easily write and read your structured data to and from a variety of data streams and
963
-
using a variety of languages.
951
+
The `python-cqrs` package supports integration with [protobuf](https://developers.google.com/protocol-buffers/).
952
+
There is interface-level support for converting Notification events to Protobuf and back. Protocol buffers are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data β think XML, but smaller, faster, and simpler. You define how you want your data to be structured once, then you can use special generated source code to easily write and read your structured data to and from a variety of data streams and using a variety of languages.
0 commit comments