logicblocks.event.store
Example
Reference
logicblocks.event.store
logicblocks.event.store.EventStore
Bases: object
The primary interface into the store of events.
An EventStore is backed by a
StorageAdapter
which implements event storage. Typically, events are stored in an immutable
append only log, the details of which are storage implementation specific.
The event store is partitioned into streams, a sequence of events relating to the same "thing", such as an entity, a process or a state machine, and categories, a logical grouping of streams that share some characteristics.
For example, a stream might exist for each order in a commerce system, with the category of such streams being "orders".
Streams and categories are each identified by a string name. The combination of a category name and a stream name acts as an identifier for a specific stream of events.
Source code in src/logicblocks/event/store/store.py
category
category(*, category: str) -> EventCategory
Get a category of events from the store.
This method alone doesn't result in any IO, it instead returns a scoped event store for the category identified by the category name, as part of a fluent interface.
Categories implicitly exist, i.e., calling this method for a category that has never been written to will not result in an error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
category
|
str
|
The name of the category. |
required |
Returns:
| Type | Description |
|---|---|
EventCategory
|
an event store scoped to the specified category. |
Source code in src/logicblocks/event/store/store.py
stream
stream(*, category: str, stream: str) -> EventStream
Get a stream of events from the store.
This method alone doesn't result in any IO, it instead returns a scoped event store for the stream identified by the category and stream names, as part of a fluent interface.
Categories and streams implicitly exist, i.e., calling this method for a category or stream that has never been written to will not result in an error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
category
|
str
|
The name of the category of the stream. |
required |
stream
|
str
|
The name of the stream. |
required |
Returns:
| Type | Description |
|---|---|
EventStream
|
an event store scoped to the specified stream. |
Source code in src/logicblocks/event/store/store.py
logicblocks.event.store.EventCategory
Bases: object
A class for interacting with a specific category of events.
Since a category consists of zero or more streams, the category
can be narrowed to a specific stream using the stream method.
Events in the category can be read using the read method. Categories are
also iterable, supporting iter.
Attributes:
| Name | Type | Description |
|---|---|---|
adapter |
StorageAdapter
|
The storage adapter to use for interacting with the category. |
category |
str
|
the name of the category. |
Source code in src/logicblocks/event/store/store.py
__iter__
read
read() -> Sequence[StoredEvent]
Read all events from the category.
All events will be read into memory so stream iteration should be preferred in order to give storage adapters the opportunity to page events as they are read from the underlying persistence.
Source code in src/logicblocks/event/store/store.py
stream
stream(*, stream: str) -> EventStream
Get a stream of events in the category.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stream
|
str
|
The name of the stream. |
required |
Returns:
| Type | Description |
|---|---|
EventStream
|
an event store scoped to the specified stream. |
Source code in src/logicblocks/event/store/store.py
logicblocks.event.store.EventStream
Bases: object
A class for interacting with a specific stream of events.
Events can be published into the stream using the publish method, and
then entire stream can be read using the read method. Streams are also
iterable, supporting iter.
Attributes:
| Name | Type | Description |
|---|---|---|
adapter |
StorageAdapter
|
The storage adapter to use for interacting with the stream. |
category |
str
|
The name of the category of the stream. |
stream |
str
|
The name of the stream. |
Source code in src/logicblocks/event/store/store.py
__iter__
Iterate over the events in the stream from position 0 to the end.
publish
publish(
*,
events: Sequence[NewEvent],
conditions: Set[WriteCondition] = frozenset()
) -> Sequence[StoredEvent]
Publish a sequence of events into the stream.
Source code in src/logicblocks/event/store/store.py
read
read() -> Sequence[StoredEvent]
Read all events from the stream.
All events will be read into memory so stream iteration should be preferred in order to give storage adapters the opportunity to page events as they are read from the underlying persistence.
Source code in src/logicblocks/event/store/store.py
logicblocks.event.store.adapters.StorageAdapter
Bases: ABC
Source code in src/logicblocks/event/store/adapters/base.py
logicblocks.event.store.adapters.InMemoryStorageAdapter
Bases: StorageAdapter
Source code in src/logicblocks/event/store/adapters/in_memory.py
logicblocks.event.store.adapters.PostgresStorageAdapter
Bases: StorageAdapter
Source code in src/logicblocks/event/store/adapters/postgres.py
logicblocks.event.store.conditions.WriteCondition
logicblocks.event.store.conditions.PositionIsCondition
dataclass
logicblocks.event.store.conditions.EmptyStreamCondition
dataclass
logicblocks.event.store.conditions.position_is
position_is(position: int) -> WriteCondition
logicblocks.event.store.conditions.stream_is_empty
stream_is_empty() -> WriteCondition
logicblocks.event.types
logicblocks.event.types.identifier.Log
dataclass
Bases: Identifier
Source code in src/logicblocks/event/types/identifier.py
logicblocks.event.types.identifier.Category
dataclass
Bases: Identifier
Source code in src/logicblocks/event/types/identifier.py
logicblocks.event.types.identifier.Stream
dataclass
Bases: Identifier
Source code in src/logicblocks/event/types/identifier.py
logicblocks.event.types.NewEvent
dataclass
Bases: object
Source code in src/logicblocks/event/types/event.py
logicblocks.event.types.StoredEvent
dataclass
Bases: object
Source code in src/logicblocks/event/types/event.py
logicblocks.event.types.Projection
dataclass
Bases: object