{"id":23689,"library":"eventsourcing","title":"eventsourcing","description":"A library for event sourcing in Python. It provides a framework for building applications using the event sourcing pattern, with support for aggregates, projections, and various persistence backends. Current version is 9.5.4, requiring Python >=3.10. Active development with regular releases.","status":"active","version":"9.5.4","language":"python","source_language":"en","source_url":"https://github.com/pyeventsourcing/eventsourcing","tags":["event sourcing","cqrs","domain-driven design","python"],"install":[{"cmd":"pip install eventsourcing","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"Aggregate moved to eventsourcing.domain in v9.","wrong":"from eventsourcing.aggregate import Aggregate","symbol":"Aggregate","correct":"from eventsourcing.domain import Aggregate"},{"note":"Event classes are in eventsourcing.domain.","wrong":"from eventsourcing.event import Event","symbol":"Event","correct":"from eventsourcing.domain import Event"},{"note":"Application has been in eventsourcing.application since early versions.","wrong":"from eventsourcing.app import Application","symbol":"Application","correct":"from eventsourcing.application import Application"},{"note":"LogEvent is part of the domain module.","wrong":"from eventsourcing.events import LogEvent","symbol":"LogEvent","correct":"from eventsourcing.domain import LogEvent"}],"quickstart":{"code":"import os\nfrom eventsourcing.application import Application\nfrom eventsourcing.domain import Aggregate, event\n\nclass Dog(Aggregate):\n    @event('Registered')\n    def __init__(self, name):\n        self.name = name\n        self.tricks = []\n\n    @event('TrickAdded')\n    def add_trick(self, trick):\n        self.tricks.append(trick)\n\nclass DogSchool(Application):\n    def register_dog(self, name):\n        dog = Dog(name)\n        self.save(dog)\n        return dog.id\n\n    def add_trick(self, dog_id, trick):\n        dog = self.repository.get(dog_id)\n        dog.add_trick(trick)\n        self.save(dog)\n\n    def get_dog(self, dog_id):\n        return self.repository.get(dog_id)\n\napp = DogSchool()\ndog_id = app.register_dog('Fido')\napp.add_trick(dog_id, 'roll over')\ndog = app.get_dog(dog_id)\nprint(f'{dog.name}: {dog.tricks}')\n","lang":"python","description":"Minimal example: define an aggregate with events, an application, and execute."},"warnings":[{"fix":"Change imports to from eventsourcing.domain import Aggregate, Event, etc.","message":"In v9, the domain model classes (Aggregate, Event, etc.) are no longer in the top-level package. They moved to eventsourcing.domain. Importing from old paths will raise ImportError.","severity":"breaking","affected_versions":">=9.0.0"},{"fix":"Decorate __init__ and other event-applying methods with @event('EventName').","message":"The 'event' decorator for methods is now required to mark event constructor methods. In v8, event methods were inferred; in v9 they must be explicitly decorated.","severity":"breaking","affected_versions":">=9.0.0"},{"fix":"Use eventsourcing[postgres] or eventsourcing[sqlite] extras and configure via environment variables.","message":"The 'sqlalchemy' persistence module has been deprecated in favor of 'sqlalchemy' as an optional dependency via eventsourcing[postgres] or eventsourcing[sqlite]. Direct import from eventsourcing.persistence.sqlalchemy may be removed.","severity":"deprecated","affected_versions":">=9.5.0"},{"fix":"Set os.environ['DB_URI'] = 'sqlite:///path/to/db' before instantiating app.","message":"When using SQLite for persistence, the database file path must be set via environment variable DB_URI or passed to Application constructor. Not providing it will cause silent fallback to in-memory store which is not persisted.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use 'from eventsourcing.domain import Aggregate'.","cause":"Aggregate class moved to eventsourcing.domain in v9.","error":"ModuleNotFoundError: No module named 'eventsourcing.aggregate'"},{"fix":"Add '@event('Registered')' above __init__.","cause":"Domain aggregate class missing @event decorator on __init__.","error":"TypeError: Can't instantiate abstract class Dog with abstract methods"},{"fix":"Use 'self.save(dog)' inside the Application method, not dog.save()","cause":"Calling save on the aggregate instance directly instead of through application.","error":"AttributeError: 'Dog' object has no attribute 'save'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}