Actions¶
Register and execute actions (on_enter, on_exit, transition actions).
ActionRegistry
¶
Registry for action functions (sync and async).
Example
registry = ActionRegistry() registry.register("notify", lambda ctx: print("notified")) registry.execute("notify", {"user": "alice"})
Source code in src/pystator/actions.py
register
¶
Register an action function. Thread-safe.
Source code in src/pystator/actions.py
unregister
¶
Unregister an action function. Thread-safe.
Source code in src/pystator/actions.py
get
¶
Look up a registered action callable by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The registered action name. |
required |
Returns:
| Type | Description |
|---|---|
AnyActionFunc
|
The action callable. |
Raises:
| Type | Description |
|---|---|
ActionNotFoundError
|
If no action is registered under name. |
Source code in src/pystator/actions.py
has
¶
get_metadata
¶
is_async
¶
execute
¶
Execute a single named action synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Registered action name. |
required |
context
|
dict[str, Any]
|
Context dict passed to the action callable. |
required |
raise_on_error
|
bool
|
If True, re-raise exceptions instead of wrapping. |
False
|
Returns:
| Type | Description |
|---|---|
ActionResult
|
ActionResult indicating success or failure. |
Source code in src/pystator/actions.py
execute_all
¶
execute_all(
actions: tuple[str, ...] | list[str],
context: dict[str, Any],
stop_on_error: bool = False,
) -> list[ActionResult]
Execute multiple actions with stop-on-error control.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
actions
|
tuple[str, ...] | list[str]
|
Sequence of action names to execute. |
required |
context
|
dict[str, Any]
|
Context dict passed to each action. |
required |
stop_on_error
|
bool
|
If True, halt after the first failure. |
False
|
Returns:
| Type | Description |
|---|---|
list[ActionResult]
|
List of ActionResult in execution order. |
Source code in src/pystator/actions.py
async_execute
async
¶
Execute a single named action asynchronously.
Falls back to synchronous execution if the action is not async.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Registered action name. |
required |
context
|
dict[str, Any]
|
Context dict passed to the action callable. |
required |
raise_on_error
|
bool
|
If True, re-raise exceptions instead of wrapping. |
False
|
Returns:
| Type | Description |
|---|---|
ActionResult
|
ActionResult indicating success or failure. |
Source code in src/pystator/actions.py
async_execute_all
async
¶
async_execute_all(
actions: tuple[str, ...] | list[str],
context: dict[str, Any],
stop_on_error: bool = False,
) -> list[ActionResult]
Execute multiple actions asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
actions
|
tuple[str, ...] | list[str]
|
Sequence of action names to execute. |
required |
context
|
dict[str, Any]
|
Context dict passed to each action. |
required |
stop_on_error
|
bool
|
If True, halt after the first failure. |
False
|
Returns:
| Type | Description |
|---|---|
list[ActionResult]
|
List of ActionResult in execution order. |
Source code in src/pystator/actions.py
list_actions
¶
clear
¶
decorator
¶
decorator(
name: str | None = None,
metadata: dict[str, Any] | None = None,
) -> Callable[[AnyActionFunc], AnyActionFunc]
Decorator to register an action function.
Example
@registry.decorator() ... def notify_user(ctx: dict) -> None: ... send_email(ctx["user_email"], "Order updated")
Source code in src/pystator/actions.py
ActionExecutor
¶
ActionExecutor(
registry: ActionRegistry,
stop_on_error: bool = False,
log_execution: bool = True,
default_mode: ExecutionMode = ExecutionMode.SEQUENTIAL,
strict: bool = False,
)
Executes actions from transition results.
Supports sequential, parallel, and phased execution modes.
Example
executor = ActionExecutor(action_registry) execution = executor.execute(transition_result, context)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
registry
|
ActionRegistry
|
ActionRegistry containing the action callables. |
required |
stop_on_error
|
bool
|
If True, halt batch execution on first failure. |
False
|
log_execution
|
bool
|
If True, log action skips and errors. |
True
|
default_mode
|
ExecutionMode
|
Default execution mode for batches. |
SEQUENTIAL
|
strict
|
bool
|
If True, raise on missing actions instead of skipping. |
False
|
Source code in src/pystator/actions.py
execute
¶
Execute all actions from a transition result sequentially.
Source code in src/pystator/actions.py
execute_specific
¶
execute_specific(
action_names: list[str] | tuple[str, ...],
context: dict[str, Any],
) -> list[ActionResult]
Execute specific actions by name sequentially.
Source code in src/pystator/actions.py
validate_actions_exist
¶
Return list of action names that are not registered.
Source code in src/pystator/actions.py
execute_action_spec
¶
Execute a single ActionSpec synchronously.
Source code in src/pystator/actions.py
execute_action_specs
¶
execute_action_specs(
actions: tuple[ActionSpec, ...] | list[ActionSpec],
context: dict[str, Any],
) -> list[ActionResult]
Execute multiple ActionSpecs sequentially.
Source code in src/pystator/actions.py
async_execute
async
¶
Execute all actions asynchronously in sequential order.
Source code in src/pystator/actions.py
async_execute_parallel
async
¶
async_execute_parallel(
transition_result: TransitionResult,
context: dict[str, Any],
) -> ExecutionResult
Execute all actions concurrently using asyncio.gather.
Source code in src/pystator/actions.py
async_execute_phased
async
¶
async_execute_phased(
transition_result: TransitionResult,
context: dict[str, Any],
) -> ExecutionResult
Execute actions in phases: exit -> transition -> enter (each parallel).
Source code in src/pystator/actions.py
async_execute_with_mode
async
¶
async_execute_with_mode(
transition_result: TransitionResult,
context: dict[str, Any],
mode: ExecutionMode = ExecutionMode.SEQUENTIAL,
) -> ExecutionResult
Execute with explicit mode (sequential, parallel, or phased).
Source code in src/pystator/actions.py
async_execute_specific_parallel
async
¶
async_execute_specific_parallel(
action_names: list[str] | tuple[str, ...],
context: dict[str, Any],
) -> list[ActionResult]
Execute specific actions in parallel by name.
Source code in src/pystator/actions.py
async_execute_action_spec
async
¶
Async execute a single ActionSpec.
Source code in src/pystator/actions.py
async_execute_action_specs_parallel
async
¶
async_execute_action_specs_parallel(
actions: tuple[ActionSpec, ...] | list[ActionSpec],
context: dict[str, Any],
) -> list[ActionResult]
Async execute multiple ActionSpecs in parallel.