eventbus.domain package

Submodules

eventbus.domain.aggregate module

class eventbus.domain.aggregate.BaseAggregateRoot(**kwargs)[source]

Bases: eventbus.domain.entity.TimestampedVersionedEntity, typing.Generic

Root entity for an aggregate in a domain driven design.

class AttributeChanged(originator_version: int, **kwargs)[source]

Bases: eventbus.domain.aggregate.Event, eventbus.domain.entity.AttributeChanged

Triggered when an aggregate root attribute is changed.

class Created(originator_version: int = 0, *args, **kwargs)[source]

Bases: eventbus.domain.entity.Created, eventbus.domain.aggregate.Event

Triggered when an aggregate root is created.

class Discarded(originator_version: int, **kwargs)[source]

Bases: eventbus.domain.aggregate.Event, eventbus.domain.entity.Discarded

Triggered when an aggregate root is discarded.

class Event(originator_version: int, **kwargs)[source]

Bases: eventbus.domain.entity.Event

Supertype for base aggregate root events.

eventbus.domain.decorators module

eventbus.domain.decorators.subclassevents(cls: type) → type[source]

Decorator that avoids “boilerplate” subclassing of domain events.

For example, with this decorator you can do this:

@subclassevents
class Example(AggregateRoot):
    class SomethingHappened(DomainEvent): pass

rather than this:

class Example(AggregateRoot):
    class Event(AggregateRoot.Event): pass
    class Created(Event, AggregateRoot.Created): pass
    class AttributeChanged(Event, AggregateRoot.AttributeChanged): pass
    class Discarded(Event, AggregateRoot.Discarded): pass
    class SomethingHappened(Event): pass

You can apply this to a tree of domain event classes by defining the base class with attribute ‘subclassevents = True’.

eventbus.domain.entity module

class eventbus.domain.entity.DomainEntity(id: uuid.UUID, discarded: bool = False, **kwargs)[source]

Bases: eventbus.domain.whitehead.EnduringObject

Supertype for domain model entity.

class AttributeChanged(originator_id: uuid.UUID, **kwargs)[source]

Bases: eventbus.domain.entity.Event, eventbus.domain.events.AttributeChangedEvent

Triggered when a named attribute is assigned a new value.

class Created(originator_topic: str, **kwargs)[source]

Bases: eventbus.domain.events.CreatedEvent, eventbus.domain.entity.Event

Triggered when an entity is created.

originator_topic

Topic (a string) representing the class of the originating domain entity.

Return type:str
class Discarded(originator_id: uuid.UUID, **kwargs)[source]

Bases: eventbus.domain.events.DiscardedEvent, eventbus.domain.entity.Event

Triggered when a DomainEntity is discarded.

class Event(originator_id: uuid.UUID, **kwargs)[source]

Bases: eventbus.domain.events.EventWithOriginatorID

Supertype for events of domain model entities.

id

The immutable ID of the domain entity.

This value is set using the originator_id of the “created” event constructed by __create__().

An entity ID allows an instance to be referenced and distinguished from others, even though its state may change over time.

This attribute has the normal “public” format for a Python object attribute name, because by definition all domain entities have an ID.

class eventbus.domain.entity.MetaDomainEntity(name: str, *args, **kwargs)[source]

Bases: abc.ABCMeta

class eventbus.domain.entity.TimestampedEntity(__created_on__: datetime.datetime, __updated_on__: datetime.datetime, **kwargs)[source]

Bases: eventbus.domain.entity.DomainEntity

class AttributeChanged(originator_id: uuid.UUID, **kwargs)[source]

Bases: eventbus.domain.entity.Event, eventbus.domain.entity.AttributeChanged

Published when a TimestampedEntity is changed.

class Created(originator_topic: str, **kwargs)[source]

Bases: eventbus.domain.entity.Created, eventbus.domain.entity.Event

Published when a TimestampedEntity is created.

