treelib
A Python implementation of tree structure.
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 treelibuv
uv add treelibpoetry
poetry add treelibInstalling 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
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
anytreeProvides a lightweight Python library for…
unclear · top 5,000 on PyPI
nutreeNutree provides a Python library for creating,…
permissive · top 5,000 on PyPI
bigtreeBigtree provides tree, binary tree, and…
permissive · top 15,000 on PyPI
treetableRenders nested data structures as formatted…
permissive · top 15,000 on PyPI
asciitreeRenders tree data structures as formatted ASCII…
permissive · top 5,000 on PyPI
dm-treeProvides utilities for working with nested data…
permissive · top 5,000 on PyPI
django-tree-queriesQuery hierarchical tree structures in Django…
permissive · top 15,000 on PyPI
optreeOpTree provides optimized utilities for…
permissive · top 5,000 on PyPI
logging-treeVisualizes the hierarchy of loggers, handlers,…
permissive · top 15,000 on PyPI
aptedComputes the tree edit distance between two…
permissive · top 15,000 on PyPI