# ![logo](https://raw.githubusercontent.com/mar10/nutree/main/docs/nutree_48x48.png) nutree
[![Tests](https://github.com/mar10/nutree/actions/workflows/tests.yml/badge.svg)](https://github.com/mar10/nutree/actions/workflows/tests.yml)
[![Latest Version](https://img.shields.io/pypi/v/nutree.svg)](https://pypi.python.org/pypi/nutree/)
[![License](https://img.shields.io/pypi/l/nutree.svg)](https://github.com/mar10/nutree/blob/main/LICENSE.txt)
[![Documentation Status](https://readthedocs.org/projects/nutree/badge/?version=latest)](http://nutree.readthedocs.io/)
[![codecov](https://codecov.io/github/mar10/nutree/branch/main/graph/badge.svg?token=9xmAFm8Icl)](https://codecov.io/github/mar10/nutree)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
[![Released with: Yabs](https://img.shields.io/badge/released%20with-yabs-yellowgreen)](https://github.com/mar10/yabs)
[![StackOverflow: nutree](https://img.shields.io/badge/StackOverflow-nutree-blue.svg)](https://stackoverflow.com/questions/tagged/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') <br>
Search by name pattern, id, or object reference <br>
Unobtrusive handling of arbitrary objects <br>
Compare two trees and calculate patches <br>
Save as DOT file and graphwiz diagram <br>
Nodes can be plain strings or objects <br>
(De)Serialize to (compressed) JSON <br>
Save as Mermaid flow diagram <br>
Different traversal methods <br>
Generate random trees <br>
Fully type annotated <br>
Convert to RDF graph <br>
Typed child nodes <br>
Pretty print <br>
Navigation <br>
Filtering <br>
**Example**
A simple tree, with text nodes
```py
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()
```
```ascii
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, ...
```py
records_node = tree["Records"]
assert isinstance(records_node, Node)
assert records_node.name == "Records"
print(records_node.first_child())
```
```ascii
Node<'Let It Be', data_id=510268653885439170>
```
Nodes may be strings or arbitrary objects:
```py
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](https://nutree.readthedocs.io/) for more.
Raw data
{
"_id": null,
"home_page": "https://github.com/mar10/nutree/",
"name": "nutree",
"maintainer": "Martin Wendt",
"docs_url": null,
"requires_python": null,
"maintainer_email": "nutree@wwwendt.de",
"keywords": "tree, data structure, digraph, graph, nodes, hierarchy, treelib",
"author": "Martin Wendt",
"author_email": "nutree@wwwendt.de",
"download_url": "https://files.pythonhosted.org/packages/ef/ea/921ee1c4f7da467b192b732204d2a2c69c8d3a70d339d065908fd2d4ae61/nutree-0.9.0.tar.gz",
"platform": null,
"description": "# ![logo](https://raw.githubusercontent.com/mar10/nutree/main/docs/nutree_48x48.png) nutree\n\n[![Tests](https://github.com/mar10/nutree/actions/workflows/tests.yml/badge.svg)](https://github.com/mar10/nutree/actions/workflows/tests.yml)\n[![Latest Version](https://img.shields.io/pypi/v/nutree.svg)](https://pypi.python.org/pypi/nutree/)\n[![License](https://img.shields.io/pypi/l/nutree.svg)](https://github.com/mar10/nutree/blob/main/LICENSE.txt)\n[![Documentation Status](https://readthedocs.org/projects/nutree/badge/?version=latest)](http://nutree.readthedocs.io/)\n[![codecov](https://codecov.io/github/mar10/nutree/branch/main/graph/badge.svg?token=9xmAFm8Icl)](https://codecov.io/github/mar10/nutree)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)\n[![Released with: Yabs](https://img.shields.io/badge/released%20with-yabs-yellowgreen)](https://github.com/mar10/yabs)\n[![StackOverflow: nutree](https://img.shields.io/badge/StackOverflow-nutree-blue.svg)](https://stackoverflow.com/questions/tagged/nutree)\n\n> _Nutree_ is a Python library for tree data structures with an intuitive,\n> yet powerful, API.\n\n**Nutree Facts**\n\nHandle multiple references of single objects ('clones') <br>\nSearch by name pattern, id, or object reference <br>\nUnobtrusive handling of arbitrary objects <br>\nCompare two trees and calculate patches <br>\nSave as DOT file and graphwiz diagram <br>\nNodes can be plain strings or objects <br>\n(De)Serialize to (compressed) JSON <br>\nSave as Mermaid flow diagram <br>\nDifferent traversal methods <br>\nGenerate random trees <br>\nFully type annotated <br>\nConvert to RDF graph <br>\nTyped child nodes <br>\nPretty print <br>\nNavigation <br>\nFiltering <br>\n\n**Example**\n\nA simple tree, with text nodes\n\n```py\nfrom nutree import Tree, Node\n\ntree = Tree(\"Store\")\n\nn = tree.add(\"Records\")\n\nn.add(\"Let It Be\")\nn.add(\"Get Yer Ya-Ya's Out!\")\n\nn = tree.add(\"Books\")\nn.add(\"The Little Prince\")\n\ntree.print()\n```\n\n```ascii\nTree<'Store'>\n\u251c\u2500\u2500\u2500 'Records'\n\u2502 \u251c\u2500\u2500\u2500 'Let It Be'\n\u2502 \u2570\u2500\u2500\u2500 \"Get Yer Ya-Ya's Out!\"\n\u2570\u2500\u2500\u2500 'Books'\n \u2570\u2500\u2500\u2500 'The Little Prince'\n```\n\nTree nodes wrap the data and also expose methods for navigation, searching,\niteration, ...\n\n```py\nrecords_node = tree[\"Records\"]\nassert isinstance(records_node, Node)\nassert records_node.name == \"Records\"\n\nprint(records_node.first_child())\n```\n\n```ascii\nNode<'Let It Be', data_id=510268653885439170>\n```\n\nNodes may be strings or arbitrary objects:\n\n```py\nalice = Person(\"Alice\", age=23, guid=\"{123-456}\")\ntree.add(alice)\n\n# Lookup nodes by object, data_id, name pattern, ...\nassert isinstance(tree[alice].data, Person)\n\ndel tree[alice]\n```\n\n[Read the Docs](https://nutree.readthedocs.io/) for more.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Python library for tree data structures with an intuitive, yet powerful, API.",
"version": "0.9.0",
"project_urls": {
"Bug Tracker": "https://github.com/mar10/nutree/issues",
"Documentation": "https://nutree.readthedocs.io/",
"Download": "https://github.com/mar10/nutree/releases/latest",
"Homepage": "https://github.com/mar10/nutree/",
"Source Code": "https://github.com/mar10/nutree"
},
"split_keywords": [
"tree",
" data structure",
" digraph",
" graph",
" nodes",
" hierarchy",
" treelib"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f567657794314698820e93c82fbccadebe69c694c1c85f6011779a9473082309",
"md5": "d795cd734aaf534e34676ab9daa1d4b5",
"sha256": "d986d8e17747be2d88576ed7aab5bb7e5f945b480474397d2db58e03c14feb48"
},
"downloads": -1,
"filename": "nutree-0.9.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d795cd734aaf534e34676ab9daa1d4b5",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 49847,
"upload_time": "2024-09-12T11:32:18",
"upload_time_iso_8601": "2024-09-12T11:32:18.836297Z",
"url": "https://files.pythonhosted.org/packages/f5/67/657794314698820e93c82fbccadebe69c694c1c85f6011779a9473082309/nutree-0.9.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "efea921ee1c4f7da467b192b732204d2a2c69c8d3a70d339d065908fd2d4ae61",
"md5": "19c015b6cc8235815e485d00f9cc3c5c",
"sha256": "34367ef7d4b9d47fbcf8a6a1964ee836f1bd59126608f7dce9f9e70ec47119fd"
},
"downloads": -1,
"filename": "nutree-0.9.0.tar.gz",
"has_sig": false,
"md5_digest": "19c015b6cc8235815e485d00f9cc3c5c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 62390,
"upload_time": "2024-09-12T11:32:16",
"upload_time_iso_8601": "2024-09-12T11:32:16.100679Z",
"url": "https://files.pythonhosted.org/packages/ef/ea/921ee1c4f7da467b192b732204d2a2c69c8d3a70d339d065908fd2d4ae61/nutree-0.9.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-12 11:32:16",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "mar10",
"github_project": "nutree",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "nutree"
}