Skip to main content

Python package for eventsourcing with UmaDB

Project description

Event Sourcing with UmaDB

This package supports using the Python eventsourcing library with UmaDB.

Installation

Use pip to install the stable distribution from the Python Package Index.

$ pip install eventsourcing-umadb

Please note, it is recommended to install Python packages into a Python virtual environment.

Getting started

Use the eventsourcing.dcb package to define a DCB application. Read the docs for more information.

from typing import Any, Dict, cast

from eventsourcing.dcb.application import DCBApplication
from eventsourcing.dcb.domain import EnduringObject
from eventsourcing.dcb.msgpack import Decision, InitialDecision, MessagePackMapper
from eventsourcing.domain import event
from eventsourcing.utils import get_topic


class TrainingSchool(DCBApplication):
    env = {"MAPPER_TOPIC": get_topic(MessagePackMapper)}

    def register(self, name: str) -> str:
        dog = Dog(name=name)
        self.repository.save(dog)
        return dog.id

    def add_trick(self, dog_id: str, trick: str) -> None:
        dog = cast(Dog, self.repository.get(dog_id))
        dog.add_trick(trick)
        self.repository.save(dog)

    def get_dog(self, dog_id: str) -> Dict[str, Any]:
        dog = cast(Dog, self.repository.get(dog_id))
        return {"name": dog.name, "tricks": tuple(dog.tricks)}


class Dog(EnduringObject[Decision, str]):
    class Registered(InitialDecision):
        dog_id: str
        name: str

    class TrickAdded(Decision):
        trick: str

    @event(Registered)
    def __init__(self, *, name: str) -> None:
        self.name = name
        self.tricks: list[str] = []

    @event(TrickAdded)
    def add_trick(self, trick: str) -> None:
        self.tricks.append(trick)

Configure the application to use UmaDB. Set environment variable PERSISTENCE_MODULE to 'eventsourcing_umadb', and set UMADB_URI to your UmaDB URI.

app = TrainingSchool(
    env={
        "PERSISTENCE_MODULE": "eventsourcing_umadb",
        "UMADB_URI": "http://127.0.0.1:50051",
    }
)

The application's methods may be then called, from tests and user interfaces.

# Register dog.
dog_id = app.register("Fido")

# Add tricks.
app.add_trick(dog_id, "roll over")
app.add_trick(dog_id, "play dead")

# Get details.
dog = app.get_dog(dog_id)
assert dog["name"] == "Fido"
assert dog["tricks"] == ("roll over", "play dead")

For more information, please refer to the Python eventsourcing library and the UmaDB project.

Developers

Clone the GitHub repo and the use the following make commands.

Install Poetry.

$ make install-poetry

Install packages.

$ make install

Start UmaDB.

$ make start-umadb

Run tests.

$ make test

Stop UmaDB.

$ make stop-umadb

Check the formatting of the code.

$ make lint

Reformat the code.

$ make fmt

Tests belong in ./tests.

Edit package dependencies in pyproject.toml. Update installed packages (and the poetry.lock file) using the following command.

$ make update

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

eventsourcing_umadb-0.3.2.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

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

eventsourcing_umadb-0.3.2-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file eventsourcing_umadb-0.3.2.tar.gz.

File metadata

  • Download URL: eventsourcing_umadb-0.3.2.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.14.0 Darwin/24.6.0

File hashes

Hashes for eventsourcing_umadb-0.3.2.tar.gz
Algorithm Hash digest
SHA256 ec4eab654f95bc3d71c06fb6ad4702ed12167250f61592e1043e4b18781fa72e
MD5 94615c0a523f9bdc5c77f146de78a91a
BLAKE2b-256 c26ad0136cbe9db36caa7e300110c1918a2a44ca09242052f40d1a5e25312535

See more details on using hashes here.

File details

Details for the file eventsourcing_umadb-0.3.2-py3-none-any.whl.

File metadata

File hashes

Hashes for eventsourcing_umadb-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e43626d4a5f5da1aef2a32a3dc7f3ae41a9a7c870a6a3187c8ea2616dab7ac57
MD5 4b9f9c0558da71dbe5464c6d7ca3cce8
BLAKE2b-256 d2bf595e534513d408057b89cfb3e34e69e1a47a3153846fd16748cf42c88f44

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