python_outbox_core.events¶
Base interface for outbox events.
Best Practices Applied: 1. ABC for contract enforcement 2. Pydantic for validation & serialization 3. Standard event metadata (CloudEvents-inspired) 4. Type safety with generics 5. Immutability encouraged (frozen=True optional)
References: - CloudEvents spec: https://cloudevents.io/ - Domain Event pattern: https://martinfowler.com/eaaDev/DomainEvent.html
Classes¶
Abstract base for all outbox events. |
Module Contents¶
- class python_outbox_core.events.IOutboxEvent¶
Bases:
pydantic.BaseModel,abc.ABCAbstract base for all outbox events.
Enforces event metadata standards and serialization contract. Projects extend this for domain-specific events.
Metadata fields follow CloudEvents specification for interoperability.
- event_id: uuid.UUID¶
Unique identifier for this event (idempotency key).
- event_type: str¶
Event type in reverse-DNS format (e.g. ‘com.gridflow.invite.created’).
- aggregate_id: str¶
ID of the aggregate root that produced this event.
- occurred_at: datetime.datetime¶
When the event occurred (domain time, not system time).
- source: str¶
Service/application that produced this event (e.g. ‘user-service’).
- data_version: str = '1.0'¶
Event schema version for evolution/compatibility (semver recommended).
- correlation_id: uuid.UUID | None = None¶
Links related events across service boundaries.
- causation_id: uuid.UUID | None = None¶
ID of the event/command that caused this event.
- abstract to_message() dict[str, Any]¶
Serialize event to Kafka message format.
Must return a JSON-serializable dict for publishing. Override to customize serialization (e.g., omit fields, transform data).
- get_partition_key() str¶
Return partition key for Kafka routing.
Default: aggregate_id (natural partition key). Override for custom routing (e.g., user_id, tenant_id).
Best practice: Use 3-10 topics with partition keys, NOT hundreds of topics per entity.
- Returns:
Partition key string for Kafka producer