Skip to main content

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vcti_path_tree-1.1.1.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vcti_path_tree-1.1.1-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

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

Hashes for vcti_path_tree-1.1.1.tar.gz
Algorithm Hash digest
SHA256 b116fce33c89c9127b46e763147e79743467cf9df3e8e7822d5875e2c2083de4
MD5 65eeaee1c7c1cabb0ce44a79c1b167d0
BLAKE2b-256 6e6ab6e468a907508975198a7cbf705eb9cb659b9875aedb390c789fa933ed8b

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for vcti_path_tree-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d36967ac302109bafe3f7d7f244975187d36906f95ed528f214df103271f30b0
MD5 ae0bd7d8975fcc3b395723f14114cbc6
BLAKE2b-256 3b474f275551f3fabe72da0589e9cc498206baf7e20da7f22d37fa3e98ce0c15

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page