Powerful and Lightweight Python Tree Data Structure..
Project description
Documentation
The Documentation is hosted on http://anytree.readthedocs.io/en/2.5.0/
Getting started
Usage is simple.
Construction
>>> from anytree import Node, RenderTree
>>> udo = Node("Udo")
>>> marc = Node("Marc", parent=udo)
>>> lian = Node("Lian", parent=marc)
>>> dan = Node("Dan", parent=udo)
>>> jet = Node("Jet", parent=dan)
>>> jan = Node("Jan", parent=dan)
>>> joe = Node("Joe", parent=dan)
Node
>>> print(udo)
Node('/Udo')
>>> print(joe)
Node('/Udo/Dan/Joe')
Tree
>>> for pre, fill, node in RenderTree(udo):
... print("%s%s" % (pre, node.name))
Udo
├── Marc
│ └── Lian
└── Dan
├── Jet
├── Jan
└── Joe
>>> from anytree.exporter import DotExporter
>>> # graphviz needs to be installed for the next line!
>>> DotExporter(udo).to_picture("udo.png")
Manipulation
A second tree:
>>> mary = Node("Mary")
>>> urs = Node("Urs", parent=mary)
>>> chris = Node("Chris", parent=mary)
>>> marta = Node("Marta", parent=mary)
>>> print(RenderTree(mary))
Node('/Mary')
├── Node('/Mary/Urs')
├── Node('/Mary/Chris')
└── Node('/Mary/Marta')
Append:
>>> udo.parent = mary
>>> print(RenderTree(mary))
Node('/Mary')
├── Node('/Mary/Urs')
├── Node('/Mary/Chris')
├── Node('/Mary/Marta')
└── Node('/Mary/Udo')
├── Node('/Mary/Udo/Marc')
│ └── Node('/Mary/Udo/Marc/Lian')
└── Node('/Mary/Udo/Dan')
├── Node('/Mary/Udo/Dan/Jet')
├── Node('/Mary/Udo/Dan/Jan')
└── Node('/Mary/Udo/Dan/Joe')
Subtree rendering:
>>> print(RenderTree(marc))
Node('/Mary/Udo/Marc')
└── Node('/Mary/Udo/Marc/Lian')
Cut:
>>> dan.parent = None
>>> print(RenderTree(dan))
Node('/Dan')
├── Node('/Dan/Jet')
├── Node('/Dan/Jan')
└── Node('/Dan/Joe')
Installation
To install the anytree module run:
pip install anytree
If you do not have write-permissions to the python installation, try:
pip install anytree --user
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file anytree-2.5.0.tar.gz.
File metadata
- Download URL: anytree-2.5.0.tar.gz
- Upload date:
- Size: 18.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.7.1 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
409ccb966d759952648d5e5656bc311ab63a1f4a7d5ed9fc0e9715343ca2aa74
|
|
| MD5 |
69aae21eca9b3c1c4d84b3baae494bd0
|
|
| BLAKE2b-256 |
e5ce2e607d2c069e2a257675ebd8ca78b3823717aab898290bb1433fc4c7581f
|
File details
Details for the file anytree-2.5.0-py2.py3-none-any.whl.
File metadata
- Download URL: anytree-2.5.0-py2.py3-none-any.whl
- Upload date:
- Size: 31.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.7.1 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4de1010295b47a607a2a0cde6417f6f1b412225654f6606d6d4f5385b5b4c10a
|
|
| MD5 |
cc758997108a7d3b5a2efc16903d50ec
|
|
| BLAKE2b-256 |
61323a73d48a9008fc1e960b5b60ef546501ea9c4727537fe25155c5f657f82b
|