class Discarded(originator_id: uuid.UUID, **kwargs)[source]

Bases: eventbus.domain.entity.Event, eventbus.domain.entity.Discarded

Published when a TimestampedEntity is discarded.

class Event(originator_id: uuid.UUID, **kwargs)[source]

Bases: eventbus.domain.entity.Event, eventbus.domain.events.EventWithTimestamp

Supertype for events of timestamped entities.

class eventbus.domain.entity.TimestampedVersionedEntity(__created_on__: datetime.datetime, __updated_on__: datetime.datetime, **kwargs)[source]

Bases: eventbus.domain.entity.TimestampedEntity, eventbus.domain.entity.VersionedEntity

class AttributeChanged(originator_version: int, **kwargs)[source]

Bases: eventbus.domain.entity.Event, eventbus.domain.entity.AttributeChanged, eventbus.domain.entity.AttributeChanged

Published when a TimestampedVersionedEntity is created.

class Created(originator_version: int = 0, *args, **kwargs)[source]

Bases: eventbus.domain.entity.Created, eventbus.domain.entity.Created, eventbus.domain.entity.Event

Published when a TimestampedVersionedEntity is created.

class Discarded(originator_version: int, **kwargs)[source]

Bases: eventbus.domain.entity.Event, eventbus.domain.entity.Discarded, eventbus.domain.entity.Discarded

Published when a TimestampedVersionedEntity is discarded.

class Event(originator_version: int, **kwargs)[source]

Bases: eventbus.domain.entity.Event, eventbus.domain.entity.Event

Supertype for events of timestamped, versioned entities.

class eventbus.domain.entity.VersionedEntity(__version__: int, **kwargs)[source]

Bases: eventbus.domain.entity.DomainEntity

class AttributeChanged(originator_version: int, **kwargs)[source]

Bases: eventbus.domain.entity.Event, eventbus.domain.entity.AttributeChanged

Published when a VersionedEntity is changed.

class Created(originator_version: int = 0, *args, **kwargs)[source]

Bases: eventbus.domain.entity.Created, eventbus.domain.entity.Event

Published when a VersionedEntity is created.

class Discarded(originator_version: int, **kwargs)[source]

Bases: eventbus.domain.entity.Event, eventbus.domain.entity.Discarded

Published when a VersionedEntity is discarded.

class Event(originator_version: int, **kwargs)[source]

Bases: eventbus.domain.events.EventWithOriginatorVersion, eventbus.domain.entity.Event

Supertype for events of versioned entities.

eventbus.domain.eventbus module

class eventbus.domain.eventbus.AbstractEventHandler[source]

Bases: abc.ABC

ASTERISK = '*'
event_type
filter(events: List[TEvent])[source]
handler(events: List[TEvent])[source]
predicate(events) → bool[source]

eventbus.domain.events module

class eventbus.domain.events.AttributeChangedEvent(**kwargs)[source]

Bases: eventbus.domain.events.DomainEvent

Happens when the value of an attribute changes.

name
value
class eventbus.domain.events.CreatedEvent(**kwargs)[source]

Bases: eventbus.domain.events.DomainEvent

Happens when something is created.

class eventbus.domain.events.DiscardedEvent(**kwargs)[source]

Bases: eventbus.domain.events.DomainEvent

Happens when something is discarded.

class eventbus.domain.events.DomainEvent(**kwargs)[source]

Bases: eventbus.domain.whitehead.ActualOccasion, typing.Generic

Base class for domain model events.

Implements methods to make instances read-only, comparable for equality in Python, and have recognisable representations.Custom To make domain events hashable, this class also implements a method to create a cryptographic hash of the state of the event.

mutate(obj: TEntity) → None[source]

Updates (“mutates”) given ‘obj’.

Intended to be overridden by subclasses, as the most concise way of coding a default projection of the event (for example into the state of a domain entity).

