aett-domain


Nameaett-domain JSON
Version 2.1.0 PyPI version JSON
download
home_pageNone
SummaryDomain modeling types aett event store
upload_time2024-11-23 21:07:56
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseMIT License Copyright (c) 2024 python_eventstore Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords events event store ddd domain
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Æt (Aett) is an Event Store for Python

[![Downloads](https://static.pepy.tech/badge/aett-domain)](https://pepy.tech/project/aett-domain)

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.

```python
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.timezone.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.

```python
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

```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "aett-domain",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "events, event store, ddd, domain",
    "author": null,
    "author_email": "Jacob Reimers <pypi@reimers.io>",
    "download_url": "https://files.pythonhosted.org/packages/bc/dc/eade2ea57ad91ef14e363948b674cff45e02507f920511e7110f69729c9b/aett_domain-2.1.0.tar.gz",
    "platform": null,
    "description": "# \u00c6t (Aett) is an Event Store for Python\n\n[![Downloads](https://static.pepy.tech/badge/aett-domain)](https://pepy.tech/project/aett-domain)\n\nAett Domain provide base classes for `aggregate` and `saga` as encapsulations of business rules and processes, respectively.\n\n## Usage\n\nThe `Aggregate` class is abstract and a subtype aggregate would implement the external interfaces and internal behavior\nand define which events are raised as a response input.\n\n```python\nfrom aett.domain.Domain import Aggregate\nfrom dataclasses import dataclass\nfrom aett.eventstore.EventStream import EventStream, Memento, DomainEvent\nimport datetime\n\n\n@dataclass(frozen=True, kw_only=True)\nclass SampleEvent(DomainEvent):\n    value: int\n\n\nclass ExampleAggregate(Aggregate[Memento]):\n    def __init__(self, event_stream: EventStream, memento: Memento = None):\n        self.value = 0\n        super().__init__(event_stream, memento)\n\n    def apply_memento(self, memento: Memento) -> None:\n        if self.id != memento.id:\n            raise ValueError(\"Memento id does not match aggregate id\")\n        self.value = memento.payload\n\n    def get_memento(self) -> Memento:\n        \"\"\"\n        The memento is a snapshot of the aggregate state. It is used to rehydrate the aggregate.\n        \n        It is backed by the Python __getstate__ and __setstate__ methods.\n        \"\"\"\n        return Memento(id=self.id, version=self.version, payload={'key': self.value})\n\n    def set_value(self, value: int) -> None:\n        self.raise_event(\n            SampleEvent(value=value, id=self.id, version=self.version,\n                      timestamp=datetime.datetime.now(datetime.timezone.utc)))\n\n    def _apply(self, event: SampleEvent) -> None:\n        \"\"\"\n        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\n        \"\"\"\n        self.value = event.value\n\n```\n\nThe `saga` class is likewise abstract and a subtype saga would implement the external interfaces and internal behavior,\nsimilar to the `aggregate` class.\n\n```python\nfrom aett.domain.Domain import Saga\nfrom aett.eventstore.EventStream import DomainEvent\nfrom dataclasses import dataclass\n\n\n@dataclass(frozen=True, kw_only=True)\nclass SampleEvent(DomainEvent):\n    value: int\n\n    \nclass SampleSaga(Saga):\n    def _apply(self, event: SampleEvent) -> None:\n        pass\n\n```\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2024 python_eventstore  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Domain modeling types aett event store",
    "version": "2.1.0",
    "project_urls": {
        "Homepage": "https://github.com/jjrdk/aett"
    },
    "split_keywords": [
        "events",
        " event store",
        " ddd",
        " domain"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "00349a1e1b683bc721645a968b687d8fa11886508e5f10ae75f7f81cd2e58429",
                "md5": "89fcd6f3cea41babaa3cc62a6ce683c9",
                "sha256": "b1d7a9bd3d673fc999f76ce52c9ad9bea485a095f068d42424bedb3f25b60814"
            },
            "downloads": -1,
            "filename": "aett_domain-2.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "89fcd6f3cea41babaa3cc62a6ce683c9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 16909,
            "upload_time": "2024-11-23T21:07:49",
            "upload_time_iso_8601": "2024-11-23T21:07:49.504001Z",
            "url": "https://files.pythonhosted.org/packages/00/34/9a1e1b683bc721645a968b687d8fa11886508e5f10ae75f7f81cd2e58429/aett_domain-2.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bcdceade2ea57ad91ef14e363948b674cff45e02507f920511e7110f69729c9b",
                "md5": "ad89885a95504e7fa56969aff95188de",
                "sha256": "0659089cd7b85f597b6cb8170ac44606e93bebdfb457d75cd7eb0f9815b12af6"
            },
            "downloads": -1,
            "filename": "aett_domain-2.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "ad89885a95504e7fa56969aff95188de",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 10620,
            "upload_time": "2024-11-23T21:07:56",
            "upload_time_iso_8601": "2024-11-23T21:07:56.027371Z",
            "url": "https://files.pythonhosted.org/packages/bc/dc/eade2ea57ad91ef14e363948b674cff45e02507f920511e7110f69729c9b/aett_domain-2.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-23 21:07:56",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jjrdk",
    "github_project": "aett",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "aett-domain"
}
        
Elapsed time: 1.20007s