Skip to main content

An abstract lightweight tree class for managing tree structures.

Requires Python 3.11 or newer.

Typed list representations

TreeNodeListRepresentation[ValueT] describes [value, child, ...] recursively. create_tree_from_list() accepts the same value type as get_list_representation(), including scalar values for a single attribute:

from verysimpletree.tree import TreeNodeListRepresentation

representation: TreeNodeListRepresentation[int] = [
    10,
    [3, [2, [1], [1]], [1]],
    [7, [4], [3]],
]
# For a concrete Tree subclass whose constructor accepts value:
tree = MyTree.create_tree_from_list(representation, "value")

For multiple attributes, each node value is a list of attribute values, ordered to match represented_attribute_names. Child representations must be lists. The value type checks the representation's contents; it does not verify that attribute names or values match the subclass constructor.

Development

Use a current uv release; development and package builds are verified with uv 0.13.1. Older uv releases may fail to extract archives used by the current build backend.

uv sync --locked
uv run pytest
uv run mypy verysimpletree --strict
uv run ruff check .
uv run ruff format --check .
uv build

GitLab CI and releases

The root .gitlab-ci.yml runs lint and strict type checks, tests Python 3.11-3.14, and builds a wheel and source distribution. Merge requests, branch pushes, and tags run validation; duplicate branch pipelines are skipped for pushes with an open merge request. Jobs explicitly select their Python interpreter rather than relying on the development .python-version pin. JUnit test reports and built distributions are retained as job artifacts.

To enable publishing on GitLab:

  1. Use a runner that supports the configured Python Docker images.
  2. Protect release tags matching v* and restrict who can create them.
  3. Add UV_PUBLISH_TOKEN as a masked, protected CI/CD variable containing a PyPI API token scoped to the verysimpletree project.
  4. Set the version in pyproject.toml, update uv.lock, and commit the changes.
  5. Push a matching stable version tag, such as v2.0.1.

Publishing runs automatically only for protected stable version tags, after checks, tests, and the build pass. The tag must match the package version. The publish job uploads the build job's artifacts without rebuilding them. Branch and merge request pipelines never publish.

Structural mutations

  • parent.add_child(child) appends a detached child and returns it.
  • parent.insert_child(index, child) inserts a detached child and returns it. Indices follow list.insert(): negative indices count from the end, and out-of-range indices are clamped.
  • parent.remove(child) detaches a direct child.
  • parent.replace_child(old, new, index=0) replaces a direct child in place. old can also be a predicate; index selects among matching children. Replacing a child with itself is a no-op. The method returns None.

Children must have no parent before attachment. Self-insertion, ancestor insertion, and attaching an already-parented child raise ValueError. Subclass child-type checks still apply. Invalid attachments leave the tree unchanged. To move a child, remove it from its old parent first:

old_parent.remove(child)
new_parent.add_child(child)

Mutation methods update parent pointers, leaf status, and affected traversal, leaf, and ancestor-path caches.

Subclass contract

Implement _check_child_to_be_added() to validate allowed child types, raising an exception for invalid children without mutating the tree. Structural checks are shared by add_child(), insert_child(), and replace_child() through _validate_child_attachment().

Inherited structural operations use _children as their authoritative child storage. Overriding get_children() alone does not provide alternative-storage support. Subclasses using _children should reuse the mutation methods rather than assign parent pointers or edit child lists directly.

get_children() still returns the mutable backing list for compatibility. Direct edits bypass validation and cache invalidation.

Metadata

Release files for verysimpletree 2.0.2

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

Source distribution (sdist)

Source distribution for verysimpletree 2.0.2
File Size Uploaded
verysimpletree-2.0.2.tar.gz 14.8 kB Details

Built distribution (wheel)

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

Total release size: 30.2 kB

Release files / verysimpletree-2.0.2.tar.gz

Download URL verysimpletree-2.0.2.tar.gz
Size 14.8 kB
Tags Source
SHA-256 checksum
How to use checksums
763e32cb17b01b4a363d0d065d0f628a01ecffc4e799e43d9d6c80cf8067b2be
BLAKE2b-256 checksum
How to use checksums
fc89d0c9edb37df8fee46109c619f83ef6248ff3c167c0c795ff7f43ea7f1e86
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / verysimpletree-2.0.2-py3-none-any.whl

Download URL verysimpletree-2.0.2-py3-none-any.whl
Size 15.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
88abb72319936c7ca213a589380f0a6a9b0535c42dbb7dc2196396ed8ceec1e3
BLAKE2b-256 checksum
How to use checksums
3f263f5e5d4da436b98dd6b025bcb5e706f3dee585e064ebb7e8e9f96f3c7990
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
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