TreeLib

1.8.0 · active · verified Sat Apr 11

TreeLib provides a Python implementation for creating, manipulating, and visualizing tree data structures. It allows users to build hierarchical data, traverse nodes, and render trees to various outputs like console text or Graphviz. It is actively maintained with a moderate release cadence, with the current version being 1.8.0.

Warnings

Install

Imports

Quickstart

This example demonstrates creating a new tree, adding several nodes with unique identifiers and parent-child relationships, and then printing the tree to the console.

from treelib import Tree

tree = Tree()
tree.create_node("Harry", "harry")  # Root node
tree.create_node("Jane", "jane", parent="harry")
tree.create_node("Bill", "bill", parent="harry")
tree.create_node("Diane", "diane", parent="jane")
tree.create_node("George", "george", parent="jane")
tree.create_node("Mark", "mark", parent="bill")

tree.show()

view raw JSON →