A library for building runnable asynchronous trees
Project description
What
A simple library for building runnable tree structures. Trees are built using Nodes, which contain code to be run.
Use:
# Declare your nodes
root_node = Node(...)
child_node1 = Node(...)
child_node2 = Node(...)
grandchild_node1 = Node(...)
# Set the layout
nodes = {
root_node: {
child_node1: None,
child_node2: [grandchild_node1],
}
}
# Use the '|' operator to connect the nodes
executor = AsyncTreeExecutor(logger=logger)
tree = executor | nodes
result = await tree.run()
Powered by asyncio
& instructor
!
asyncio
: https://docs.python.org/3/library/asyncio.htmlinstructor
: https://python.useinstructor.com/
How
- You have a tree of interconected
Nodes
and anasyncio.Queue()
- Upon each Node's execution, it queues its children up next
- Workers stop when they find a
None
in the queue - ⚠️ Be careful with UnionNodes, they can cause invisible deadlocks. ⚠️
Axioms
- A tree can only have one root node.
- Nodes can be run concurrently.
- Dictionary outputs are passed as kwargs to children. All other types are passed as args.
- UnionNodes can never be direct children of PickerNodes.
Zen
- Follow established names: a Node is a Node, not a "Leaf".
- Syntax sugar is sweet in moderation.
- Give the programmer granular control.
During Development
pip install -e .
to install on your environmentpytest
to run tests, add-s
flag for tests to runprint
statements
Extras
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
grafo-0.1.4.tar.gz
(13.6 kB
view hashes)
Built Distribution
grafo-0.1.4-py3-none-any.whl
(11.0 kB
view hashes)