Skip to main content

Python package for eventsourcing with Axon Server

Project description

Event Sourcing with Axon Server

This package supports using the Python eventsourcing library with Axon Server.

Installation

Use pip to install the stable distribution from the Python Package Index.

$ pip install eventsourcing-axonserver

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 Axon Server start from position 0, so set INITIAL_VERSION on your aggregate classes accordingly.

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):
    INITIAL_VERSION = 0

    @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)

Configure the application to use Axon Server. Set environment variable PERSISTENCE_MODULE to 'eventsourcing_axonserver', and set AXONSERVER_URI to the host and port of your Axon Server.

school = TrainingSchool(env={
    "PERSISTENCE_MODULE": "eventsourcing_axonserver",
    "AXONSERVER_URI": "localhost:8124",
})

The application's methods may be then called, from tests and user interfaces.

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']

For more information, please refer to the Python eventsourcing library and the Axon Server project.

Developers

Clone the project 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 Axon Server.

$ make start-axon-server

Run tests.

$ make test

Add tests in ./tests. Add code in ./eventsourcing_axonserver.

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 Axon Server.

$ make stop-axon-server

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-axonserver-0.1.3.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file eventsourcing-axonserver-0.1.3.tar.gz.

File metadata

  • Download URL: eventsourcing-axonserver-0.1.3.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.4 Darwin/19.6.0

File hashes

Hashes for eventsourcing-axonserver-0.1.3.tar.gz
Algorithm Hash digest
SHA256 fd4f47e57f2ab8c7787475024fdd2c66bcad7dd49a3f6dfa83d9550280447f19
MD5 73e6dbd35a794eff1826538fa9a773c6
BLAKE2b-256 ef29da754683e3bf5e152783260bcde5be60301d61ddf052052a9dbed5904441

See more details on using hashes here.

File details

Details for the file eventsourcing_axonserver-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for eventsourcing_axonserver-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8e906cc3f63195e61fce37d253876b8ef38ce2c37da3d74593182b7e64e37a59
MD5 97956ad612af9fe7bf42360d330e397a
BLAKE2b-256 d379de27c4109ec75318e44058859ade2ed5eb8b85906ff68f3ac0fa586f7c29

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page