Skip to content

lverweijen/littletree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 Node or BaseNode.
  • 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()
tree["America"] = Node()
tree["Europe"] = Node()

# 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:

world

See tutorial for more information.

See further: Pypi | Github | Issues

About

Tree data structure

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages