Skip to main content

vcti-tree

Tree protocols and generic algorithms for the vcti ecosystem. Zero-dependency abstractions; pluggable backings.

Overview

vcti-tree defines what a tree is in the vcti ecosystem: three Protocols (ReadOnlyTree, MutableTree, LockableTree) parameterized in payload type T and handle type H, plus generic algorithms — DFS and BFS walks, ancestor/depth/path queries, locking guards — written against those Protocols. The Protocols specify semantics (what a tree must support); they do not prescribe storage. Any backing — numpy-array, pointer-based, dict-based — that satisfies the Protocols gets the algorithms for free. The package has no numpy or other heavy dependency; it is a pure-Python abstraction layer that downstream tree packages depend on. Adding a tree implementation means satisfying three small Protocols, not rewriting walkers and guards.

Installation

pip install vcti-tree

In requirements.txt

vcti-tree>=3.0.0

In pyproject.toml dependencies

dependencies = [
    "vcti-tree>=3.0.0",
]

Quick Start

The protocols and algorithms are the API; you bring (or import) a backing. DictTree is the bundled dict-backed reference implementation — enough to build a tree and run the generic algorithms against it:

from vcti.tree.core import DictTree, dfs_preorder, ancestors, depth

tree = DictTree[str]("root")            # every tree has a root from the start
a = tree.create_child(tree.root_handle, "a")
b = tree.create_child(tree.root_handle, "b")
tree.create_child(a, "a1")

# Generic walks/queries work against any tree that satisfies the protocols.
print([tree.payload(h) for h in dfs_preorder(tree)])   # ['root', 'a', 'a1', 'b']
print([tree.payload(h) for h in ancestors(tree, a)])   # ['root']
print(depth(tree, a))                                  # 1

Everything is importable from the package root, vcti.tree.core.


Key API

Name Kind What it is
ReadOnlyTree[T, H] Protocol Root, payload, parent, children, membership, iteration, length
MutableTree[T, H] Protocol Adds set_payload, create_child, delete_subtree
LockableTree[T, H] Protocol Adds per-node structure and payload locks
DictTree[T] Class Dict-backed reference implementation of LockableTree
TreeError Exception Base of every error a tree operation or algorithm raises

Condensed reference

Function Takes Returns
dfs_preorder(tree, start=None) ReadOnlyTree Iterator: node, then its subtrees
dfs_postorder(tree, start=None) ReadOnlyTree Iterator: subtrees, then node
bfs(tree, start=None) ReadOnlyTree Iterator: level order
ancestors(tree, h) ReadOnlyTree Iterator: parent up to root
depth(tree, h) ReadOnlyTree int; the root is 0
path(tree, h) ReadOnlyTree list: root down to h
descendants(tree, h, *, include_self=False) ReadOnlyTree Iterator: h's subtree, pre-order
collect_deletable_subtree(tree, h) LockableTree list of h's subtree; raises if it may not be deleted
ensure_structure_unlocked(tree, handles) LockableTree None; raises on the first structure-locked handle
ensure_payload_unlocked(tree, handles) LockableTree None; raises on the first payload-locked handle
Exception Raised when
HandleError (InvalidHandleError, StaleHandleError) A handle names no usable node
InactiveNodeError The node has been deleted
StructureLockedError, PayloadLockedError (LockedError) A lock blocked the operation
RootDeletionError delete_subtree was called on the root

Dependencies

None. Standard library only.

Documentation

If you want to… Read
Get started using the package Quick Start above
See practical, real-world usage docs/patterns.md
Understand the architecture and design decisions docs/design.md
Navigate and understand the source docs/source-guide.md
Implement a tree backing of your own docs/extending.md

Metadata

Release files for vcti-tree 3.0.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 vcti-tree 3.0.0
File Size Uploaded Provenance Actions
vcti_tree-3.0.0.tar.gz 31.1 kB With provenance Details for vcti_tree-3.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for vcti-tree 3.0.0
File Interpreter ABI Platform Actions
vcti_tree-3.0.0-py3-none-any.whl Python 3 none any Details for vcti_tree-3.0.0-py3-none-any.whl

Total release size: 50.0 kB

Release files / vcti_tree-3.0.0.tar.gz

Download URL vcti_tree-3.0.0.tar.gz
Size 31.1 kB
Tags Source
SHA-256 checksum
How to use checksums
7bca925d9256eab38810780b159d894071ccdac8b10d8c90dc6b0c96c6c9e8f6
BLAKE2b-256 checksum
How to use checksums
7265e7264616da34788a8e70f67ba4a0f7973efd1efc638902583747f0f9ba74
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Release files / vcti_tree-3.0.0-py3-none-any.whl

Download URL vcti_tree-3.0.0-py3-none-any.whl
Size 18.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ed85c2dc6c653f219042fcf4ed4a74d3ad8fbbdebed9d91bee793943e3f69e7b
BLAKE2b-256 checksum
How to use checksums
be6e74aa2498f54a44a4e7d0c6ee36bf51ebc056efc4858c6787a1b5be0cc7aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Security for vcti-tree 3.0.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for vcti_tree-3.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

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