Node#
- class sycamore.plan_nodes.Node(children: list[Node | None], materialize: dict = {}, parallelism: int | None = None, **resource_args)[source]#
A Node is the abstract base unit of a Sycamore Transform, which allows DocSets to transform themselves into end results. Sycamore processes this as a directed tree graph, which allows transforms to be linked to each other and then implemented
- finalize() None [source]#
Override this method to run something at the end of execution after all documents have been returned.
- prepare() Callable | None [source]#
Override this method to run something at the beginning of execution after rules have been applied. The entire tree will be traversed in before mode and then any returned callables will be called in the order they were returned. Each callable can return another callable.
- traverse(obj: NodeTraverse | None = None, before: Callable[[Node], Node] | None = None, visit: Callable[[Node], None] | None = None, after: Callable[[Node], Node] | None = None) Node [source]#
Traverse the node tree, functions will be converted to an object. See NodeTraverse for the semantics.
- class sycamore.plan_nodes.NodeTraverse(before: Callable[[Node], Node] | None = None, visit: Callable[[Node], None] | None = None, after: Callable[[Node], Node] | None = None)[source]#
NodeTraverse allows for complicated traversals
For simple use cases, call node.traverse({before,visit,after}=fn)
before is called before traversing children.
after is called after traversing children.
visit is called over each node in an unspecified order, and is easier to use since the function returns nothing.
once is called one time at the very start, and enables multi-pass transforms.
- sycamore.plan_nodes.print_plan(node: ~sycamore.plan_nodes.Node, stream=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>) None [source]#
Utility function for printing plans.
Prints the node and all its children. Indentation is used to indicate the parent-child relation, e.g.
- RootNode
- InternalNode1
LeafNode1
- InternalNode2
LeafNode2