VCollab Path Tree - directory tree scanning and serialization using Pydantic models
Project description
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. Usemax_depthto guard against cycles from recursive symlinks. - Permission errors propagate. If a file or directory is not readable,
OSErroris 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file vcti_path_tree-1.1.1.tar.gz.
File metadata
- Download URL: vcti_path_tree-1.1.1.tar.gz
- Upload date:
- Size: 12.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b116fce33c89c9127b46e763147e79743467cf9df3e8e7822d5875e2c2083de4
|
|
| MD5 |
65eeaee1c7c1cabb0ce44a79c1b167d0
|
|
| BLAKE2b-256 |
6e6ab6e468a907508975198a7cbf705eb9cb659b9875aedb390c789fa933ed8b
|
Provenance
The following attestation bundles were made for vcti_path_tree-1.1.1.tar.gz:
Publisher:
publish.yml on vcollab/vcti-python-path-tree
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
vcti_path_tree-1.1.1.tar.gz -
Subject digest:
b116fce33c89c9127b46e763147e79743467cf9df3e8e7822d5875e2c2083de4 - Sigstore transparency entry: 1155602791
- Sigstore integration time:
-
Permalink:
vcollab/vcti-python-path-tree@67996d36e93b08e671ff46109b2971c3ac8c63dd -
Branch / Tag:
refs/heads/main - Owner: https://github.com/vcollab
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@67996d36e93b08e671ff46109b2971c3ac8c63dd -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file vcti_path_tree-1.1.1-py3-none-any.whl.
File metadata
- Download URL: vcti_path_tree-1.1.1-py3-none-any.whl
- Upload date:
- Size: 10.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d36967ac302109bafe3f7d7f244975187d36906f95ed528f214df103271f30b0
|
|
| MD5 |
ae0bd7d8975fcc3b395723f14114cbc6
|
|
| BLAKE2b-256 |
3b474f275551f3fabe72da0589e9cc498206baf7e20da7f22d37fa3e98ce0c15
|
Provenance
The following attestation bundles were made for vcti_path_tree-1.1.1-py3-none-any.whl:
Publisher:
publish.yml on vcollab/vcti-python-path-tree
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
vcti_path_tree-1.1.1-py3-none-any.whl -
Subject digest:
d36967ac302109bafe3f7d7f244975187d36906f95ed528f214df103271f30b0 - Sigstore transparency entry: 1155602804
- Sigstore integration time:
-
Permalink:
vcollab/vcti-python-path-tree@67996d36e93b08e671ff46109b2971c3ac8c63dd -
Branch / Tag:
refs/heads/main - Owner: https://github.com/vcollab
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@67996d36e93b08e671ff46109b2971c3ac8c63dd -
Trigger Event:
workflow_dispatch
-
Statement type: