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
from typing import Any, Dict
from uuid import UUID
from eventsourcing.application import Application
from eventsourcing.domain import Aggregate, event
class TrainingSchool(Application):
def register(self, name: str) -> UUID:
dog = Dog(name)
self.save(dog)
return dog.id
def add_trick(self, dog_id: UUID, trick: str) -> None:
dog = self.repository.get(dog_id)
dog.add_trick(trick)
self.save(dog)
def get_dog(self, dog_id) -> Dict[str, Any]:
dog = self.repository.get(dog_id)
return {'name': dog.name, 'tricks': tuple(dog.tricks)}
class Dog(Aggregate):
@event('Registered')
def __init__(self, name: str) -> None:
self.name = name
self.tricks = []
@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.
school = 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 = school.register('Fido')
# Add tricks.
school.add_trick(dog_id, 'roll over')
school.add_trick(dog_id, 'play dead')
# Get details.
dog = school.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
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 eventsourcing_umadb-0.1.tar.gz.
File metadata
- Download URL: eventsourcing_umadb-0.1.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.14.0 Darwin/24.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc121cf92965f74ff27fdada87695e95985de08f548b706087c1bb3cea7c2855
|
|
| MD5 |
6b04a63cc87a9d9215f2f850b5d6a8a4
|
|
| BLAKE2b-256 |
0a784cb00abaae5789964a99cdd496a54b0df2910aa981480672f1d83b5726bf
|
File details
Details for the file eventsourcing_umadb-0.1-py3-none-any.whl.
File metadata
- Download URL: eventsourcing_umadb-0.1-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.14.0 Darwin/24.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0dc39f9994d3834c6b320da22640ec48c6a0caba552d2c55db9ef7a1c1547f6f
|
|
| MD5 |
4b6be9663b710aee802fd8c0e1adfe84
|
|
| BLAKE2b-256 |
ee30312c78b7c89efeb60e5edec4ce635165621aa63e1c49648d467a7370c2be
|