skillfed

treelib

A Python implementation of tree structure.

treelib v1.8.0 1.8M downloads/30d#3,552 on PyPI870
Permissive license Apache-2.0 Active released

What it is and what it does

Treelib is a Python library that implements a tree data structure—a hierarchical collection of nodes where each node can have parent-child relationships. It abstracts away the complexity of manually managing node pointers and tree traversal, letting you focus on building and working with tree-shaped data. The library is designed for simplicity: you create nodes, link them together, and the tree handles the structure. It includes built-in display capabilities, likely for console output, making it useful for visualizing hierarchies during development or in terminal-based tools.

The package depends only on six, a Python 2/3 compatibility layer, keeping its footprint minimal. It supports Python 3.7 through 3.13 and is classified as production-stable. With over 1.7 million monthly downloads and a position in the top 5000 PyPI packages, it has established itself as a go-to choice for developers needing a lightweight, no-fuss tree implementation without the overhead of more specialized graph libraries.

Use it for:

  • Build file system or directory tree representations for explorers or navigation tools.
  • Create organizational hierarchies or family trees for display and traversal.
  • Implement parse trees or abstract syntax trees for simple language processing tasks.
  • Display menu structures or nested configuration hierarchies in CLI applications.
  • Model hierarchical data like category taxonomies or DOM-like document structures.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Provides a simple tree data structure implementation for Python, allowing you to create, manipulate, and display hierarchical node-based trees.

Yes. Treelib is a mature, actively maintained library with no known vulnerabilities, minimal dependencies, and broad Python version support. It solves a straightforward problem—simple tree data structures—without bloat. Install it if you need basic tree operations and console visualization; skip it if you need advanced graph algorithms or specialized tree types (e.g., balanced trees, tries).

Install

treelib on PyPI

pip

pip install treelib

uv

uv add treelib

poetry

poetry add treelib

Installing treelib

Before you install

Low friction install with a single lightweight dependency (six). Actively maintained with recent releases; last commit on 2026-08-13 and over 870 repository stars indicate ongoing support.

License in practice

Licensed under Apache-2.0 (permissive), which allows commercial and private use with minimal restrictions—suitable for most projects.

Quickstart

pip install treelib

from treelib import Tree

tree = Tree()
tree.create_node('Root', 'root')
tree.create_node('Child', 'child', parent='root')
print(tree)

Requires Python 3.7 or later.

Verify before relying

  • Whether the tree implementation supports all standard tree operations (insertion, deletion, search, traversal methods) beyond basic node creation.
  • Performance characteristics for large trees or deeply nested hierarchies.
  • Whether visualization/rendering output formats are customizable beyond console display.

Package facts

License Apache-2.0 (permissive)
Python support supports the current Python release (<4.0,>=3.7)
Install friction low — pure-Python wheel
Runtime dependencies 1 — six
Maintenance actively maintained — 411 days since the last release
Last repo commit
First released
Downloads 1,793,127/month — #3,552 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: treelib-1.8.0-py3-none-any.whl

Keywords: data structure, tree, tools

Development Status :: 5 - Production/StableEnvironment :: ConsoleIntended Audience :: DevelopersLicense :: OSI Approved :: Apache Software LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Software Development :: Libraries :: Python Modules

Tags

tree data structure pythonhierarchical tree implementationnode tree librarytree traversal pythondisplay tree structurepython tree nodes
data-structurestree-algorithms

More Python Modules packages