Skip to main content

Event Sourcing with UmaDB

This package supports using the Python eventsourcing library with UmaDB.

Installation

Add the Python eventsourcing package to your project with the umadb option. Run uv init to start a new project.

uv add "eventsourcing[umadb,pydantic]~=10.0.0a3"

Pydantic is recommended for modelling and serialising events.

After installing, you can start the UmaDB server with uv run umadb.

Getting started

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

from typing import TypedDict
from uuid import uuid4

from eventsourcing.domain import triggers
from eventsourcing.pydantic import DcbApplication, Decision, EnduringObject


class Dog(EnduringObject):
    class Registered(Decision):
        dog_id: str
        name: str

    class TrickAdded(Decision):
        dog_id: str
        trick: str

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

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


class TrainingSchool(DcbApplication):
    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 = self.repository.get(dog_id, Dog)
        dog.add_trick(trick)
        self.repository.save(dog)

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


class DogSummary(TypedDict):
    name: str
    tricks: tuple[str, ...]

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.

Community

Join the Event Sourcing in Python Discord server today.

Contributors

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

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.4.2.tar.gz (6.8 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.4.2-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: eventsourcing_umadb-0.4.2.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.14.4 Darwin/25.5.0

File hashes

Hashes for eventsourcing_umadb-0.4.2.tar.gz
Algorithm Hash digest
SHA256 d3cdc00a3f11b57f9060936bce188edbd20c3bcea85223e138be5fecaf9245fe
MD5 e1035541bbd49e892b3312b738281b59
BLAKE2b-256 83fd4e5be5e8edc0217ed1238ee3851509bcf29b09a2bff40c557563678f9a17

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for eventsourcing_umadb-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1f4b025b3564226abfb42046b0c264d6adf8be4a2eadaf2200771992fda89480
MD5 e457802c70bd92744919b62a1c1b30d8
BLAKE2b-256 9f7baecaff176049c5e1236640a8421d6808fd5694595d649101d7eb02991d49

See more details on using hashes here.

Release history Release notifications | RSS feed

0.4.5

2 files

0.4.4

2 files

0.4.3

2 files

This release

0.4.2 This release

2 files

0.4.1

2 files

0.4.0

2 files

0.3.5

2 files

0.3.4

2 files

0.3.2

2 files

0.3.1

2 files

0.3

2 files

0.2

2 files

0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page