Skip to main content

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.0. 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(), get_path().

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), show(), get_text().

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.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytreeds 0.2.0
File Size Uploaded Provenance Actions
pytreeds-0.2.0.tar.gz 7.2 kB Without provenance Details for pytreeds-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pytreeds 0.2.0
File Interpreter ABI Platform Actions
pytreeds-0.2.0-py3-none-any.whl Python 3 none any Details for pytreeds-0.2.0-py3-none-any.whl

Total release size: 13.1 kB

Release files / pytreeds-0.2.0.tar.gz

Download URL pytreeds-0.2.0.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f097f35a2ae3ea98e9dbda624015fa876b2a483c924c17c8409c3afd6667d547
BLAKE2b-256 checksum
How to use checksums
ae8b9b9ed3dae6dc1132d6c4b099a0f00d4cfd6a88ccb0a72590e9f766f547a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.12.15

Release files / pytreeds-0.2.0-py3-none-any.whl

Download URL pytreeds-0.2.0-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9787fb89437cc2a4dacb7ba19ced5618a203e2a94be4b2b1417e64992c938c43
BLAKE2b-256 checksum
How to use checksums
082c7407f47d89b828937bd30f0f661059c01138f8bb757b32a5fa64e54028d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.12.15

Security for pytreeds 0.2.0

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page