{"id":3833,"library":"treelib","title":"TreeLib","description":"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.","status":"active","version":"1.8.0","language":"en","source_language":"en","source_url":"https://github.com/caesar0301/treelib","tags":["tree","data structure","hierarchy","visualization"],"install":[{"cmd":"pip install treelib","lang":"bash","label":"Install core library"},{"cmd":"pip install treelib[graphviz]","lang":"bash","label":"Install with Graphviz support"}],"dependencies":[{"reason":"Required for `Tree.to_graphviz()` and other visualization methods. The Graphviz system utility must also be installed.","package":"graphviz","optional":true}],"imports":[{"symbol":"Tree","correct":"from treelib import Tree"}],"quickstart":{"code":"from treelib import Tree\n\ntree = Tree()\ntree.create_node(\"Harry\", \"harry\")  # Root node\ntree.create_node(\"Jane\", \"jane\", parent=\"harry\")\ntree.create_node(\"Bill\", \"bill\", parent=\"harry\")\ntree.create_node(\"Diane\", \"diane\", parent=\"jane\")\ntree.create_node(\"George\", \"george\", parent=\"jane\")\ntree.create_node(\"Mark\", \"mark\", parent=\"bill\")\n\ntree.show()","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade your Python interpreter to 3.7 or higher. If you must use Python 3.6, you will need to pin treelib to a version prior to 1.8.0 (e.g., `treelib<1.8`).","message":"treelib v1.8.0 and later no longer support Python 3.6 due to its End-of-Life. Attempting to install or run treelib 1.8.0+ on Python 3.6 will result in errors.","severity":"breaking","affected_versions":">=1.8.0"},{"fix":"Refactor code to avoid the `plugin` module. For custom node behavior or mixins, use standard Python inheritance or create your own mixin classes directly without depending on `treelib.plugin.NodeMixin`.","message":"The `treelib.plugin` module, including `BaseConnector` and `NodeMixin`, was removed in v1.7.0. Code relying on these deprecated components will break.","severity":"breaking","affected_versions":">=1.7.0"},{"fix":"Install the `graphviz` Python package with `pip install treelib[graphviz]` or `pip install graphviz`. Additionally, ensure the Graphviz system utility is installed on your operating system and discoverable in your PATH.","message":"Methods like `Tree.to_graphviz()` require the `graphviz` Python package (and the Graphviz system library) to be installed separately. Without these, such methods will raise an `ImportError` or similar error.","severity":"gotcha","affected_versions":"all"},{"fix":"Always provide a unique `identifier` when calling methods like `tree.create_node()`. If you need multiple nodes to share the same display text, use different identifiers for each node while keeping their `tag` attribute the same.","message":"Each node in a `treelib.Tree` must have a unique `identifier`. Reusing identifiers for different nodes will lead to unexpected behavior, as `treelib` uses them internally for lookup and maintaining structure. This is often confused with the `tag` attribute, which can be duplicated.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}