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.
Re-registration replaces the existing action (allows overriding builtins).
If the function accepts keyword arguments beyond ctx, parameters
from the action spec are passed as **kwargs instead of injected
into the context dict.
Source code in src/pystator/actions.py
accepts_kwargs
¶
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")