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. Works on trees that are 10 000 layers deep.
- Extensible. Subclass from
BaseNode
if you need more freedom. - Can be imported / exported to many different formats (nested dict, rows, relations, graphviz, mermaid, newick, networkx).
- Purely written in Python.
Limitations
- Each node has at most one parent. (It's a tree not a graph!)
- Nodes cannot be their own ancestor.
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()
tree["America"] = Node()
tree["Europe"] = Node()
# Print tree to console
tree.show()
# Show tree as an image
tree.to_image().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.
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
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
File details
Details for the file littletree-0.8.1-py3-none-any.whl
.
File metadata
- Download URL: littletree-0.8.1-py3-none-any.whl
- Upload date:
- Size: 24.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.11.3 pkginfo/1.8.3 requests/2.28.1 requests-toolbelt/0.9.1 tqdm/4.64.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 107f54e1583026016cdaf395d5882268e45536be04942d69a78b0092cf8b01fe |
|
MD5 | 69f31e2b44b2b8ef1f7c4a7a1d838bf3 |
|
BLAKE2b-256 | 0b6c9833dd5fb608f8ffe92a0940562aff8c425c8d1ee4f63b50e091ce6b4b9d |