Skip to main content

A Python library for tree data structures with an intuitive, yet powerful, API.

Project description

logo nutree

Latest Version Tests codecov License Documentation Status Released with: Yabs StackOverflow: nutree

Nutree is a Python library for tree data structures with an intuitive, yet powerful, API.

Nutree Facts

Handle multiple references of single objects ('clones')
Search by name pattern, id, or object reference
Compare two trees and calculate patches
Unobtrusive handling of arbitrary objects
Save as DOT file and graphwiz diagram
Nodes can be plain strings or objects
(De)Serialize to (compressed) JSON
Save as Mermaid flow diagram
Different traversal methods
Generate random trees
Convert to RDF graph
Fully type annotated
Typed child nodes
Pretty print
Navigation
Filtering

Example

A simple tree, with text nodes

from nutree import Tree, Node

tree = Tree("Store")

n = tree.add("Records")

n.add("Let It Be")
n.add("Get Yer Ya-Ya's Out!")

n = tree.add("Books")
n.add("The Little Prince")

tree.print()
Tree<'Store'>
├─── 'Records'
│    ├─── 'Let It Be'
│    ╰─── "Get Yer Ya-Ya's Out!"
╰─── 'Books'
     ╰─── 'The Little Prince'

Tree nodes wrap the data and also expose methods for navigation, searching, iteration, ...

records_node = tree["Records"]
assert isinstance(records_node, Node)
assert records_node.name == "Records"

print(records_node.first_child())
Node<'Let It Be', data_id=510268653885439170>

Nodes may be strings or arbitrary objects:

alice = Person("Alice", age=23, guid="{123-456}")
tree.add(alice)

# Lookup nodes by object, data_id, name pattern, ...
assert isinstance(tree[alice].data, Person)

del tree[alice]

Read the Docs for more.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nutree-0.11.0.tar.gz (72.0 kB view details)

Uploaded Source

Built Distribution

nutree-0.11.0-py3-none-any.whl (53.8 kB view details)

Uploaded Python 3

File details

Details for the file nutree-0.11.0.tar.gz.

File metadata

  • Download URL: nutree-0.11.0.tar.gz
  • Upload date:
  • Size: 72.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for nutree-0.11.0.tar.gz
Algorithm Hash digest
SHA256 50ba9c61819849951b976dd3746346a7d0027c101f97dd177575543cbc874e58
MD5 2600c222b3bac54d19938aae8a6fcaf9
BLAKE2b-256 19b879b9cd46bc610b5adf6af2f8ee5d5fa3d40b1c83d3867d188ab749a3d7bb

See more details on using hashes here.

File details

Details for the file nutree-0.11.0-py3-none-any.whl.

File metadata

  • Download URL: nutree-0.11.0-py3-none-any.whl
  • Upload date:
  • Size: 53.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for nutree-0.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 570a6a74b83edb3241c3b56938e701256296bdb0c50338aead71f9a91bf6811a
MD5 86969087f066dbf898ba95d57fc4972e
BLAKE2b-256 61f21196ad3e6fab730a7e5585883b2abefbb4ae6fcb5ee569c1ec2f0c6f4d3b

See more details on using hashes here.

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