The Python package
spec_kitty_events is a small, dependency-light Pydantic package. A consumer imports it,
validates and reduces, and stays insulated from how the CLI produced the event. Everything a
consumer needs is re-exported from the top-level package (__all__); the producer_contract
and total_order sub-surfaces are reached by their own module paths.
Install
pip install "spec-kitty-events==10.6.0"pip install "spec-kitty-events[conformance]==10.6.0" # with validation supportPin an explicit version and read versioning & compatibility before moving a major.
Emit an envelope
import uuidfrom datetime import datetime, timezonefrom spec_kitty_events import Event, WP_STATUS_CHANGED
event = Event( event_id="01ARZ3NDEKTSV4RRFFQ69G5FAV", event_type=WP_STATUS_CHANGED, # == "WPStatusChanged" aggregate_id="mission/WP01", payload={ "mission_slug": "mission-001", "wp_id": "WP01", "from_lane": "planned", "to_lane": "claimed", "actor": "ci-bot", "execution_mode": "worktree", }, timestamp=datetime.now(timezone.utc), build_id="build-2026-04-05", node_id="runner-01", lamport_clock=1, project_uuid=uuid.uuid4(), correlation_id="01ARZ3NDEKTSV4RRFFQ69G5FAV", schema_version="3.0.0",)Every field is explained in the envelope.
Validate a payload
validate_event checks one payload against its event type’s contract. Pass strict=True to
validate a whole envelope (shape plus payload), and use the dedicated strict profile for the
fail-closed journal gate.
from spec_kitty_events.conformance import validate_event
result = validate_event(event.payload, "WPStatusChanged")assert result.valid
# validate a full envelope dictresult = validate_event(event.to_dict(), "WPStatusChanged", strict=True)assert result.validGate an envelope fail-closed
The strict profile is the deterministic, fail-closed gate for the durable journal and
TeamSpace ingress. It is intentionally separate from validate_event.
from spec_kitty_events.strict import validate_strict_envelope, STRICT_PROFILE_ID
errors = validate_strict_envelope(event.to_dict())assert not errors # empty list == admittedassert STRICT_PROFILE_ID == "journal/v1"See the strict profile for what it enforces.
Reduce a stream into state
Each family ships a pure reducer that folds an ordered list of Events into a frozen state
snapshot. Reducers order, de-duplicate and fold deterministically — see
ordering and reduction.
from spec_kitty_events import reduce_status_events
state = reduce_status_events(events) # -> ReducedStatuslane = state.wp_states["WP01"].lane| Reducer | Reduced state | Family |
|---|---|---|
reduce_status_events | ReducedStatus (per-WP WPState) | work & status |
reduce_lifecycle_events | ReducedMissionState | mission lifecycle |
reduce_mission_next_events | ReducedMissionRunState | mission lifecycle |
reduce_mission_audit_events | ReducedMissionAuditState | review, audit & decisions |
reduce_decision_point_events | ReducedDecisionPointState | review, audit & decisions |
reduce_mission_dossier | MissionDossierState | review, audit & decisions |
reduce_collaboration_events | ReducedCollaborationState | collaboration |
reduce_connector_events | ReducedConnectorState | runtime observation |
reduce_glossary_events | ReducedGlossaryState | semantics & analytics |
reduce_decision_point_records | dict of ReducedDecisionPointState by decision | review, audit & decisions |
The status-diary reducer that reads the CLI’s on-disk status.events.jsonl is the standalone
spec_kitty_events.diary module (parse_diary, reduce, State); it is the same fold the
Team Kitty dossier runs. See work & status.
Load JSON Schemas and fixtures
Pre-generated JSON Schemas (Draft 2020-12) are generated from the canonical Pydantic models and shipped in the package:
from spec_kitty_events.schemas import load_schema
schema = load_schema("mission_audit_requested_payload")The packaged conformance corpus (valid/invalid payloads, replay streams, golden reducer outputs) is the authoritative compatibility surface. Run the drift and conformance gates:
python -m spec_kitty_events.schemas.generate --checkuv run pytest --pyargs spec_kitty_events.conformance -vWrite to a local ledger
spec_kitty_events.persistence.append_event(event, path) (10.8.0) validates an Event, a
flat dict or a registered payload model fail-closed, then appends one pinned-byte JSONL line.
Its refusals (LedgerAppendError, LedgerValidationError, LedgerTornTailError) are
exported from spec_kitty_events.persistence only, deliberately not from the package
root. See Ledger write contract.
from spec_kitty_events.persistence import LedgerAppendError, append_eventGlossary names and ordering
Glossary payloads are imported from the flat module, with the *Payload names, for example
from spec_kitty_events.glossary import TermCandidateObservedPayload, StepCheckpointedPayload.
There is no glossary.events submodule. spec_kitty_events.ordering.canonical_order_key(event)
is the one ordering key: (1 if clocked else 0, clock or 0, timestamp, event_id), so
unclocked envelopes come first, ordered by (timestamp, event_id), then clocked ones. This
is the same rule as ADR 0001’s total order (spec_kitty_events.total_order.order_key).
LOCAL_ONLY_EVENT_TYPES (removed)
Removed in 11.0.0. The local-only classification was retired in 10.8.0; every modelled
event type is canonical and append_event never consulted the set. Delete the import.
See also
- The envelope · The strict profile · Lane vocabulary
- Event families — the payload models each reducer folds.