Domain modeling types aett event store
Project description
Æt (Aett) is an Event Store for Python
Aett Domain provide base classes for aggregate and saga as encapsulations of business rules and processes, respectively.
Usage
The Aggregate class is abstract and a subtype aggregate would implement the external interfaces and internal behavior
and define which events are raised as a response input.
from aett.domain.Domain import Aggregate
from dataclasses import dataclass
from aett.eventstore.EventStream import EventStream, Memento, DomainEvent
import datetime
@dataclass(frozen=True, kw_only=True)
class SampleEvent(DomainEvent):
value: int
class ExampleAggregate(Aggregate[Memento]):
def __init__(self, event_stream: EventStream, memento: Memento = None):
self.value = 0
super().__init__(event_stream, memento)
def apply_memento(self, memento: Memento) -> None:
if self.id != memento.id:
raise ValueError("Memento id does not match aggregate id")
self.value = memento.payload
def get_memento(self) -> Memento:
"""
The memento is a snapshot of the aggregate state. It is used to rehydrate the aggregate.
It is backed by the Python __getstate__ and __setstate__ methods.
"""
return Memento(id=self.id, version=self.version, payload={'key': self.value})
def set_value(self, value: int) -> None:
self.raise_event(
SampleEvent(value=value, id=self.id, version=self.version,
timestamp=datetime.datetime.now(datetime.UTC)))
def _apply(self, event: SampleEvent) -> None:
"""
The apply method is a convention named method to apply the event to the aggregate. It is called from the raise_event method using multiple dispatch
"""
self.value = event.value
The saga class is likewise abstract and a subtype saga would implement the external interfaces and internal behavior,
similar to the aggregate class.
from aett.domain.Domain import Saga
from aett.eventstore.EventStream import DomainEvent
from dataclasses import dataclass
@dataclass(frozen=True, kw_only=True)
class SampleEvent(DomainEvent):
value: int
class SampleSaga(Saga):
def _apply(self, event: SampleEvent) -> None:
pass
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aett_domain-1.0.0.tar.gz.
File metadata
- Download URL: aett_domain-1.0.0.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99f88cc72afcbb81b27e5b44877c563ca5cd2e289b7f4cdfc77b8947e0ea4ad7
|
|
| MD5 |
d05f3929730270872e1e5c9513d9c19c
|
|
| BLAKE2b-256 |
172a6c3cb19462dbc066a632582e41bc72afed139d8f517dafe613c6c4010226
|
File details
Details for the file aett_domain-1.0.0-py3-none-any.whl.
File metadata
- Download URL: aett_domain-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5628d2cd02c6008b8cf544fd8c675017e9c4159a20306e4f3cbd9c4d16a22513
|
|
| MD5 |
948fa8a103b478a3a6dcbbeaaeaa60f6
|
|
| BLAKE2b-256 |
f069a71e982117f9c4cbe676f1a5254c91b6946fbd69c9eb41f858c8569f5499
|