eventsourcing¶
Interface layer¶
eventsourcing.interface.notificationlog
¶
-
class
eventsourcing.interface.notificationlog.
AbstractNotificationLog
[source]¶ Bases:
object
Presents a sequence of sections from a sequence of notifications.
-
class
eventsourcing.interface.notificationlog.
NotificationLog
(big_array, section_size)[source]¶ Bases:
eventsourcing.interface.notificationlog.AbstractNotificationLog
-
class
eventsourcing.interface.notificationlog.
NotificationLogReader
(notification_log)[source]¶ Bases:
object
-
class
eventsourcing.interface.notificationlog.
RemoteNotificationLog
(base_url, notification_log_id)[source]¶ Bases:
eventsourcing.interface.notificationlog.AbstractNotificationLog
-
class
eventsourcing.interface.notificationlog.
Section
(section_id, items, previous_id=None, next_id=None)[source]¶ Bases:
object
Section of a notification log.
Contains items, and has an ID.
May also have either IDs of previous and next sections of the notification log.
Application layer¶
eventsourcing.application.base
¶
-
class
eventsourcing.application.base.
ApplicationWithEventStores
(entity_active_record_strategy=None, log_active_record_strategy=None, snapshot_active_record_strategy=None, always_encrypt=False, cipher=None)[source]¶ Bases:
object
-
construct_event_store
(event_sequence_id_attr, event_position_attr, active_record_strategy, always_encrypt=False, cipher=None)[source]¶
-
construct_sequenced_item_mapper
(sequenced_item_class, event_sequence_id_attr, event_position_attr, json_encoder_class=<class 'eventsourcing.infrastructure.transcoding.ObjectJSONEncoder'>, json_decoder_class=<class 'eventsourcing.infrastructure.transcoding.ObjectJSONDecoder'>, always_encrypt=False, cipher=None)[source]¶
-
-
class
eventsourcing.application.base.
ApplicationWithPersistencePolicies
(**kwargs)[source]¶ Bases:
eventsourcing.application.base.ApplicationWithEventStores
Domain layer¶
eventsourcing.domain.model.aggregate
¶
-
class
eventsourcing.domain.model.aggregate.
AggregateRoot
(**kwargs)[source]¶ Bases:
eventsourcing.domain.model.entity.TimestampedVersionedEntity
Root entity for an aggregate in a domain driven design.
-
class
AttributeChanged
(timestamp=None, **kwargs)[source]¶ Bases:
eventsourcing.domain.model.aggregate.Event
,eventsourcing.domain.model.entity.AttributeChanged
Published when an AggregateRoot is changed.
-
class
Created
(timestamp=None, **kwargs)[source]¶ Bases:
eventsourcing.domain.model.aggregate.Event
,eventsourcing.domain.model.entity.Created
Published when an AggregateRoot is created.
-
class
Discarded
(timestamp=None, **kwargs)[source]¶ Bases:
eventsourcing.domain.model.aggregate.Event
,eventsourcing.domain.model.entity.Discarded
Published when an AggregateRoot is discarded.
-
class
eventsourcing.domain.model.array
¶
-
class
eventsourcing.domain.model.array.
AbstractArrayRepository
(array_size=10000, *args, **kwargs)[source]¶ Bases:
eventsourcing.domain.model.entity.AbstractEntityRepository
Repository for sequence objects.
-
class
eventsourcing.domain.model.array.
AbstractBigArrayRepository
(*args, **kwargs)[source]¶ Bases:
eventsourcing.domain.model.entity.AbstractEntityRepository
Repository for compound sequence objects.
-
subrepo
¶ Sub-sequence repository.
-
-
class
eventsourcing.domain.model.array.
BigArray
(array_id, repo)[source]¶ Bases:
eventsourcing.domain.model.array.Array
A virtual array holding items in indexed positions, across a number of Array instances.
Getting and setting items at index position is supported. Slices are supported, and operate across the underlying arrays. Appending is also supported.
BigArray is designed to overcome the concern of needing a single large sequence that may not be suitably stored in any single partiton. In simple terms, if events of an aggregate can fit in a partition, we can use the same size partition to make a tree of arrays that will certainly be capable of sequencing all the events of the application in a single stream.
With normal size base arrays, enterprise applications can expect read and write time to be approximately constant with respect to the number of items in the array.
The array is composed of a tree of arrays, which gives the capacity equal to the size of each array to the power of the size of each array. If the arrays are limited to be about the maximum size of an aggregate event stream (a large number but not too many that would cause there to be too much data in any one partition, let’s say 1000s to be safe) then it would be possible to fit such a large number of aggregates in the corresponding BigArray, that we can be confident it would be full.
Write access time in the worst case, and the time to identify the index of the last item in the big array, is proportional to the log of the highest assigned index to the base of the underlying array size. Write time on average, and read time given an index, is contant with respect to the number of items in a BigArray.
Items can be appended in log time in a single thread. However, the time between reading the current last index and claiming the next position leads to contention and retries when there are lots of threads of execution all attempting to append items, which inherently limits throughput.
Todo: Not possible in Cassandra, but maybe do it in a transaction in SQLAlchemy?
An alternative to reading the last item before writing the next is to use an integer sequence generator to generate a stream of integers. Items can be assigned to index positions in a big array, according to the integers that are issued. Throughput will then be much better, and will be limited only by the rate at which the database can have events written to it (unless the number generator is quite slow).
An external integer sequence generator, such as Redis’ INCR command, or an auto-incrementing database column, may constitute a single point of failure.
eventsourcing.domain.model.decorators
¶
-
eventsourcing.domain.model.decorators.
attribute
(getter)[source]¶ When used as a method decorator, returns a property object with the method as the getter and a setter defined to call instance method change_attribute(), which publishes an AttributeChanged event.
-
eventsourcing.domain.model.decorators.
mutator
(arg=None)[source]¶ Structures mutator functions by allowing handlers to be registered for different types of event. When the decorated function is called with an initial value and an event, it will call the handler that has been registered for that type of event.
It works like singledispatch, which it uses. The difference is that when the decorated function is called, this decorator dispatches according to the type of last call arg, which fits better with reduce(). The builtin Python function reduce() is used by the library to replay a sequence of events against an initial state. If a mutator function is given to reduce(), along with a list of events and an initializer, reduce() will call the mutator function once for each event in the list, but the initializer will be the first value, and the event will be the last argument, and we want to dispatch according to the type of the event. It happens that singledispatch is coded to switch on the type of the first argument, which makes it unsuitable for structuring a mutator function without the modifications introduced here.
The other aspect introduced by this decorator function is the option to set the type of the handled entity in the decorator. When an entity is replayed from scratch, in other words when all its events are replayed, the initial state is None. The handler which handles the first event in the sequence will probably construct an object instance. It is possible to write the type into the handler, but that makes the entity more difficult to subclass because you will also need to write a handler for it. If the decorator is invoked with the type, when the initial value passed as a call arg to the mutator function is None, the handler will instead receive the type of the entity, which it can use to construct the entity object.
class Entity(object): class Created(object): pass @mutator(Entity) def mutate(initial, event): raise NotImplementedError(type(event)) @mutate.register(Entity.Created) def _(initial, event): return initial(**event.__dict__) entity = mutate(None, Entity.Created())
-
eventsourcing.domain.model.decorators.
random
() → x in the interval [0, 1).¶
-
eventsourcing.domain.model.decorators.
retry
(exc=<class 'Exception'>, max_retries=1, wait=0)[source]¶
-
eventsourcing.domain.model.decorators.
subscribe_to
(event_class)[source]¶ Decorator for making a custom event handler function subscribe to a certain event type
event_class: DomainEvent class or its child classes that the handler function should subscribe to
The following example shows a custom handler that reacts to Todo.Created event and saves a projection of a Todo model object.
@subscribe_to(Todo.Created) def new_todo_projection(event): todo = TodoProjection(id=event.originator_id, title=event.title) todo.save()
eventsourcing.domain.model.entity
¶
-
class
eventsourcing.domain.model.entity.
AbstractEntityRepository
(*args, **kwargs)[source]¶ Bases:
object
-
event_store
¶ Returns event store object used by this repository.
-
-
class
eventsourcing.domain.model.entity.
DomainEntity
(originator_id)[source]¶ Bases:
eventsourcing.domain.model.events.QualnameABC
-
class
AttributeChanged
(originator_id, **kwargs)[source]¶ Bases:
eventsourcing.domain.model.entity.Event
,eventsourcing.domain.model.events.AttributeChanged
Published when a DomainEntity is discarded.
-
class
Created
(originator_id, **kwargs)[source]¶ Bases:
eventsourcing.domain.model.entity.Event
,eventsourcing.domain.model.events.Created
Published when a DomainEntity is created.
-
class
Discarded
(originator_id, **kwargs)[source]¶ Bases:
eventsourcing.domain.model.entity.Event
,eventsourcing.domain.model.events.Discarded
Published when a DomainEntity is discarded.
-
class
Event
(originator_id, **kwargs)[source]¶ Bases:
eventsourcing.domain.model.events.EventWithOriginatorID
,eventsourcing.domain.model.events.DomainEvent
Layer supertype.
-
change_attribute
(name, value, **kwargs)[source]¶ Changes given attribute of the entity, by constructing and applying an AttributeChanged event.
-
id
¶
-
class
-
class
eventsourcing.domain.model.entity.
TimestampedEntity
(timestamp, **kwargs)[source]¶ Bases:
eventsourcing.domain.model.entity.DomainEntity
-
class
AttributeChanged
(timestamp=None, **kwargs)[source]¶ Bases:
eventsourcing.domain.model.entity.Event
,eventsourcing.domain.model.entity.AttributeChanged
Published when a TimestampedEntity is changed.
-
class
Created
(timestamp=None, **kwargs)[source]¶ Bases:
eventsourcing.domain.model.entity.Event
,eventsourcing.domain.model.entity.Created
Published when a TimestampedEntity is created.
-
class
Discarded
(timestamp=None, **kwargs)[source]¶ Bases:
eventsourcing.domain.model.entity.Event
,eventsourcing.domain.model.entity.Discarded
Published when a TimestampedEntity is discarded.
-
class
Event
(timestamp=None, **kwargs)[source]¶ Bases:
eventsourcing.domain.model.events.EventWithTimestamp
,eventsourcing.domain.model.entity.Event
Layer supertype.
-
created_on
¶
-
last_modified_on
¶
-
class
-
class
eventsourcing.domain.model.entity.
TimestampedVersionedEntity
(timestamp, **kwargs)[source]¶ Bases:
eventsourcing.domain.model.entity.TimestampedEntity
,eventsourcing.domain.model.entity.VersionedEntity
-
class
AttributeChanged
(timestamp=None, **kwargs)[source]¶ Bases:
eventsourcing.domain.model.entity.Event
,eventsourcing.domain.model.entity.AttributeChanged
,eventsourcing.domain.model.entity.AttributeChanged
Published when a TimestampedVersionedEntity is created.
-
class
Created
(timestamp=None, **kwargs)[source]¶ Bases:
eventsourcing.domain.model.entity.Event
,eventsourcing.domain.model.entity.Created
,eventsourcing.domain.model.entity.Created
Published when a TimestampedVersionedEntity is created.
-
class
-
class
eventsourcing.domain.model.entity.
TimeuuidedEntity
(event_id, **kwargs)[source]¶ Bases:
eventsourcing.domain.model.entity.DomainEntity
-
created_on
¶
-
last_modified_on
¶
-
-
class
eventsourcing.domain.model.entity.
TimeuuidedVersionedEntity
(event_id, **kwargs)[source]¶ Bases:
eventsourcing.domain.model.entity.TimeuuidedEntity
,eventsourcing.domain.model.entity.VersionedEntity
-
class
eventsourcing.domain.model.entity.
VersionedEntity
(originator_version, **kwargs)[source]¶ Bases:
eventsourcing.domain.model.entity.DomainEntity
-
class
AttributeChanged
(originator_version, **kwargs)[source]¶ Bases:
eventsourcing.domain.model.entity.Event
,eventsourcing.domain.model.entity.AttributeChanged
Published when a VersionedEntity is changed.
-
class
Created
(originator_version=0, **kwargs)[source]¶ Bases:
eventsourcing.domain.model.entity.Event
,eventsourcing.domain.model.entity.Created
Published when a VersionedEntity is created.
-
class
Discarded
(originator_version, **kwargs)[source]¶ Bases:
eventsourcing.domain.model.entity.Event
,eventsourcing.domain.model.entity.Discarded
Published when a VersionedEntity is discarded.
-
class
Event
(originator_version, **kwargs)[source]¶ Bases:
eventsourcing.domain.model.events.EventWithOriginatorVersion
,eventsourcing.domain.model.entity.Event
Layer supertype.
-
version
¶
-
class
-
class
eventsourcing.domain.model.entity.
WithReflexiveMutator
(originator_id)[source]¶ Bases:
eventsourcing.domain.model.entity.DomainEntity
Implements an entity mutator function by dispatching to the event itself all calls to mutate an entity with an event.
This is an alternative to using an independent mutator function implemented with the @mutator decorator, or an if-else block.
eventsourcing.domain.model.events
¶
-
class
eventsourcing.domain.model.events.
AttributeChanged
(**kwargs)[source]¶ Bases:
eventsourcing.domain.model.events.DomainEvent
Can be published when an attribute of an entity is created.
-
name
¶
-
value
¶
-
-
class
eventsourcing.domain.model.events.
Created
(**kwargs)[source]¶ Bases:
eventsourcing.domain.model.events.DomainEvent
Can be published when an entity is created.
-
class
eventsourcing.domain.model.events.
Discarded
(**kwargs)[source]¶ Bases:
eventsourcing.domain.model.events.DomainEvent
Published when something is discarded.
-
class
eventsourcing.domain.model.events.
DomainEvent
(**kwargs)[source]¶ Bases:
eventsourcing.domain.model.events.QualnameABC
Base class for domain events.
Implements methods to make instances read-only, comparable for equality, have recognisable representations, and hashable.
-
class
eventsourcing.domain.model.events.
EventWithOriginatorID
(originator_id, **kwargs)[source]¶ Bases:
eventsourcing.domain.model.events.DomainEvent
-
originator_id
¶
-
-
class
eventsourcing.domain.model.events.
EventWithOriginatorVersion
(originator_version, **kwargs)[source]¶ Bases:
eventsourcing.domain.model.events.DomainEvent
For events that have an originator version number.
-
originator_version
¶
-
-
class
eventsourcing.domain.model.events.
EventWithTimestamp
(timestamp=None, **kwargs)[source]¶ Bases:
eventsourcing.domain.model.events.DomainEvent
For events that have a timestamp value.
-
timestamp
¶
-
-
class
eventsourcing.domain.model.events.
EventWithTimeuuid
(event_id=None, **kwargs)[source]¶ Bases:
eventsourcing.domain.model.events.DomainEvent
For events that have an UUIDv1 event ID.
-
event_id
¶
-
-
class
eventsourcing.domain.model.events.
Logged
(**kwargs)[source]¶ Bases:
eventsourcing.domain.model.events.DomainEvent
Published when something is logged.
-
class
eventsourcing.domain.model.events.
QualnameABC
[source]¶ Bases:
object
Base class that introduces __qualname__ for objects in Python 2.7.
-
class
eventsourcing.domain.model.events.
QualnameABCMeta
[source]¶ Bases:
abc.ABCMeta
Supplies __qualname__ to object classes with this metaclass.
-
eventsourcing.domain.model.events.
resolve_attr
(obj, path)[source]¶ A recursive version of getattr for navigating dotted paths.
- Args:
- obj: An object for which we want to retrieve a nested attribute. path: A dot separated string containing zero or more attribute names.
- Returns:
- The attribute referred to by obj.a1.a2.a3…
- Raises:
- AttributeError: If there is no such attribute.
-
eventsourcing.domain.model.events.
resolve_domain_topic
(topic)[source]¶ Return domain class described by given topic.
- Args:
- topic: A string describing a domain class.
- Returns:
- A domain class.
- Raises:
- TopicResolutionError: If there is no such domain class.
eventsourcing.domain.model.snapshot
¶
-
class
eventsourcing.domain.model.snapshot.
AbstractSnapshop
[source]¶ Bases:
object
-
originator_id
¶ ID of the snapshotted entity.
-
originator_version
¶ Version of the last event applied to the entity.
-
state
¶ State of the snapshotted entity.
-
topic
¶ Path to the class of the snapshotted entity.
-
-
class
eventsourcing.domain.model.snapshot.
Snapshot
(originator_id, originator_version, topic, state)[source]¶ Bases:
eventsourcing.domain.model.events.EventWithTimestamp
,eventsourcing.domain.model.events.EventWithOriginatorVersion
,eventsourcing.domain.model.events.EventWithOriginatorID
,eventsourcing.domain.model.snapshot.AbstractSnapshop
-
state
¶ State of the snapshotted entity.
-
topic
¶ Path to the class of the snapshotted entity.
-
eventsourcing.domain.services.aes_cipher
¶
Infrastructure layer¶
eventsourcing.infrastructure.eventsourcedrepository
¶
-
class
eventsourcing.infrastructure.eventsourcedrepository.
EventSourcedRepository
(event_store, mutator=None, snapshot_strategy=None, use_cache=False, *args, **kwargs)[source]¶ Bases:
eventsourcing.domain.model.entity.AbstractEntityRepository
-
event_store
¶
-
get_entity
(entity_id, lt=None, lte=None)[source]¶ Returns entity with given ID, optionally until position.
-
mutator
(initial, event)¶ Entity mutator function. Mutates initial state by the event.
Different handlers are registered for different types of event.
-
eventsourcing.infrastructure.eventplayer
¶
-
class
eventsourcing.infrastructure.eventplayer.
EventPlayer
(event_store, mutator, page_size=None, is_short=False, snapshot_strategy=None)[source]¶ Bases:
object
Reconstitutes domain entities from domain events retrieved from the event store, optionally with snapshots.
-
get_domain_events
(entity_id, gt=None, gte=None, lt=None, lte=None, limit=None, is_ascending=True)[source]¶ Returns domain events for given entity ID.
-
get_most_recent_event
(entity_id, lt=None, lte=None)[source]¶ Returns the most recent event for the given entity ID.
-
get_snapshot
(entity_id, lt=None, lte=None)[source]¶ Returns a snapshot for given entity ID, according to the snapshot strategy.
-
replay_entity
(entity_id, gt=None, gte=None, lt=None, lte=None, limit=None, initial_state=None, query_descending=False)[source]¶ Reconstitutes requested domain entity from domain events found in event store.
-
eventsourcing.infrastructure.snapshotting
¶
-
class
eventsourcing.infrastructure.snapshotting.
AbstractSnapshotStrategy
[source]¶ Bases:
object
-
get_snapshot
(entity_id, lt=None, lte=None)[source]¶ Gets the last snapshot for entity, optionally until a particular version number.
Return type: Snapshot
-
take_snapshot
(entity_id, entity, last_event_version)[source]¶ Takes a snapshot of entity, using given ID, state and version number.
Return type: AbstractSnapshop
-
-
class
eventsourcing.infrastructure.snapshotting.
EventSourcedSnapshotStrategy
(event_store)[source]¶ Bases:
eventsourcing.infrastructure.snapshotting.AbstractSnapshotStrategy
Snapshot strategy that uses an event sourced snapshot.
eventsourcing.infrastructure.eventstore
¶
-
class
eventsourcing.infrastructure.eventstore.
AbstractEventStore
[source]¶ Bases:
object
-
class
eventsourcing.infrastructure.eventstore.
EventStore
(active_record_strategy, sequenced_item_mapper=None)[source]¶ Bases:
eventsourcing.infrastructure.eventstore.AbstractEventStore
-
get_domain_events
(originator_id, gt=None, gte=None, lt=None, lte=None, limit=None, is_ascending=True, page_size=None)[source]¶
-
iterator_class
¶ alias of
SequencedItemIterator
-
eventsourcing.infrastructure.sequenceditem
¶
-
class
eventsourcing.infrastructure.sequenceditem.
SequencedItem
(sequence_id, position, topic, data)¶ Bases:
tuple
-
data
¶ Alias for field number 3
-
position
¶ Alias for field number 1
-
sequence_id
¶ Alias for field number 0
-
topic
¶ Alias for field number 2
-
eventsourcing.infrastructure.sequenceditemmapper
¶
-
class
eventsourcing.infrastructure.sequenceditemmapper.
AbstractSequencedItemMapper
[source]¶ Bases:
object
-
class
eventsourcing.infrastructure.sequenceditemmapper.
SequencedItemMapper
(sequenced_item_class=<class 'eventsourcing.infrastructure.sequenceditem.SequencedItem'>, sequence_id_attr_name=None, position_attr_name=None, json_encoder_class=<class 'eventsourcing.infrastructure.transcoding.ObjectJSONEncoder'>, json_decoder_class=<class 'eventsourcing.infrastructure.transcoding.ObjectJSONDecoder'>, always_encrypt=False, cipher=None, other_attr_names=())[source]¶ Bases:
eventsourcing.infrastructure.sequenceditemmapper.AbstractSequencedItemMapper
Uses JSON to transcode domain events.
-
POSITION_FIELD_INDEX
= 1¶
-
SEQUENCE_ID_FIELD_INDEX
= 0¶
-
construct_item_args
(domain_event)[source]¶ Constructs attributes of a sequenced item from the given domain event.
-
deserialize_event_attrs
(event_attrs, is_encrypted)[source]¶ Deserialize event attributes from JSON, optionally with decryption.
-
eventsourcing.infrastructure.transcoding
¶
eventsourcing.infrastructure.activerecord
¶
-
class
eventsourcing.infrastructure.activerecord.
AbstractActiveRecordStrategy
(active_record_class, sequenced_item_class=<class 'eventsourcing.infrastructure.sequenceditem.SequencedItem'>)[source]¶ Bases:
object
-
all_items
()[source]¶ Returns all stored items from all sequences (possibly in chronological order, depending on database).
-
all_records
(resume=None, *arg, **kwargs)[source]¶ Returns all records in the table (possibly in chronological order, depending on database).
-
eventsourcing.infrastructure.datastore
¶
-
exception
eventsourcing.infrastructure.datastore.
DatastoreConnectionError
[source]¶ Bases:
eventsourcing.infrastructure.datastore.DatastoreError
-
class
eventsourcing.infrastructure.datastore.
DatastoreSettings
[source]¶ Bases:
object
Base class for settings for database connection used by a stored event repository.
-
exception
eventsourcing.infrastructure.datastore.
DatastoreTableError
[source]¶ Bases:
eventsourcing.infrastructure.datastore.DatastoreError
eventsourcing.infrastructure.cassandra.activerecords
¶
eventsourcing.infrastructure.cassandra.datastore
¶
eventsourcing.infrastructure.sqlalchemy.activerecords
¶
eventsourcing.infrastructure.sqlalchemy.datastore
¶
eventsourcing.infrastructure.iterators
¶
-
class
eventsourcing.infrastructure.iterators.
AbstractSequencedItemIterator
(active_record_strategy, sequence_id, page_size=None, gt=None, gte=None, lt=None, lte=None, limit=None, is_ascending=True)[source]¶ Bases:
object
-
DEFAULT_PAGE_SIZE
= 1000¶
-
-
class
eventsourcing.infrastructure.iterators.
GetEntityEventsThread
(active_record_strategy, sequence_id, gt=None, gte=None, lt=None, lte=None, page_size=None, is_ascending=True, *args, **kwargs)[source]¶ Bases:
threading.Thread
-
class
eventsourcing.infrastructure.iterators.
SequencedItemIterator
(active_record_strategy, sequence_id, page_size=None, gt=None, gte=None, lt=None, lte=None, limit=None, is_ascending=True)[source]¶ Bases:
eventsourcing.infrastructure.iterators.AbstractSequencedItemIterator
-
class
eventsourcing.infrastructure.iterators.
ThreadedSequencedItemIterator
(active_record_strategy, sequence_id, page_size=None, gt=None, gte=None, lt=None, lte=None, limit=None, is_ascending=True)[source]¶ Bases:
eventsourcing.infrastructure.iterators.AbstractSequencedItemIterator
eventsourcing.infrastructure.repositories.array
¶
-
class
eventsourcing.infrastructure.repositories.array.
ArrayRepository
(array_size=10000, *args, **kwargs)[source]¶ Bases:
eventsourcing.domain.model.array.AbstractArrayRepository
,eventsourcing.infrastructure.eventsourcedrepository.EventSourcedRepository
-
class
eventsourcing.infrastructure.repositories.array.
BigArrayRepository
(base_size=10000, *args, **kwargs)[source]¶ Bases:
eventsourcing.domain.model.array.AbstractBigArrayRepository
,eventsourcing.infrastructure.eventsourcedrepository.EventSourcedRepository
-
subrepo
¶
-
subrepo_class
¶ alias of
ArrayRepository
-
eventsourcing.infrastructure.integersequencegenerators.base
¶
-
class
eventsourcing.infrastructure.integersequencegenerators.base.
AbstractIntegerSequenceGenerator
[source]¶ Bases:
object
-
class
eventsourcing.infrastructure.integersequencegenerators.base.
SimpleIntegerSequenceGenerator
(i=0)[source]¶ Bases:
eventsourcing.infrastructure.integersequencegenerators.base.AbstractIntegerSequenceGenerator
eventsourcing.infrastructure.integersequencegenerators.redisincr
¶
Exception classes¶
-
exception
eventsourcing.exceptions.
ArrayIndexError
[source]¶ Bases:
IndexError
,eventsourcing.exceptions.EventSourcingError
Raised when appending item to an array that is full.
-
exception
eventsourcing.exceptions.
ConcurrencyError
[source]¶ Bases:
eventsourcing.exceptions.EventSourcingError
Raised when appending events at the wrong version to a versioned stream.
-
exception
eventsourcing.exceptions.
ConsistencyError
[source]¶ Bases:
eventsourcing.exceptions.EventSourcingError
Raised when applying an event stream to a versioned entity.
-
exception
eventsourcing.exceptions.
DatasourceSettingsError
[source]¶ Bases:
eventsourcing.exceptions.EventSourcingError
Raised when an error is detected in settings for a datasource.
-
exception
eventsourcing.exceptions.
EntityIsDiscarded
[source]¶ Bases:
AssertionError
Raised when access to a recently discarded entity object is attempted.
-
exception
eventsourcing.exceptions.
EntityVersionNotFound
[source]¶ Bases:
eventsourcing.exceptions.EventSourcingError
Raise when accessing an entity version that does not exist.
-
exception
eventsourcing.exceptions.
EventSourcingError
[source]¶ Bases:
Exception
Base eventsourcing exception.
-
exception
eventsourcing.exceptions.
MismatchedOriginatorError
[source]¶ Bases:
eventsourcing.exceptions.ConsistencyError
Raised when applying an event to an inappropriate object.
-
exception
eventsourcing.exceptions.
MismatchedOriginatorIDError
[source]¶ Bases:
eventsourcing.exceptions.MismatchedOriginatorError
Raised when applying an event to the wrong entity or aggregate.
-
exception
eventsourcing.exceptions.
MismatchedOriginatorVersionError
[source]¶ Bases:
eventsourcing.exceptions.MismatchedOriginatorError
Raised when applying an event to the wrong version of an entity or aggregate.
-
exception
eventsourcing.exceptions.
MutatorRequiresTypeNotInstance
[source]¶ Bases:
eventsourcing.exceptions.ConsistencyError
Raised when mutator function received a class rather than an entity.
-
exception
eventsourcing.exceptions.
ProgrammingError
[source]¶ Bases:
eventsourcing.exceptions.EventSourcingError
Raised when programming errors are encountered.
-
exception
eventsourcing.exceptions.
RepositoryKeyError
[source]¶ Bases:
KeyError
,eventsourcing.exceptions.EventSourcingError
Raised when using entity repository’s dictionary like interface to get an entity that does not exist.
-
exception
eventsourcing.exceptions.
SequencedItemError
[source]¶ Bases:
eventsourcing.exceptions.EventSourcingError
Raised when an integer sequence error occurs e.g. trying to save a version that already exists.
-
exception
eventsourcing.exceptions.
TimeSequenceError
[source]¶ Bases:
eventsourcing.exceptions.EventSourcingError
Raised when a time sequence error occurs e.g. trying to save a timestamp that already exists.
-
exception
eventsourcing.exceptions.
TopicResolutionError
[source]¶ Bases:
eventsourcing.exceptions.EventSourcingError
Raised when unable to resolve a topic to a Python class.
Example application¶
eventsourcing.example.interface.flaskapp
¶
eventsourcing.example.application
¶
-
class
eventsourcing.example.application.
ExampleApplication
(**kwargs)[source]¶ Bases:
eventsourcing.application.base.ApplicationWithPersistencePolicies
Example event sourced application with entity factory and repository.
-
eventsourcing.example.application.
close_example_application
()[source]¶ Shuts down single global instance of application.
To be called when tearing down, perhaps between tests, in order to allow a subsequent call to init_example_application().
-
eventsourcing.example.application.
construct_example_application
(**kwargs)[source]¶ Application object factory.
eventsourcing.example.domainmodel
¶
-
class
eventsourcing.example.domainmodel.
AbstractExampleRepository
(*args, **kwargs)[source]¶ Bases:
eventsourcing.domain.model.entity.AbstractEntityRepository
-
class
eventsourcing.example.domainmodel.
Example
(foo='', a='', b='', **kwargs)[source]¶ Bases:
eventsourcing.domain.model.entity.TimestampedVersionedEntity
An example event sourced domain model entity.
-
class
AttributeChanged
(timestamp=None, **kwargs)[source]¶ Bases:
eventsourcing.example.domainmodel.Event
,eventsourcing.domain.model.entity.AttributeChanged
Published when an Example is created.
-
class
Created
(timestamp=None, **kwargs)[source]¶ Bases:
eventsourcing.example.domainmodel.Event
,eventsourcing.domain.model.entity.Created
Published when an Example is created.
-
class
Discarded
(timestamp=None, **kwargs)[source]¶ Bases:
eventsourcing.example.domainmodel.Event
,eventsourcing.domain.model.entity.Discarded
Published when an Example is discarded.
-
class
Event
(timestamp=None, **kwargs)[source]¶ Bases:
eventsourcing.domain.model.entity.Event
Layer supertype.
-
class
Heartbeat
(timestamp=None, **kwargs)[source]¶ Bases:
eventsourcing.example.domainmodel.Event
,eventsourcing.domain.model.entity.Event
Published when a heartbeat in the entity occurs (see below).
-
a
¶ An example attribute.
-
b
¶ Another example attribute.
-
foo
¶ An example attribute.
-
class
eventsourcing.example.infrastructure
¶
-
class
eventsourcing.example.infrastructure.
ExampleRepository
(event_store, mutator=None, snapshot_strategy=None, use_cache=False, *args, **kwargs)[source]¶ Bases:
eventsourcing.infrastructure.eventsourcedrepository.EventSourcedRepository
,eventsourcing.example.domainmodel.AbstractExampleRepository
Event sourced repository for the Example domain model entity.
-
mutator
(initial, event)¶
-