Skip to main content

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

Project description

logo nutree

Tests Latest Version License Documentation Status codecov Code style: black 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
Unobtrusive handling of arbitrary objects
Compare two trees and calculate patches
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
Fully type annotated
Convert to RDF graph
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.8.0.tar.gz (55.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nutree-0.8.0-py3-none-any.whl (45.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nutree-0.8.0.tar.gz
  • Upload date:
  • Size: 55.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.0

File hashes

Hashes for nutree-0.8.0.tar.gz
Algorithm Hash digest
SHA256 4274de3bb738c5f7110acd9c90986b54f8ea17a833f8c772fab6b7b774a57cc9
MD5 8067a4b5352e5b5b7871e5de35872415
BLAKE2b-256 f91fa8e9b094a48b079d78b3cc92b4e9068a06e7e35d6da5d8d72807ed46132e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nutree-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 45.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.0

File hashes

Hashes for nutree-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 76da896c86cdef51353e922a17794ab209769853473e3e821a0feef2af840c87
MD5 92fff6b9a3937aad99b4f64697f94e63
BLAKE2b-256 e47561ce0441c9c3f28bea469a07c2cc84a5bd1f9384fd26416e475a8ded785b

See more details on using hashes here.

Supported by

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