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 eventstotal_order_key(event): Deterministic tiebreaker
Merge Functions:
merge_gset(events): CRDT merge for grow-only setsmerge_counter(events): CRDT merge for countersstate_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:
- Fork the repository
- Create a feature branch
- Run tests and type checking
- 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:
publish-testpypi.yml: Manual TestPyPI dry run.publish-pypi.yml: Publish onv*tags (or manual dispatch) to PyPI.
Release flow:
- Update
project.versioninpyproject.toml. - Commit to
main. - Create and push matching tag (for example,
v0.5.0forversion = "0.5.0"). - Approve the
pypiGitHub environment (if required). - Verify package on PyPI and install in a clean environment.
Generated with Spec Kitty
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spec_kitty_events-0.4.1.tar.gz.
File metadata
- Download URL: spec_kitty_events-0.4.1.tar.gz
- Upload date:
- Size: 25.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba9bdae8d0b9a667fb72fcee46ee7e0a36767124d0aea87f41dc5873bc52413d
|
|
| MD5 |
a8d546905010b1f923d24a2b3f0f8029
|
|
| BLAKE2b-256 |
c8e46f2dfd9316a9f300f78f7cc1f73f8dfa20cfffc3775161763e8dfeabf544
|
Provenance
The following attestation bundles were made for spec_kitty_events-0.4.1.tar.gz:
Publisher:
publish-pypi.yml on Priivacy-ai/spec-kitty-events
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spec_kitty_events-0.4.1.tar.gz -
Subject digest:
ba9bdae8d0b9a667fb72fcee46ee7e0a36767124d0aea87f41dc5873bc52413d - Sigstore transparency entry: 1025003148
- Sigstore integration time:
-
Permalink:
Priivacy-ai/spec-kitty-events@5e51f80142355d27eaeb6df9113332e02d5100a1 -
Branch / Tag:
refs/tags/v0.4.1 - Owner: https://github.com/Priivacy-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@5e51f80142355d27eaeb6df9113332e02d5100a1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file spec_kitty_events-0.4.1-py3-none-any.whl.
File metadata
- Download URL: spec_kitty_events-0.4.1-py3-none-any.whl
- Upload date:
- Size: 27.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
97a0a56214cb96a5dd307f5db8389516ca41b17984bfcadd22d0883550f686d6
|
|
| MD5 |
e8f168d2572626ab2998afdca4a7a909
|
|
| BLAKE2b-256 |
1d98d9d16b8edc0051520e706fdc11f546e8a75a4e012b9b9990e7fad4cb095d
|
Provenance
The following attestation bundles were made for spec_kitty_events-0.4.1-py3-none-any.whl:
Publisher:
publish-pypi.yml on Priivacy-ai/spec-kitty-events
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spec_kitty_events-0.4.1-py3-none-any.whl -
Subject digest:
97a0a56214cb96a5dd307f5db8389516ca41b17984bfcadd22d0883550f686d6 - Sigstore transparency entry: 1025003208
- Sigstore integration time:
-
Permalink:
Priivacy-ai/spec-kitty-events@5e51f80142355d27eaeb6df9113332e02d5100a1 -
Branch / Tag:
refs/tags/v0.4.1 - Owner: https://github.com/Priivacy-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@5e51f80142355d27eaeb6df9113332e02d5100a1 -
Trigger Event:
push
-
Statement type: