Context and Sinks API¶
TransitionContext¶
TransitionContext
¶
Bases: dict
Context dict with typed access to internal metadata.
Internal keys (prefixed with _) are set by the engine and
orchestrator. User data lives alongside them in the same dict.
Example::
def my_guard(ctx: dict) -> bool:
tc = TransitionContext(ctx)
event = tc.event # typed access
entity = tc.entity_id # typed access
return ctx.get("valid") # still works as a normal dict
user_data
¶
Sinks¶
EventSink
¶
Bases: Protocol
Protocol for domain event sinks.
MetricSink
¶
Bases: Protocol
Protocol for metric emission sinks.
LoggingEventSink
¶
LoggingMetricSink
¶
configure_event_sink
¶
configure_event_sink(registry: ActionRegistry, sink: EventSink | None = None) -> None
Register the publish action backed by the given sink.
If sink is None, uses :class:LoggingEventSink.
Replaces the action if already registered.
Source code in src/pystator/sinks.py
configure_metric_sink
¶
configure_metric_sink(registry: ActionRegistry, sink: MetricSink | None = None) -> None
Register the emit_metric action backed by the given sink.
If sink is None, uses :class:LoggingMetricSink.
Replaces the action if already registered.
Source code in src/pystator/sinks.py
Import¶
from pystator.context import TransitionContext
from pystator.sinks import (
EventSink,
MetricSink,
LoggingEventSink,
LoggingMetricSink,
configure_event_sink,
configure_metric_sink,
)
Context key reference¶
| Key | Set by | Description |
|---|---|---|
_event |
Engine | Event object for the current transition |
_entity_id |
Orchestrator | Entity ID being processed |
_action_params |
ActionExecutor | Parameters from YAML params: for the current action |
All other keys are user-defined and come from the entity's persistent context or the event payload.
See also¶
- Context guide
- Orchestrator —
context_validatorparameter - Hooks and Metrics