Bigtree
Bigtree is a Python library that provides a performant, flexible, and intuitive implementation for tree data structures. It supports various tree types (Tree, Binary Tree, Directed Acyclic Graph) and offers a rich API for traversal, search, modification, and export. It integrates seamlessly with Python lists, dictionaries, pandas, and polars DataFrames, making it suitable for a wide range of hierarchical data workflows. The library is actively maintained with frequent releases, currently at version 1.4.0.
Warnings
- gotcha Node names cannot contain the separator symbol (default '/'). While it won't immediately raise an error, it can lead to issues with certain functions like tree export/import or path-based operations.
- gotcha The `get_attr` method, especially for `BaseNode`/`DAGNode`, was enhanced in v1.3.0 to support chained and nested attributes and to return a default value instead of raising an error if the attribute is not found. Code relying on an `AttributeError` for missing attributes or expecting simple attribute access might need adjustments.
- breaking Version 1.0.0 and subsequent releases (e.g., 1.0.2) introduced significant API improvements and a plugin architecture. While core usage remains largely compatible, users with highly customized node types or those directly interacting with internal components might need to refactor their code to align with the new plugin-based structure.
Install
-
pip install bigtree -
pip install 'bigtree[pandas,polars,rich]'
Imports
- Node
from bigtree import Node
- print_tree
from bigtree import print_tree
- DAGNode
from bigtree import DAGNode
- BinaryNode
from bigtree import BinaryNode
Quickstart
from bigtree import Node, print_tree
# Create nodes
root = Node("a")
b = Node("b", parent=root)
c = Node("c", parent=root)
d = Node("d", parent=b)
e = Node("e", parent=b)
f = Node("f", parent=c)
# Print the tree
print_tree(root)
# Access node attributes
print(f"Node 'd' is a leaf: {d.is_leaf}")
print(f"Root node name: {root.node_name}")