Event Sourcing in Python with DynamoDB
This package supports using the Python eventsourcing library with Amazon DynamoDB.
Table of contents
Quick start
To use DynamoDB with your Python eventsourcing applications:
- install the Python package
eventsourcing_dynamodb - set the environment variable
PERSISTENCE_MODULEto'eventsourcing_dynamodb' - set the environment variable
DYNAMO_ENDPOINT_URLto a DynamoDB endpoint URL - set the environment variable
DYNAMO_TABLEto a DynamoDB table
See below for more information.
Installation
Use pip to install the stable distribution from the Python Package Index. Please note, it is recommended to install Python packages into a Python virtual environment.
$ pip install eventsourcing_dynamodb
Getting started
Define aggregates and applications in the usual way.
from eventsourcing.application import Application
from eventsourcing.domain import Aggregate, event
from uuid import uuid5, NAMESPACE_URL
class TrainingSchool(Application):
def register(self, name):
dog = Dog(name)
self.save(dog)
def add_trick(self, name, trick):
dog = self.repository.get(Dog.create_id(name))
dog.add_trick(trick)
self.save(dog)
def get_tricks(self, name):
dog = self.repository.get(Dog.create_id(name))
return dog.tricks
class Dog(Aggregate):
@event('Registered')
def __init__(self, name):
self.name = name
self.tricks = []
@staticmethod
def create_id(name):
return uuid5(NAMESPACE_URL, f'/dogs/{name}')
@event('TrickAdded')
def add_trick(self, trick):
self.tricks.append(trick)
To use this module as the persistence module for your application, set the environment
variable PERSISTENCE_MODULE to 'eventsourcing_dynamodb'.
When using this module, you need to set the environment variables DYNAMO_ENDPOINT_URL and
DYNAMO_TABLE to a DynamoDB URL and table.
import os
os.environ['PERSISTENCE_MODULE'] = 'eventsourcing_dynamodb'
os.environ['DYNAMO_ENDPOINT_URL'] = 'http://localhost:8000'
os.environ['DYNAMO_TABLE'] = 'dynamo_events'
Construct and use the application in the usual way.
school = TrainingSchool()
school.register('Fido')
school.add_trick('Fido', 'roll over')
school.add_trick('Fido', 'play dead')
tricks = school.get_tricks('Fido')
assert tricks == ['roll over', 'play dead']
Metadata
Release files for eventsourcing-dynamodb 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| eventsourcing_dynamodb-0.1.0.tar.gz | 5.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| eventsourcing_dynamodb-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.8 kB
Release files / eventsourcing_dynamodb-0.1.0.tar.gz
| Download URL | eventsourcing_dynamodb-0.1.0.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c13fa8ffad25bddb0223e89c967a1ed0d3af5a426429f6d2993542a2746f0e64
|
|
BLAKE2b-256 checksum How to use checksums |
730e7af8035852689c48bb62adae305fae8a9e36a5eb78f7e9c79005104105b7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.13.1 Darwin/24.3.0
|
Release files / eventsourcing_dynamodb-0.1.0-py3-none-any.whl
| Download URL | eventsourcing_dynamodb-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bda7df56d3ae1fafd16fc87be00be1e6fa05afd9b18a937f931328cd8d58b4d4
|
|
BLAKE2b-256 checksum How to use checksums |
269b17dc0859cd0bea2cb9156ea0e56ca12d0957708ff27b21c24231785284a6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.13.1 Darwin/24.3.0
|