Skip to main content

Tree library

Project description

LittleTree is a library that provides a tree data structure to python. The package is purely written in python. It should be easy to use while efficient.

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()

tree.show()  # Same as print(tree.to_string())
tree.to_image().show()  # Show as an image instead

The resulting tree is printed like this:

World
├─ Asia
├─ Africa
├─ America
└─ Europe

And it creates the following image:

world

See tutorial for more information.

Limitations

  • Each node has a single parent
  • A node can't have a sibling with the same identifier

Alternatives

Before creating this, I looked at some other tree libraries. I found the others to be lacking, because they were either slow or made simple things complicated. Therefore, I decided to make my own.

  • anytree - Very hackable, but generally slow.
  • bigtree - Similar to anytree, but has more features.
  • itertree - Has many features and good performance, but has a complicated design.
  • treelib - This puts all nodes of a tree into a single dict. This makes some operations difficult or slow, although it has advantages too.
  • networkx - Is actually made for graphing. Doesn't have a dedicated tree type.

Project details


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

littletree-0.4.1-py3-none-any.whl (31.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page