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
- Usage
- Options
- Examples
- Python API
- Sample Output
- Features
- Release History
- Authors
- License
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,--helpShow help message-v,--versionShow version
Modes
-do,--dir-onlyShow directories only-fo,--files-onlyShow files only
Ordering
-d,--dirs-firstList directories before files-f,--files-firstList files before directories
Alphabetical order is always applied as base sorting.
Display
-n,--no-pipesRemove vertical pipes between branches
Ignoring
-g [DIR ...],--git [DIR ...]Ignore.gitfolder and respect rules from given.gitdirectories or directories containing.git(defaults to current dir if omitted but flag is used)-gi [DIR_OR_FILE ...],--gitignore [DIR_OR_FILE ...]Respect.gitignorerules from given paths/dirs (defaults to current dir if omitted)-i,--ignore PATTERN [PATTERN ...]Ignore files/directories
Depth
-dl,--depth-level NLimit depth
Examples
Basic:
pyletree
Directories first:
pyletree . -d
Files only:
pyletree . -fo
Limit depth:
pyletree . -dl 2
Ignore entries:
pyletree . -i node_modules dist .git
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
.gitignoresupport (it does not ignore either the.gitdirectory or the.gitignorefile; 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.0.1
-g/--gitnow accepts only directories or.gitdirectories, or directories containing a.gitfolder.-gi/--gitignorecontinues to accept either a.gitignorefile 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 parameterNto 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.- Global File Filter: support for excluding/including files based on patterns or extensions.
- Add patterns to
-i/--ignoreoption.
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-fileoption - Added
FileTreeclass 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
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 pyletree-2.0.1.tar.gz.
File metadata
- Download URL: pyletree-2.0.1.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a14800fd3a66f996b5fcb89e5d7612fc8d4cbe340159b4932c2453cf8437372a
|
|
| MD5 |
db6591586a4feb9f3bf67c726440f692
|
|
| BLAKE2b-256 |
2e6208269c7883349486bc56e5ad91c492324e43b9c31c8415f2582d182bdce7
|
File details
Details for the file pyletree-2.0.1-py3-none-any.whl.
File metadata
- Download URL: pyletree-2.0.1-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c5504306f3c8352652314520b3cf9e02e72c16d4faa9edfda94f37901fdfce8
|
|
| MD5 |
f4a360c2869fe96d02ec77d834365997
|
|
| BLAKE2b-256 |
1cbb0c94d91cf327071d658d554aee155c4d93c6eaccfceb119d20df9cc87cd5
|