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/Nodes
and an asyncio.Queue()
None
in the queue1) A tree can only have one root node. 2) Nodes can be run concurrently. 3) Dictionary outputs are passed as kwargs to children. All other types are passed as args. 4) UnionNodes can never be direct children of PickerNodes.
pip install -e .
to install on your environmentpytest
to run tests, add -s
flag for tests to run print
statements