Skip to main content

logo nutree

Latest Version Tests codecov License Documentation Status Downloads

Nutree lets you organize and query arbitrary Python objects as a tree — with clones, diffing, and graph export built in.

Trees and nodes behave like familiar Python containers wherever that makes sense — len(tree) counts nodes, for node in tree: ... walks the tree depth-first, and value in tree tests membership. Lookup (tree[value]) matches by id or by the wrapped data (not by position, since a tree has no natural order).

[!TIP] Take the Tour and Read the Docs for more.

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
Multiple traversal methods
Generate random trees
Convert to RDF graph
Fully type annotated
Typed child nodes
Memory efficient
Pretty print
Navigation
Filtering
Fast

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 can holdarbitrary objects (not just strings):

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

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

del tree[alice]

Take the Tour and Read the Docs for more.

Download files

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

Source Distribution

nutree-1.2.0.tar.gz (78.5 kB view details)

Uploaded Source

Built Distribution

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

nutree-1.2.0-py3-none-any.whl (57.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nutree-1.2.0.tar.gz
  • Upload date:
  • Size: 78.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for nutree-1.2.0.tar.gz
Algorithm Hash digest
SHA256 f2e505e002df01eeb6a06aca483a70aaa341adc62ab3ebddfabd50a15421edeb
MD5 ca15233dca463e972655bf9c23f21459
BLAKE2b-256 21ff019829f01b17f4c39ebc53f069890aeb8145fd86b08e09ab89110b05465d

See more details on using hashes here.

Provenance

The following attestation bundles were made for nutree-1.2.0.tar.gz:

Publisher: release.yml on mar10/nutree

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: nutree-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 57.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for nutree-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9e44f932b657a213844df3b47f091c67dee92db70845c01e503a387a5b01aad1
MD5 3bd5bb46120c54b5e5d5ff3fb354d719
BLAKE2b-256 dce422ef7b69b9849e9b2b6d36a830cfcedefa7670129de0b01db38be32bcca4

See more details on using hashes here.

Provenance

The following attestation bundles were made for nutree-1.2.0-py3-none-any.whl:

Publisher: release.yml on mar10/nutree

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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