Skip to main content

Event store for event sourced architectures.

Project description

logicblocks.event.store

Eventing infrastructure for event sourced architectures:

Table of Contents

Installation

pip install logicblocks.event.store

Example Usage

from logicblocks.event.store import EventStore, adapters
from logicblocks.event.types import NewEvent
from logicblocks.event.projection import Projector

adapter = adapters.InMemoryStorageAdapter()
store = EventStore(adapter)

stream = store.stream(category="profiles", stream="joe.bloggs")
stream.publish(
  events = [
    NewEvent(
      name="profile-created",
      payload={
        "name": "Joe Bloggs",
        "email": "joe.bloggs@example.com"
      }
    )
  ])
stream.publish(
  events = [
    NewEvent(
      name="date-of-birth-set",
      payload={
          "dob": "1992-07-10"
      }
    )
  ]
)

projector = Projector(
  handlers={
    "profile-created": lambda state, event: state.merge({
      "name": event.payload["name"],
      "email": event.payload["email"]
    }),
    "date-of-birth-set": lambda state, event: state.merge({
      "dob": event.payload["dob"]
    })
  }
)
profile = projector.project({}, stream.read())

# profile == {
#   "name": "Joe Bloggs", 
#   "email": "joe.bloggs@example.com", 
#   "dob": "1992-07-10"
# }

Features

  • Event modelling:
    • Log / category / stream based: events are grouped into logs of categories of streams.
    • Arbitrary payloads and metadata: events can have arbitrary payloads and metadata limited only by what the underlying storage backend can support.
    • Bi-temporality support: events included timestamps for both the time the event was created and the time the event was recorded in the log.
  • Event storage:
    • Immutable and append only: the event store is modelled as an append-only log of immutable events.
    • Consistency guarantees: concurrent stream updates can optionally be handled with optimistic concurrency control.
    • Write conditions: an extensible write condition system allows pre-conditions to be evaluated before publish.
    • Ordering guarantees: event writes are serialised (currently at log level) to guarantee consistent ordering at scan time.
    • Thread safety: the event store is thread safe and can be used in multithreaded applications.
  • Storage adapters:
    • Storage adapter abstraction: adapters are provided for different storage backends, currently including:
      • an in-memory implementation for testing and experimentation; and
      • a PostgreSQL backed implementation for production use.
    • Extensible to other backends: the storage adapter abstract base class is designed to be relatively easily implemented to support other storage backends.
  • Projections:
    • Reduction: event sequences can be reduced to a single value, a projection, using a projector.
    • Versioning: projections are versioned based on some attribute of the last event processed (position, sequence number, etc).
    • Storage: coming soon.
    • Snapshotting: coming soon.
  • Types:
    • Type hints: includes type hints for all public classes and functions.
    • Value types: includes serialisable value types for identifiers, events and projections.
    • Pydantic support: coming soon.
  • Testing utilities:
    • Builders: includes builders for events to simplify testing.
    • Data generators: includes random data generators for events and event attributes.
    • Storage adapter tests: includes tests for storage adapters to ensure consistency across implementations.

Development

To run the full pre-commit build:

./go

To run tests:

./go library:test:all          # all tests
./go library:test:unit         # unit tests
./go library:test:integration  # integration tests

To perform linting:

./go library:lint:check  # check linting rules are met
./go library:lint:fix    # attempt to fix linting issues

To format code:

./go library:format:check  # check code formatting
./go library:format:fix    # attempt to fix code formatting

To run type checking:

./go library:type:check  # check type hints

To build packages:

./go library:build

To see all available tasks:

./go -T

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/logicblocks/event.store.

License

Copyright © 2024 LogicBlocks Maintainers

Distributed under the terms of the MIT License.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

logicblocks_event_store-0.1.3a33.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

logicblocks_event_store-0.1.3a33-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file logicblocks_event_store-0.1.3a33.tar.gz.

File metadata

  • Download URL: logicblocks_event_store-0.1.3a33.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.2 Linux/5.15.0-1057-aws

File hashes

Hashes for logicblocks_event_store-0.1.3a33.tar.gz
Algorithm Hash digest
SHA256 03243580683c61671a35ad3722a548fd86620c5574713cb61e3c2c1902325b13
MD5 b2a3b413e128b28ac6fa54b251f49043
BLAKE2b-256 35f75c3e10c9babf6397c2cb8086428e19cdcc62d6f8e3d94f0334592a5cd918

See more details on using hashes here.

File details

Details for the file logicblocks_event_store-0.1.3a33-py3-none-any.whl.

File metadata

File hashes

Hashes for logicblocks_event_store-0.1.3a33-py3-none-any.whl
Algorithm Hash digest
SHA256 b700c811723ad22ed61176931e50974ca6d5c6fcedfb5fe5afaa0b685103ca33
MD5 1dd94b7c59cdadf99664b83712d11ceb
BLAKE2b-256 bee9c3104811b73b166cd25716394fe7190be2ec0b9106c40f201deb0c1ddd90

See more details on using hashes here.

Supported by

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