Action Trees
Source Code: https://gitlab.com/roxautomation/action-trees
Summary
Action Trees is an asyncio-based Python library for managing hierarchical and asynchronous tasks. It breaks down complex tasks into simpler, independent steps that can be run sequentially or in parallel.
Functionality
ActionItemClass: Central class for representing tasks, supporting states likeINITIALIZING,RUNNING,PAUSED, andFAILED.- Task Management: Provides APIs to start, pause, resume, and cancel tasks asynchronously.
- Hierarchical Actions: Actions can have child actions, supporting structured, tree-like task management.
- Parallel Execution: Supports running child tasks concurrently using
asyncio. - State and Exception Handling: Handles task state transitions and exceptions, ensuring proper state flow.
Example
The following example illustrates a high-level task to prepare and make a cappuccino using the ActionItem class:
import asyncio
from action_trees import ActionItem
class AtomicAction(ActionItem):
"""Basic machine action with no children."""
def __init__(self, name: str, duration: float = 0.1):
super().__init__(name=name)
self._duration = duration
async def _on_run(self) -> None:
await asyncio.sleep(self._duration)
class PrepareMachineAction(ActionItem):
"""Prepare the machine."""
def __init__(self) -> None:
super().__init__(name="prepare")
self.add_child(AtomicAction(name="initialize"))
self.add_child(AtomicAction(name="clean"))
async def _on_run(self) -> None:
for child in self.children:
await child.start()
class MakeCappuccinoAction(ActionItem):
"""Make cappuccino."""
def __init__(self) -> None:
super().__init__(name="make_cappuccino")
self.add_child(AtomicAction(name="boil_water"))
self.add_child(AtomicAction(name="grind_coffee"))
async def _on_run(self) -> None:
await self.run_children_parallel()
class CappuccinoOrder(ActionItem):
"""High-level action to make a cappuccino."""
def __init__(self) -> None:
super().__init__(name="cappuccino_order")
self.add_child(PrepareMachineAction())
self.add_child(MakeCappuccinoAction())
async def _on_run(self) -> None:
for child in self.children:
await child.start()
async def main() -> None:
order = CappuccinoOrder()
await order.start()
order.display_tree()
if __name__ == "__main__":
asyncio.run(main())
This code creates a hierarchical task to prepare a machine and make a cappuccino, with some actions running sequentially and others in parallel.
More examples : see examples
State transitions
ActionItem contains a state machine with these transitions. (spec from VDA5050)
Metadata
Release files for action-trees 2.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| action_trees-2.0.1.tar.gz | 11.0 kB | Without provenance | Details for action_trees-2.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| action_trees-2.0.1-py3-none-any.whl | Python 3 | none | any | Details for action_trees-2.0.1-py3-none-any.whl |
Total release size: 19.2 kB
Release files / action_trees-2.0.1.tar.gz
| Download URL | action_trees-2.0.1.tar.gz |
|---|---|
| Size | 11.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5293a1b15e03905d9af8ce4e51948b3c64b41f3c8c2739e048a044e6f800c7e8
|
|
BLAKE2b-256 checksum How to use checksums |
82bb194e7d8441003a40f45b4b4abe61c9aa953c7d550979a29329c68bf0e6c9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.9
|
Release files / action_trees-2.0.1-py3-none-any.whl
| Download URL | action_trees-2.0.1-py3-none-any.whl |
|---|---|
| Size | 8.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
14b182f2716cfd0518e57983b807cf5304e7dcd799fe7e54b59e6d3a9e74a259
|
|
BLAKE2b-256 checksum How to use checksums |
0ff6e4fb36477424fc1ea17d8209e1ae6afbb86ca2ba7a4cf9747a40a07f5efb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.9
|
Security for action-trees 2.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.