Skip to main content

Python package for eventsourcing with DynamoDB

Project description

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_MODULE to 'eventsourcing_dynamodb'
  • set the environment variable DYNAMO_ENDPOINT_URL to a DynamoDB endpoint URL
  • set the environment variable DYNAMO_TABLE to 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']

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_dynamodb-0.1.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

eventsourcing_dynamodb-0.1.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file eventsourcing_dynamodb-0.1.0.tar.gz.

File metadata

  • Download URL: eventsourcing_dynamodb-0.1.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.13.1 Darwin/24.3.0

File hashes

Hashes for eventsourcing_dynamodb-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c13fa8ffad25bddb0223e89c967a1ed0d3af5a426429f6d2993542a2746f0e64
MD5 51640aafda844f36ab38b0c99fd2f566
BLAKE2b-256 730e7af8035852689c48bb62adae305fae8a9e36a5eb78f7e9c79005104105b7

See more details on using hashes here.

File details

Details for the file eventsourcing_dynamodb-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for eventsourcing_dynamodb-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bda7df56d3ae1fafd16fc87be00be1e6fa05afd9b18a937f931328cd8d58b4d4
MD5 fb7f058e1b93dd3af25f4fe43e594056
BLAKE2b-256 269b17dc0859cd0bea2cb9156ea0e56ca12d0957708ff27b21c24231785284a6

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