Skip to main content

Generate directory tree diagrams from the command line

Project description

Pyletree


Pyletree is a simple and fast CLI tool to generate directory tree diagrams.

Table of Contents

Installation

From PyPI

pip install pyletree

Local

git clone https://github.com/davi-furtado/pyletree.git
cd pyletree
pip install -e .

Usage

pyletree [ROOT_DIR]

If no directory is provided, the current directory is used:

pyletree

Show help:

pyletree -h

Options

General

  • -h, --help Show help message
  • -v, --version Show version

Modes

  • -do, --dir-only Show directories only
  • -fo, --files-only Show files only

Ordering

  • -d, --dirs-first List directories before files
  • -f, --files-first List files before directories

Alphabetical order is always applied as base sorting.

Display

  • -n, --no-pipes Remove vertical pipes between branches

Ignoring

  • -g [DIR ...], --git [DIR ...] Ignore .git folder and respect rules from given .git directories or directories containing .git (defaults to current dir if omitted but flag is used)
  • -gi [DIR_OR_FILE ...], --gitignore [DIR_OR_FILE ...] Respect .gitignore rules from given paths/dirs (defaults to current dir if omitted)
  • -i, --ignore PATTERN [PATTERN ...] Ignore files/directories
  • -fi, --filter PATTERN [PATTERN ...] Include only files or directories matching gitignore-style patterns

Depth

  • -dl, --depth-level N Limit depth

Examples

Basic:

pyletree

Directories first:

pyletree . -d

Files only:

pyletree . -fo

Limit depth:

pyletree . -dl 2

Dictionary output:

pyletree . -dt 4

Ignore entries:

pyletree . -i node_modules dist .git

Filter entries with patterns:

pyletree . -fi *.py docs/

Use .gitignore:

pyletree . -gi

No pipes mode:

pyletree . -n

Python API

You can also use Pyletree programmatically in your own Python code using the FileTree class. It returns an iterable that can also be printed directly:

from pyletree import FileTree

# Create a tree for the current directory
tree = FileTree()

# Print the tree directly
print(tree)

# Or iterate over its lines
for line in tree:
    print(line)

# You can configure it with the same options of the CLI
custom_tree = FileTree(
    root_dir='src/',
    dir_only=True,
    ignore=['__pycache__']
)
print(custom_tree)

Sample Output

Default

project/
│
├── src/
│   ├── main.py
│   └── utils.py
│
├── tests/
│   └── test_main.py
│
└── README.md

No pipes (-n)

project/
├── src/
│   ├── main.py
│   └── utils.py
├── tests/
│   └── test_main.py
└── README.md

Features

  • Clean and readable tree output
  • .gitignore support (it does not ignore either the .git directory or the .gitignore file; if you want to ignore them, add them to the ignore patterns)
  • Custom ignore patterns
  • Depth limiting
  • Flexible sorting
  • Optional compact mode (--no-pipes)

Release History

2.3.0

Enhancements

  • Integrated -di/--dict-indent into -dt/--dict-tree.
    • Example: pyletree . -dt 4 (4-space indentation)
    • Example: pyletree . -dt 0 (compact, no indentation)

2.2.0

Enhancements

  • -dt/--dict-tree | Enhanced Dictionary Output: improved dictionary format with configurable indentation. Now returns {root: {tree...}} format and supports custom indentation via -dt N/--dict-tree N (default 2).
    • Example: pyletree . -dt 4 (4-space indentation)
    • Example: pyletree . -dt 0 (compact, no indentation)
    • Better structured output for programmatic use

2.1.0

New Features

  • -fi/--filter | Include Patterns: display only files and directories matching gitignore-style patterns. Supports multiple patterns and maintains tree hierarchy by including parent directories of matching files.
    • Example: pyletree . -fi *.py src/
    • Smart directory inclusion: shows parent folders even if they don't match the pattern directly
    • Caching optimization for large directory trees

2.0.1

  • -g/--git now accepts only directories or .git directories, or directories containing a .git folder.
  • -gi/--gitignore continues to accept either a .gitignore file or the containing directory.

2.0.0

Visual & Metadata

  • -p/--path-tree | Path Tree: generates a view focused exclusively on the paths of files and directories.
  • -o [N] | Text-Only Mode: generates the tree in plain text (without special characters). Accepts an optional parameter N to define the indentation (default: 2 spaces). Can't be used with -n.
  • -fs/--file-size | File Sizes: toggle visibility of individual file sizes.
  • -ds/--dir-size | Directory Sizes: display cumulative sizes for folders.
  • [-b/--big-first | -s/--small-first] | Smart Sorting: order tree entries by size (descending/ascending).

Filtering & Data Structures

  • -dt/--dict-tree | Dictionary format: output the tree structure as a native Python dictionary. Use -dt N/--dict-tree N for indentation (default 2). Format: {root: {tree...}}
  • Global File Filter: support for excluding/including files based on patterns or extensions.
  • Add patterns to -i / --ignore option.

API Enhancements

  • FileTree.getPath(name): new method to programmatically retrieve the full path of a specific file or directory within the tree.
  • Add dict(FileTree) method to convert the tree to a dictionary.
  • Add FileTree.getTree() method to convert the tree to a string.
  • Add FileTree.getDictTree() method to convert the tree to a dictionary.

1.1.0

  • Removed -o / --output-file option
  • Added FileTree class for programmatic usage in Python scripts.

1.0.0

  • Initial release

Authors

Davi Reis Furtado

Original RP Tree Author: Leodanis Pozo Ramos

License

Pyletree is distributed under the MIT license. See LICENSE for more information.

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

pyletree-2.3.0.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

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

pyletree-2.3.0-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file pyletree-2.3.0.tar.gz.

File metadata

  • Download URL: pyletree-2.3.0.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyletree-2.3.0.tar.gz
Algorithm Hash digest
SHA256 5cf42bb11575b0c4d511dae5f295131dc03491b0b082b05f38dcb477aeafc484
MD5 e5d39e2110b2c164323cd5f5c26b6860
BLAKE2b-256 36bca97dee0b397af108c443621a32439da445c46761c882fc0242e4557a9f39

See more details on using hashes here.

File details

Details for the file pyletree-2.3.0-py3-none-any.whl.

File metadata

  • Download URL: pyletree-2.3.0-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyletree-2.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e01145744cb89f00f2cbb7ec10ec4632ebe23c3fc4814ece9996c5c413266c13
MD5 a7ced5926b4edcf9cccfe8a7b0eb26d4
BLAKE2b-256 8a897087b49745377807f1f9e6ae640d9a36d9ad2a92e91cd7584e4f43c40997

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