Skip to main content

treeproject

treeproject is a lightweight Python library providing simple, deterministic utilities to:

  • render a directory structure as a readable Unicode tree,
  • extract and concatenate file contents into a single structured text bundle.

It is designed for documentation, debugging, tooling, and building compact filesystem context bundles (for example, for LLM prompts).

The API is intentionally minimal, dependency-free, and based on pathlib.Path.


Installation

pip install treeproject

Requires Python 3.10+.


Features

  • Unicode tree rendering (similar to the Unix tree command)
  • Deterministic traversal (directories first, case-insensitive sorting)
  • Strict pruning-based filtering
  • Optional symbolic link traversal
  • Text content extraction with stable formatting
  • Binary file detection and skipping
  • Configurable encoding and error handling
  • Zero runtime dependencies

Quick Start

Render a directory tree

from pathlib import Path
from treeproject import path_tree

print(path_tree(Path("./my_project")))

Example output:

my_project
├── README.md
├── pyproject.toml
└── src
    ├── __init__.py
    └── app.py

Extract file contents

from pathlib import Path
from treeproject import path_content

bundle = path_content(Path("./my_project"))
print(bundle)

Example output format:

===== FILE: README.md =====
# My Project
...
===== END FILE =====

===== FILE: src/app.py =====
print("hello")
===== END FILE =====

Filtering and Pruning

Filtering is controlled via an include(Path) -> bool predicate.

If the predicate returns False for a directory, the directory is pruned and none of its descendants are visited.

IGNORE = {".git", "__pycache__", ".pytest_cache"}

def include(p: Path) -> bool:
    return p.name not in IGNORE

print(path_tree(Path("."), include=include))

The same predicate can be reused for content extraction.


API Reference

path_tree(root, *, follow_symlinks=False, include=lambda p: True) -> str

Render a Unicode directory tree and return it as a string.

  • Directories are listed before files
  • Sorting is case-insensitive
  • Excluded directories are fully pruned

`path_content(root, *, follow_symlinks=False, include=lambda p: True,

skip_binary=True, encoding="utf-8", errors="raise") -> str`

Walk a filesystem path and return a single string containing the formatted contents of all selected files.

  • Files are processed in deterministic order
  • Binary files can be skipped automatically
  • Errors can be raised or ignored per file

Design Notes

  • Uses pathlib.Path.walk for traversal
  • No global state
  • No side effects except explicit string rendering in path_tree
  • Suitable for programmatic use and automation

Development

git clone https://github.com/dylan-lebreton/treeproject
cd treeproject
poetry install
pytest

License

MIT License

Copyright (c) 2025 Dylan Lebreton

Metadata

Release files for treeproject 2.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 treeproject 2.0.0
File Size Uploaded Provenance
treeproject-2.0.0.tar.gz 6.6 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 15.2 kB

Release files / treeproject-2.0.0.tar.gz

Download URL treeproject-2.0.0.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b07e9cd91f41faaa5122ec951421fd0bc2d56a161a84b90a591af6abda7552e1
BLAKE2b-256 checksum
How to use checksums
1c556cf11e2d8ad048aa406662d4020998993d0f93f6fd331c05e2b10a5a426e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.2 CPython/3.12.12 Linux/6.12.5-linuxkit

Release files / treeproject-2.0.0-py3-none-any.whl

Download URL treeproject-2.0.0-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6fe88c9086655af84ab5c9510b2196b8f1100ad85f529237e57663c022fb7b76
BLAKE2b-256 checksum
How to use checksums
5a766b318d226e58ddadca41faaf5900900dda5ba33ae1958984b7a133d990be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.2 CPython/3.12.12 Linux/6.12.5-linuxkit

Security for treeproject 2.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

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