Directory tree generator — a simple CLI tool for visualising directory structures
Project description
structree
structree is a lightweight command-line utility written in Python that generates a visual directory tree, similar to the Unix tree command. The output can be saved to a file or printed directly to the console.
Works on Windows, macOS, and Linux.
Features
- Generate a directory tree structure
- Ignore specific files or folders (comma-separated)
- Show only files or only directories
- Output to a file or directly to stdout
- Zero external dependencies — pure Python standard library
Installation
Via pip / uv (from PyPI)
pip install structree
# or
uv tool install structree
From source
git clone https://github.com/KaifKol/py-structree.git
cd structree
uv tool install .
# or for development:
uv sync
Usage
structree -p <path> [options]
If run without any arguments, the help message is displayed.
Options
| Option | Description |
|---|---|
-p, --path |
Target directory (. , relative, or full path) (required) |
-o, --out |
Output file name (default: tree.txt) |
-i, --ignore |
Comma-separated list of files/folders to ignore |
-f, --files-only |
Show only files |
-d, --dirs-only |
Show only directories |
-s, --stdout |
Print output to console instead of writing to a file |
--version |
Show version number and exit |
Examples
1. Generate a tree for the current directory
structree -p .
Creates tree.txt inside the target directory.
2. Ignore folders like .git and node_modules
structree -p . -i .git,node_modules
3. Print the tree directly to the console
structree -p . -s
4. Show only files
structree -p . -f
5. Show only directories
structree -p . -d
6. Run as a Python module
python -m structree -p . -s
Example Output
Assume the following directory structure:
project/
├── main.py
├── utils.py
├── README.md
└── src/
├── core.py
└── helpers.py
Running:
structree -p project -s
Will output:
project/
├── README.md
├── main.py
├── utils.py
└── src
├── core.py
└── helpers.py
Development
# Clone and enter the project
git clone https://github.com/KaifKol/py-structree.git
cd structree
# Create a virtual environment and install dependencies
uv sync
# Run tests
uv run pytest
# Install as a CLI tool (global)
uv tool install .
# Run with uv (no install needed)
uv run structree -p . -s
Publishing to PyPI
# Build the package
uv build
# Upload to PyPI
uv publish
Notes
- The output uses Unicode box-drawing characters (
├──,└──,│) - Permission errors are silently skipped
- When writing to a file, it is created inside the target directory
License
MIT © KaifKol
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 structree-1.0.0.tar.gz.
File metadata
- Download URL: structree-1.0.0.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e83a1963b6a768573b681a4356443bbf62f2b8d9e74c08787657f5032592cd20
|
|
| MD5 |
560d9f05cc4e3bad746cbac22db4cf51
|
|
| BLAKE2b-256 |
aeaa722eb5728f012957c63e6e9adf9e1dc44362771b6dcc2781dcab44b53c33
|
File details
Details for the file structree-1.0.0-py3-none-any.whl.
File metadata
- Download URL: structree-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a373ca8a2befe1334c8fc87d984150698a8d163e41fa9a18ff6c92499a4e4d6
|
|
| MD5 |
2218159605e72e8ed48426f40f202ed7
|
|
| BLAKE2b-256 |
38f6e1328d3c37531149d7a913dbfba163aecaab7d6380314e06e0615939523c
|