Python package for eventsourcing with EventStoreDB
Project description
Event Sourcing with EventStoreDB
This package supports using the Python eventsourcing library with EventStoreDB.
Installation
Use pip to install the stable distribution from the Python Package Index.
$ pip install eventsourcing-eventstoredb
Please note, it is recommended to install Python packages into a Python virtual environment.
Getting started
Define aggregates and applications in the usual way. Please note, aggregate
sequences in EventStoreDB start from position 0
, so set INITIAL_VERSION
on your aggregate classes accordingly.
from eventsourcing.application import Application
from eventsourcing.domain import Aggregate, event
class TrainingSchool(Application):
def register(self, name):
dog = Dog(name)
self.save(dog)
return dog.id
def add_trick(self, dog_id, trick):
dog = self.repository.get(dog_id)
dog.add_trick(trick)
self.save(dog)
def get_tricks(self, dog_id):
dog = self.repository.get(dog_id)
return dog.tricks
class Dog(Aggregate):
INITIAL_VERSION = 0
@event('Registered')
def __init__(self, name):
self.name = name
self.tricks = []
@event('TrickAdded')
def add_trick(self, trick):
self.tricks.append(trick)
Configure the application to use EventStoreDB. Set environment variable
PERSISTENCE_MODULE
to 'eventsourcing_eventstoredb'
, and set
EVENTSTOREDB_URI
to the host and port of your EventStoreDB.
school = TrainingSchool(env={
"PERSISTENCE_MODULE": "eventsourcing_eventstoredb",
"EVENTSTOREDB_URI": "localhost:2113",
})
In case you are running against a cluster, or want to use SSL/TLS certificates, you can specify these things in the URI.
"EVENTSTOREDB_URI": "esdb://localhost:2111,localhost:2112,localhost:2113?tls&rootCertificate=./certs/ca/ca.crt"
The application's methods may be then called, from tests and user interfaces.
dog_id = school.register('Fido')
school.add_trick(dog_id, 'roll over')
school.add_trick(dog_id, 'play dead')
tricks = school.get_tricks(dog_id)
assert tricks == ['roll over', 'play dead']
For more information, please refer to the Python eventsourcing library and the EventStoreDB project.
Developers
Clone the eventsourcing-eventstoredb
repository, set up a virtual
environment, and install dependencies.
Use your IDE (e.g. PyCharm) to open the project repository. Create a Poetry virtual environment, and then update packages.
$ make update-packages
Alternatively, use the make install
command to create a dedicated
Python virtual environment for this project.
$ make install
Start EventStoreDB.
$ make start-eventstoredb
Run tests.
$ make test
Add tests in ./tests
. Add code in ./eventsourcing_eventstoredb
.
Check the formatting of the code.
$ make lint
Reformat the code.
$ make fmt
Add dependencies in pyproject.toml
and then update installed packages.
$ make update-packages
Stop EventStoreDB.
$ make stop-eventstoredb
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
File details
Details for the file eventsourcing-eventstoredb-0.2.tar.gz
.
File metadata
- Download URL: eventsourcing-eventstoredb-0.2.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.10.4 Darwin/19.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52370c800f7b492ea6c9ea9ca0d1a2099f986d3a18ee02b46457e5feaa02c2e7 |
|
MD5 | 2437253cb1f9b6abfb63c51ca1311dc7 |
|
BLAKE2b-256 | 927449d33ac94b2c600c1b797639cc7dcd14aa498af9f94955086a722e006133 |
File details
Details for the file eventsourcing_eventstoredb-0.2-py3-none-any.whl
.
File metadata
- Download URL: eventsourcing_eventstoredb-0.2-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.10.4 Darwin/19.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae4da93c3d21fc74d26a7d489780b8e7dea9ae5e1958d75adb06185d114ce211 |
|
MD5 | eeaab91513842cc83e946efe7393496c |
|
BLAKE2b-256 | 6fc64e73157d89eaa5518827c8fba5849f26404b8c7b48ab1d538529d803122d |