Generate annotated file tree structures with descriptions from file comments
Project description
Annotree - Automatic Annotated File Trees for Python ๐ณ
Annotree is the easiest way to generate annotated project file trees in Python, automatically pulling descriptions from your Python-style docstrings and comments. Perfect for README files, documentation, and quick project overviews.
๐ Table of Contents
โก Key Features
- ๐ง Automatic Annotations โ Pulls descriptions from first lines, comments, or
__init__.pydocstrings - ๐ Directory Descriptions โ Folders inherit descriptions from
__init__.py - ๐ซ Smart Ignore Support โ Honors
.treeignoreor.gitignoreautomatically - ๐จ Clean, Aligned Output โ Beautiful tree structure with readable annotations
- โ๏ธ Customizable โ Control depth, output format, and annotation alignment
- ๐ Python API & CLI โ Use as a library or from the command line
- ๐ Pre-commit Hook Support โ Auto-update file trees in your README on every commit
๐ป Installation
Using uv (recommended)
uv pip install annotree
Using pip
pip install annotree
For Development
git clone https://github.com/yourusername/annotree.git
cd annotree
uv pip install -e .
๐ Usage
Command Line
# Generate tree in current directory
annotree
# Specify output file
annotree -o structure.txt
# Limit depth to 2 levels
annotree -l 2
# Show directories only
annotree -d
# Disable annotations for cleaner output
annotree --no-annotate
# Combine options: depth 3, no annotations, custom output
annotree -l 3 --no-annotate -o docs/structure.txt
# Embed tree into README between HTML comment tags
annotree --embed README.md -l 2 --no-annotate
# Use custom ignore file
annotree -i .customignore -o tree.txt
# Customize annotation alignment (default: 42)
annotree -a 60 -o tree.txt
Python API
from pathlib import Path
from annotree import tree, embed_tree_in_file
# Basic usage
tree(Path.cwd(), output_file="tree.txt")
# Custom options
tree(
Path.cwd(),
ignore_file=".treeignore",
level=3,
output_file="tree.txt",
annotation_start=50,
annotate=False # Disable annotations
)
# Directories only
tree(Path.cwd(), limit_to_directories=True, output_file="dirs_only.txt")
# Embed into a file between tags
embed_tree_in_file(
target_file=Path("README.md"),
dir_path=Path.cwd(),
level=2,
annotate=False
)
๐ .treeignore
Create a .treeignore file in your project root to filter files specifically for Annotree (independent of .gitignore):
__pycache__/
*.pyc
.pytest_cache/
.venv/
node_modules/
dist/
build/
- If
.treeignoreexists, Annotree uses it automatically. - Otherwise,
.gitignoreis respected if present.
๐ Pre-commit Integration
You can use Annotree as a pre-commit hook to automatically keep a file (for example README.md) in sync with your repository layout.
Setup
-
Add start/end tags where you'd like the tree inserted in your
README.md: -
Configure a pre-commit hook in your
.pre-commit-config.yaml:repos: - repo: https://github.com/suecrumpler/annotree rev: main hooks: - id: annotree-readme name: Annotree README entry: annotree --embed README.md -l 2 language: system pass_filenames: false files: '\\.(py|md)$'
-
Install the hook:
pre-commit install
Now every time you commit, the file tree in your README will be automatically updated!
Example: This Repository
This repository uses Annotree itself! The file structure below is auto-updated by the pre-commit hook:
โโ annotree # annotree package - Generate annotated file trees with descriptions from file comments
โ โโ __init__.py
โ โโ __main__.py # Command-line interface for annotree
โ โโ annotree.py # Core tree generation logic
โ
โโ tests # Test suite for annotree package
โ โโ __init__.py
โ โโ test_annotree.py # Unit tests for annotree core functionality
โ
โโ .bumpversion.toml # Version bumping config
โโ .gitignore # .gitignore file for Python projects
โโ .pre-commit-config.yaml # Pre-commit hooks configuration
โโ .treeignore # This file is used specifically for ignoring files for tree generation
โโ LICENSE # MIT License
โโ README.md # Annotree - Automatic Annotated File Trees for Python ๐ณ
โโ pyproject.toml # Project configuration for build, tools, and dependencies
โโ ruff.toml # Ruff configuration
2 directories, 13 files
๐ License
License MIT see LICENSE for details.
๐ค Contributing
Contributions welcome! Feel free to submit a Pull Request or open an Issue.
๐ Links
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 annotree-0.2.0.tar.gz.
File metadata
- Download URL: annotree-0.2.0.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68c9d81ff9137a3d6653e0793d2201b9b14a9d38221faf1056aabcd7d798a970
|
|
| MD5 |
52ce63ba2cfe3f635754a8388fd1b7e8
|
|
| BLAKE2b-256 |
af5da1241001416543841b957092129f525083f5747c31323570c31b867b00e0
|
File details
Details for the file annotree-0.2.0-py3-none-any.whl.
File metadata
- Download URL: annotree-0.2.0-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa3f6489176216d3cd8e32868d464c35d55e18953ed24cd54a891894b1031f8c
|
|
| MD5 |
fac3934c9b8ac9d428cdf8b4c2629cf7
|
|
| BLAKE2b-256 |
d6915e2dc09d89df0fc6406b1b3df8fad7e22fd622d1daef8b666122803231c2
|