Nutree is a Python library for tree data structures with an intuitive, yet powerful, API. It allows handling of arbitrary objects in a hierarchical structure, offering features like navigation, searching, filtering, serialization to JSON and DOT, diffing, and typed child nodes. The library is actively maintained with regular releases, currently at version 1.1.0.
pip install nutreeVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to create a tree, add nodes using string data and arbitrary objects, chain `add` calls for easy construction, and pretty print the tree structure. It also shows how to access nodes by their name.
Verify that documentation and examples explicitly reference 'nutree' (Python) or the PyPI/GitHub project for this library.
If you need graph features, install with the appropriate extra, e.g., `pip install "nutree[graph]"`.
Be aware of how `nutree` handles object references and identity within the tree structure. Use the library's methods for searching and comparing nodes to ensure expected behavior, especially when an object is part of the tree multiple times.
Install the library using pip: `pip install nutree`
Provide an explicit `data_id` when adding the object, or wrap the dictionary in `nutree.DictWrapper`. Example: `node.add({'key': 'value'}, data_id='unique_id')` or `from nutree import DictWrapper; node.add(DictWrapper({'key': 'value'}))`Import the correct core components, typically `Tree` and `Node`: `from nutree import Tree, Node`