Skip to main content

Generate annotated file tree structures with descriptions from file comments

Project description

Annotree - Automatic Annotated File Trees for Python ๐ŸŒณ

PyPI version Python Support

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__.py docstrings
  • ๐Ÿ“ Directory Descriptions โ€“ Folders inherit descriptions from __init__.py
  • ๐Ÿšซ Smart Ignore Support โ€“ Honors .treeignore or .gitignore automatically
  • ๐ŸŽจ 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 .treeignore exists, Annotree uses it automatically.
  • Otherwise, .gitignore is 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

  1. Add start/end tags where you'd like the tree inserted in your README.md:

    alt text

  2. 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)$'
    
  3. 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


Download files

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

Source Distribution

annotree-0.2.0.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

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

annotree-0.2.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

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

Hashes for annotree-0.2.0.tar.gz
Algorithm Hash digest
SHA256 68c9d81ff9137a3d6653e0793d2201b9b14a9d38221faf1056aabcd7d798a970
MD5 52ce63ba2cfe3f635754a8388fd1b7e8
BLAKE2b-256 af5da1241001416543841b957092129f525083f5747c31323570c31b867b00e0

See more details on using hashes here.

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

Hashes for annotree-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aa3f6489176216d3cd8e32868d464c35d55e18953ed24cd54a891894b1031f8c
MD5 fac3934c9b8ac9d428cdf8b4c2629cf7
BLAKE2b-256 d6915e2dc09d89df0fc6406b1b3df8fad7e22fd622d1daef8b666122803231c2

See more details on using hashes here.

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