The advantage of implementing a default projection using this method rather than __mutate__ is that you don’t need to call super or return a value.

Parameters:obj – domain entity to be mutated
class eventbus.domain.events.EventWithOriginatorID(originator_id: uuid.UUID, **kwargs)[source]

Bases: eventbus.domain.events.DomainEvent

For events that have an originator ID.

originator_id

Originator ID is the identity of the object that originated this event.

Returns:A UUID representing the identity of the originator.
Return type:UUID
class eventbus.domain.events.EventWithOriginatorVersion(originator_version: int, **kwargs)[source]

Bases: eventbus.domain.events.DomainEvent

For events that have an originator version number.

originator_version

Originator version is the version of the object that originated this event.

Returns:A integer representing the version of the originator.
class eventbus.domain.events.EventWithTimestamp(timestamp: Optional[datetime.datetime] = None, **kwargs)[source]

Bases: eventbus.domain.events.DomainEvent

For events that have a timestamp value.

timestamp

A UNIX timestamp as a datetime object.

eventbus.domain.exceptions module

exception eventbus.domain.exceptions.ConsistencyError[source]

Bases: eventbus.domain.exceptions.DomainEventError

Raised when applying an event stream to a versioned entity.

exception eventbus.domain.exceptions.DomainEventError[source]

Bases: Exception

Base eventsourcing exception.

exception eventbus.domain.exceptions.EncoderTypeError[source]

Bases: TypeError

exception eventbus.domain.exceptions.EntityIsDiscarded[source]

Bases: AssertionError

Raised when access to a recently discarded entity object is attempted.

exception eventbus.domain.exceptions.MismatchedOriginatorError[source]

Bases: eventbus.domain.exceptions.ConsistencyError

Raised when applying an event to an inappropriate object.

exception eventbus.domain.exceptions.OriginatorIDError[source]

Bases: eventbus.domain.exceptions.MismatchedOriginatorError

Raised when applying an event to the wrong entity or aggregate.

exception eventbus.domain.exceptions.OriginatorVersionError[source]

Bases: eventbus.domain.exceptions.MismatchedOriginatorError

Raised when applying an event to the wrong version of an entity or aggregate.

exception eventbus.domain.exceptions.TopicResolutionError[source]

Bases: eventbus.domain.exceptions.DomainEventError

Raised when unable to resolve a topic to a Python class.

eventbus.domain.whitehead module

class eventbus.domain.whitehead.ActualOccasion[source]

Bases: eventbus.domain.whitehead.Event

“‘Actual entities’ – also termed ‘actual occasions’ – are the final real things of which the world is made up. There is no going behind actual entities to find anything more real.”

“Just as ‘potentiality for process’ is the meaning of the more general term ‘entity’ or ‘thing’; so ‘decision’ is the additional meaning imported by the word ‘actual’ into the phrase ‘actual entity’. ‘Actuality’ is the decision amid ‘potentiality’. It represents stubborn fact which cannot be evaded.”

“Actual entities perish, but do not change; they are what they are.”

Alfred North Whitehead, 1929

class eventbus.domain.whitehead.EnduringObject[source]

Bases: eventbus.domain.whitehead.Event

“The notions of ‘social order’ and of ‘personal order’ cannot be omitted from this preliminary sketch. A ‘society’ in the sense in which that term is here used, is a nexus with social order; and an ‘enduring object’ or ‘enduring creature’ is a society whose social order has taken the special form of ‘personal order.’”

“A nexus enjoys ‘personal order’ when (a) it is a ‘society’ and when the genetic relatedness of its members orders these members ‘serially’.”

Alfred North Whitehead, 1929

class eventbus.domain.whitehead.Event[source]

Bases: object

“I shall use the term ‘event’ in the more general sense of a nexus of actual occasions, inter-related in some determinate fashion in one extensive quantum. An actual occasion is the limiting type of an event with only one member.”

Alfred North Whitehead, 1929

Module contents