pytreeds
A dependency-free, beginner-focused Python tree library suitable for Pyodide. One Tree variable holds all nodes, and navigation/traversal uses names (strings) consistently. Attach optional Python data to individual nodes.
Version: The current source release is 0.2.1. See the PyPI project page for the latest published version.
Quick start
from pytreeds import Tree
org = Tree()
org.add_node("CEO", data={"level": 1})
org.add_node("CTO", parent="CEO", data=[90, 85])
org.add_node("CFO", parent="CEO")
org.add_node("COO", parent="CEO")
org.add_node("Engineering", parent="CTO")
org.add_node("DevOps", parent="CTO")
print(org)
print(org.get_node_data("CTO")) # [90, 85]
org.set_node_data("CTO", {"team": "Technology"})
print(org.get_node_data("CTO"))
print(list(org.dfs()))
print(list(org.bfs()))
org.move_node("CTO", parent="COO") # The entire CTO subtree moves
org.delete_node("CFO") # Works on leaf or subtree
print(org)
Omitting parent in add_node() creates a root only when the tree is empty. Every later node requires a parent. One Tree contains exactly one root.
Install
Regular Python: pip install pytreeds
Pyodide (asynchronous package loader):
import micropip
await micropip.install("pytreeds")
API summary
Build: Tree(), add_node(name, parent=None, data=None).
Edit: delete_node(), move_node(), rename_node(), copy(). Removing a node removes all its descendants; moving one moves its entire subtree.
Inspect: get_root(), get_size(), get_height(), get_depth(), get_leaf_count(), is_leaf(), contains().
Relationships: get_parent(), get_children(), get_siblings(), get_ancestors(), get_descendants(), get_leaves().
Data: get_node_data(name), set_node_data(name, data). Any Python object can be attached, including lists and dictionaries. Values are returned by reference; copy() deep-copies data, so objects incompatible with deepcopy() may cause an error when copying.
Traversal: dfs(), bfs(), and ordinary for name in tree. The dfs() method uses left-to-right preorder (visits parents before their children).
Text: print(tree) for display, or get_text() to retrieve a diagram as a string.
See the illustrated terminology guide and the Detailed Reference, with a dedicated page for every method.
Local tests
python -m unittest discover -s tests -v
The existing GitLab PyPI publishing pipeline is unchanged. No testing CI pipeline has been introduced.
Metadata
Release files for pytreeds 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pytreeds-0.2.1.tar.gz | 7.2 kB | Without provenance | Details for pytreeds-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytreeds-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for pytreeds-0.2.1-py3-none-any.whl |
Total release size: 13.1 kB
Release files / pytreeds-0.2.1.tar.gz
| Download URL | pytreeds-0.2.1.tar.gz |
|---|---|
| Size | 7.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7b5925098f832af3a4f3eaa555ecd6ac04274c6b08815a77f459f66c68350128
|
|
BLAKE2b-256 checksum How to use checksums |
3e4183de188b92bc32a836541de6cffc427ec3c36980ac15fabc23b357350c51
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.12.16
|
Release files / pytreeds-0.2.1-py3-none-any.whl
| Download URL | pytreeds-0.2.1-py3-none-any.whl |
|---|---|
| Size | 5.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
55827b283449f958ef43870115085ea3918a0acf1b69cf720f28d170885fc54e
|
|
BLAKE2b-256 checksum How to use checksums |
971770db718fd548680f480a8030f3c86c94328b2c061d1d14870863f7a71a1b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.12.16
|
Security for pytreeds 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.