Skip to main content

Event log library with Lamport clocks and systematic error tracking

Project description

spec-kitty-events

Event log library with Lamport clocks and systematic error tracking for distributed systems.

Status: Alpha (v0.4.0-alpha)

Features

  • Lamport Clocks: Establish causal ordering in distributed systems
  • Event Immutability: Events are immutable (frozen Pydantic models)
  • Conflict Detection: Detect concurrent events with is_concurrent()
  • CRDT Merge Rules: Merge grow-only sets and counters with CRDT semantics
  • State-Machine Merge: Resolve state conflicts with priority-based selection
  • Error Logging: Systematic error tracking with retention policies (Manus pattern)
  • Storage Adapters: Abstract storage interfaces (bring your own database)
  • Type Safety: Full mypy --strict compliance with py.typed marker

Installation

From PyPI (Preferred)

After the first trusted-publishing release:

pip install spec-kitty-events==<version>

From Git (Fallback Until First PyPI Release)

pip install git+https://github.com/Priivacy-ai/spec-kitty-events.git@v0.4.0-alpha

Or add to pyproject.toml:

dependencies = [
    "spec-kitty-events @ git+https://github.com/Priivacy-ai/spec-kitty-events.git@v0.4.0-alpha",
]

Development Installation

git clone https://github.com/Priivacy-ai/spec-kitty-events.git
cd spec-kitty-events
pip install -e ".[dev]"

Quick Start

Basic Event Emission

import uuid
from datetime import datetime
from spec_kitty_events import (
    Event,
    LamportClock,
    InMemoryClockStorage,
    InMemoryEventStore,
)

# Setup
clock_storage = InMemoryClockStorage()
event_store = InMemoryEventStore()
clock = LamportClock(node_id="alice", storage=clock_storage)
PROJECT_UUID = uuid.uuid4()

# Emit event
clock.tick()
event = Event(
    event_id="01ARZ3NDEKTSV4RRFFQ69G5FAV",
    event_type="WPStatusChanged",
    aggregate_id="WP001",
    timestamp=datetime.now(),
    node_id="alice",
    lamport_clock=clock.current(),
    project_uuid=PROJECT_UUID,
    project_slug="my-project",
    payload={"state": "doing"}
)
event_store.save_event(event)

Conflict Detection & Resolution

from spec_kitty_events import is_concurrent, state_machine_merge

# Assume event1/event2 are valid Event instances (including project_uuid)

# Detect concurrent events
if is_concurrent(event1, event2):
    # Resolve using state-machine merge
    priority_map = {"done": 4, "for_review": 3, "doing": 2, "planned": 1}
    resolution = state_machine_merge([event1, event2], priority_map)
    winner = resolution.merged_event

CRDT Merge

from spec_kitty_events import merge_gset, merge_counter

# Assume event1/event2/event3 are valid Event instances (including project_uuid)

# Merge grow-only set (tags)
tags = merge_gset([event1, event2, event3])

# Merge counter (deltas)
total = merge_counter([event1, event2, event3])

Architecture

Storage Adapters

The library provides abstract storage interfaces (EventStore, ClockStorage, ErrorStorage) that you can implement for your persistence layer:

  • InMemoryEventStore: For testing (not durable)
  • InMemoryClockStorage: For testing (not durable)
  • InMemoryErrorStorage: For testing (not durable)

For production, implement adapters for your database (PostgreSQL, SQLite, etc.).

API Overview

Core Models:

  • Event: Immutable event with causal metadata (lamport_clock, causation_id, project_uuid, project_slug)
  • ErrorEntry: Error log entry (timestamp, action_attempted, error_message)
  • ConflictResolution: Result of merge operation

Clocks:

  • LamportClock: Lamport logical clock with tick(), update(), current()

Conflict Detection:

  • is_concurrent(e1, e2): Detect concurrent events
  • total_order_key(event): Deterministic tiebreaker

Merge Functions:

  • merge_gset(events): CRDT merge for grow-only sets
  • merge_counter(events): CRDT merge for counters
  • state_machine_merge(events, priority_map): Priority-based state merge

Error Logging:

  • ErrorLog: Append-only error log with retention policy

Documentation

API reference documentation coming in v0.2.0. For now, refer to:

  • Type hints in source code (fully type-annotated with mypy --strict)
  • Integration tests in tests/integration/ for usage examples
  • Docstrings in src/spec_kitty_events/

Testing

Run tests with pytest:

pytest --cov --cov-report=html

Type checking:

mypy src/spec_kitty_events --strict

Requirements

  • Python 3.10+
  • Pydantic 2.x
  • python-ulid

License

No license information provided. This is a private repository.

Contributing

This is an alpha release. Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Run tests and type checking
  4. Submit a pull request

Roadmap

v0.1.1-alpha (Current):

  • ✅ Lamport clocks
  • ✅ Event immutability
  • ✅ Conflict detection
  • ✅ CRDT and state-machine merge
  • ✅ Error logging
  • ✅ Project identity (project_uuid, project_slug)

v0.2.0 (Planned):

  • Vector clocks (full happens-before ordering)
  • Persistent storage adapters (SQLite, PostgreSQL)
  • Additional CRDT types (LWW-Register, OR-Set)
  • API reference documentation (Sphinx)

Support

For issues, questions, or feature requests, please open an issue on GitHub.

Release and Publishing

This repository uses GitHub Actions trusted publishing:

  1. publish-testpypi.yml: Manual TestPyPI dry run.
  2. publish-pypi.yml: Publish on v* tags (or manual dispatch) to PyPI.

Release flow:

  1. Update project.version in pyproject.toml.
  2. Commit to main.
  3. Create and push matching tag (for example, v0.5.0 for version = "0.5.0").
  4. Approve the pypi GitHub environment (if required).
  5. Verify package on PyPI and install in a clean environment.

Generated with Spec Kitty

Project details


Download files

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

Source Distribution

spec_kitty_events-0.4.0a0.tar.gz (23.7 kB view details)

Uploaded Source

Built Distribution

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

spec_kitty_events-0.4.0a0-py3-none-any.whl (26.1 kB view details)

Uploaded Python 3

File details

Details for the file spec_kitty_events-0.4.0a0.tar.gz.

File metadata

  • Download URL: spec_kitty_events-0.4.0a0.tar.gz
  • Upload date:
  • Size: 23.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for spec_kitty_events-0.4.0a0.tar.gz
Algorithm Hash digest
SHA256 cc24c4aa754b246d9b6c74b0627afe56a4eb520e72f7c9e32302912dea978fe4
MD5 089524dfd39664aa16f23045ba2d3add
BLAKE2b-256 8c9e8a243169a41cc094a32e9f00f8ed72634deeabdb2a5408301aa527f2142c

See more details on using hashes here.

Provenance

The following attestation bundles were made for spec_kitty_events-0.4.0a0.tar.gz:

Publisher: publish-pypi.yml on Priivacy-ai/spec-kitty-events

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spec_kitty_events-0.4.0a0-py3-none-any.whl.

File metadata

File hashes

Hashes for spec_kitty_events-0.4.0a0-py3-none-any.whl
Algorithm Hash digest
SHA256 f0b28715ec704c705c2058055ae0a82c845605614d20fe7d1ebfd552121299e8
MD5 3b118645cf38664062d0be6253724663
BLAKE2b-256 3d5addf1807e5539429782244190b119d33d738725174af0e10ff2e3655079df

See more details on using hashes here.

Provenance

The following attestation bundles were made for spec_kitty_events-0.4.0a0-py3-none-any.whl:

Publisher: publish-pypi.yml on Priivacy-ai/spec-kitty-events

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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