Tree library
Project description
LittleTree is a library that provides a tree data structure to python, which is both fast and flexible. It can be used to represent file systems, taxonomies and much more.
Features
- Intuitive basic creation and modification of trees.
- Efficient implementation of common tree operations and traversals that still work on trees that are more than 10,000 layers deep.
- Extensible: either subclass from
NodeorBaseNode. - Can be imported / exported to many different formats (nested dict, rows, relations, graphviz, mermaid, newick, networkx).
- Purely written in Python.
Limitation
- Each node has at most one parent. (It's a tree not a graph!)
Installing
- Use pip to install littletree:
$ pip install --upgrade littletree
Usage
A tree can be used in a similar way as a dict:
from littletree import Node
tree = Node(identifier="World")
tree["Asia"] = Node()
tree["Africa"] = Node(data={"surface_area": 30.37e6})
tree["America"] = Node()
# Alternative way of adding a node
tree.add_child(Node(identifier="Europe"))
# Print tree to console
tree.show()
# Show tree as an image
tree.to_pillow().show()
The resulting tree is printed like this:
World
├─ Asia
├─ Africa
├─ America
└─ Europe
If Pillow and graphviz are installed, it will also display the following image:
See tutorial for more information.
See further: Pypi | Github | Issues | Documentation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file littletree-0.9.1-py3-none-any.whl.
File metadata
- Download URL: littletree-0.9.1-py3-none-any.whl
- Upload date:
- Size: 24.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
03ab9f57e39dcf773562271e94c3a4cc020507d6c51db91dcf10d23fbd00e65d
|
|
| MD5 |
e360920c006aa7c3da72a0fd80582833
|
|
| BLAKE2b-256 |
60ef93570a0c158d11cc75650ee3958284fbd94fddd587ffc5c6f739e65867d0
|