Skip to main content

Path Tree

Purpose

VCollab applications frequently need to scan directory structures — listing files and subdirectories recursively, representing them as structured data for API responses, and generating CLI-style tree visualizations.

The vcti-path-tree package provides Pydantic models (File, Directory) for representing file system trees and entry points — get_path_tree() for scanning directories into models, get_cli_tree() for generating tree visualizations, walk_tree() for iterating over scanned trees, and get_tree_stats() for summary statistics.

Requires Python 3.12+. Dependencies: pydantic, vcti-enum.


Installation

From GitHub (recommended for development)

# Latest main branch
pip install vcti-path-tree



### In `requirements.txt`

vcti-path-tree>=1.1.1


### In `pyproject.toml` dependencies

```toml
dependencies = [
    "vcti-path-tree>=1.1.1",
]

Quick Start

from pathlib import Path
from vcti.pathtree import get_path_tree, get_cli_tree

# Scan a directory into Pydantic models
tree = get_path_tree(Path("/data/project"))

# Generate a CLI-style tree visualization
lines = get_cli_tree(tree)
for line in lines:
    print(line)
# project/
# ├── src/
# │   ├── main.py
# │   └── utils.py
# └── README.md

# Access model attributes
root = tree[0]
print(root.name)       # "project"
print(root.type)       # PathType.DIRECTORY
for child in root.children:
    print(f"  {child.name} ({child.type})")

# Relative paths with posix format
tree = get_path_tree(
    Path("/data/project"),
    base_path=Path("/data"),
    as_posix=True
)
print(tree[0].path)    # "project"

# Skip root directory, get only children
children = get_path_tree(Path("/data/project"), skip_root=True)

# Limit recursion depth
tree = get_path_tree(Path("/data/project"), max_depth=2)

# Filter: only include .py files and directories
tree = get_path_tree(
    Path("/data/project"),
    filter_fn=lambda p: p.is_dir() or p.suffix == ".py",
)

# Include file timestamps
tree = get_path_tree(Path("/data/project"), include_metadata=True)

# Serialize to JSON (Pydantic models)
import json
print(json.dumps([node.model_dump() for node in tree], indent=2))

Public API

Name Kind Description
PathType Enum FILE or DIRECTORY
PathBase Model Base Pydantic model with name, path, type
File Model File node with size, optional modified_time/created_time
Directory Model Directory node with children list, optional timestamps
PathTree Type alias list[Directory | File]
FilterFn Type alias Callable[[Path], bool] for path filtering
TreeStats Model Summary stats: total_files, total_dirs, total_size, max_depth
handle_file(...) Function Create a File model from a Path
handle_directory(...) Function Create a Directory model recursively
get_path_tree(...) Function Scan path into a list of models
get_cli_tree(path_tree) Function Generate CLI tree visualization lines
walk_tree(tree) Function Yield (dir_path, dirs, files) tuples like os.walk
get_tree_stats(tree) Function Compute summary statistics for a tree
parse_path_tree(data) Function Deserialize list of dicts into a PathTree

Limitations

  • Symlinks are followed. The scanner uses Python's default behavior (Path.stat(), Path.iterdir()), which follows symbolic links. Use max_depth to guard against cycles from recursive symlinks.
  • Permission errors propagate. If a file or directory is not readable, OSError is raised. There is no partial-tree or skip-on-error mode.
  • Entire tree is materialized in memory. Not suitable for very large directory trees where streaming would be preferred.

Documentation

  • Design — Concepts, architecture decisions, and trade-offs
  • Source Guide — Execution flow traces for developers
  • API Reference — Autodoc for all modules

Metadata

Release files for vcti-path-tree 1.1.1

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-path-tree 1.1.1
File Size Uploaded
vcti_path_tree-1.1.1.tar.gz 12.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for vcti-path-tree 1.1.1
File Interpreter ABI Platform
vcti_path_tree-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 23.1 kB

Release files / vcti_path_tree-1.1.1.tar.gz

Download URL vcti_path_tree-1.1.1.tar.gz
Size 12.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b116fce33c89c9127b46e763147e79743467cf9df3e8e7822d5875e2c2083de4
BLAKE2b-256 checksum
How to use checksums
6e6ab6e468a907508975198a7cbf705eb9cb659b9875aedb390c789fa933ed8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Mar 22, 2026.

Transparency log

Release files / vcti_path_tree-1.1.1-py3-none-any.whl

Download URL vcti_path_tree-1.1.1-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d36967ac302109bafe3f7d7f244975187d36906f95ed528f214df103271f30b0
BLAKE2b-256 checksum
How to use checksums
3b474f275551f3fabe72da0589e9cc498206baf7e20da7f22d37fa3e98ce0c15
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Mar 22, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release files

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