Skip to main content

A customizable tree-like directory viewer with filtering, depth control, and statistics

Project description

ltree

ltree is a fast, highly customizable CLI utility used to visualize directory structures in a tree diagram. It features beautiful Rich UI console formatting, robust icon theme support (Nerd Font / Emoji), detailed metrics tracking, and versatile exporters (JSON, YAML, Markdown, HTML, and Graphviz).

>>> ltree tree ltree/core --no-mtime --no-git --no-perm
  ๐Ÿ“‚ core/
  โ”œโ”€โ”€ ๐Ÿ __init__.py
  โ”œโ”€โ”€ ๐Ÿ config.py
  โ”œโ”€โ”€ ๐Ÿ“‚ filters/
  โ”‚   โ”œโ”€โ”€ ๐Ÿ __init__.py
  โ”‚   โ”œโ”€โ”€ ๐Ÿ base.py
  โ”‚   โ”œโ”€โ”€ ๐Ÿ depth.py
  โ”‚   โ”œโ”€โ”€ ๐Ÿ folders.py
  โ”‚   โ”œโ”€โ”€ ๐Ÿ pipeline.py
  โ”‚   โ””โ”€โ”€ ๐Ÿ sorting.py
  โ”œโ”€โ”€ ๐Ÿ“‚ metadata/
  โ”‚   โ”œโ”€โ”€ ๐Ÿ __init__.py
  โ”‚   โ”œโ”€โ”€ ๐Ÿ base.py
  โ”‚   โ”œโ”€โ”€ ๐Ÿ code.py
  โ”‚   โ”œโ”€โ”€ ๐Ÿ filesystem.py
  โ”‚   โ”œโ”€โ”€ ๐Ÿ git.py
  โ”‚   โ”œโ”€โ”€ ๐Ÿ models.py
  โ”‚   โ”œโ”€โ”€ ๐Ÿ project.py
  โ”‚   โ”œโ”€โ”€ ๐Ÿ registry.py
  โ”‚   โ””โ”€โ”€ ๐Ÿ time.py
  โ”œโ”€โ”€ ๐Ÿ models.py
  โ”œโ”€โ”€ ๐Ÿ“‚ scanners/
  โ”‚   โ”œโ”€โ”€ ๐Ÿ __init__.py
  โ”‚   โ”œโ”€โ”€ ๐Ÿ aggregation.py
  โ”‚   โ”œโ”€โ”€ ๐Ÿ filters.py
  โ”‚   โ”œโ”€โ”€ ๐Ÿ scanner.py
  โ”‚   โ”œโ”€โ”€ ๐Ÿ sorting.py
  โ”‚   โ”œโ”€โ”€ ๐Ÿ subtree.py
  โ”‚   โ””โ”€โ”€ ๐Ÿ traversal.py
  โ””โ”€โ”€ ๐Ÿ utils.py

Summary:
Visible:   3 directories,  26 files
Total  :   3 directories,  26 files

Installation

You can install ltree directly from PyPI:

# Using pip
pip install ltree-cli

# Or using uv
uv pip install ltree-cli

For local development or source installations:

# Clone the repository
git clone https://github.com/YuHao-Yeh/ltree.git
cd ltree

# Install in editable mode using uv
uv pip install -e .

# Or using standard pip
pip install -e .

VS Code Extension

ltree now comes with an official VS Code companion!

  • Quick Action: Right-click any workspace file or folder in the explorer sidebar to generate a structure diagram.
  • Multiple Formats: Select your desired generation format (Markdown List, JSON, Plain Text, or Markdown Code Blocks).
  • Customizable: Seamlessly pass any CLI arguments directly from your VS Code Settings or input boxes.
  • Convenience: The generated tree diagram will automatically save to your system clipboard for instant sharing.

To get started, check the ltree-vscode directory for detailed installation instructions.


Command-Line Usage

ltree organizes its functionality through logical subcommands.
Run ltree --help to inspect the full list of available subcommands.

1. The tree Subcommand

Generate a directory tree diagram with advanced filtering, metadata inspection, and custom outputs.

[!TIP] Executing ltree directly with a directory path or without any arguments automatically falls back to invoking the tree subcommand.

# Explicitly generate a tree
ltree tree [path] [options]

# Shortcut fallback (automatically executes the 'tree' subcommand)
ltree [path] [options]

Command Options

Run ltree tree --help to see the full list of available parameters.

View Full Parameter List

Basic Options

Argument Short Default Description
start_path . Starting directory path.
--output -o - Output file name. Use - for standard outout (stdout).

Formatting & Theme

Argument Short Default Description
--format -F text Output format. Choices: text, json, yaml, md, markdown, block, rich, html, graphviz.
--theme emoji Default icon style. Choices: emoji, nerd, none.
--color, --no-color -c Auto Toggles ANSI colored output.

Metadata Flags

Argument Short Description
--perm, --no-perm Toggle filesystem permissions (e.g., drwxr-xr-x). Default: active.
--git, --no-git Toggle git tracking and modification states. Default: active.
--size, --no-size -s Display file and aggregated directory sizes in bytes.
--human -H Formats size displays to human-readable scales (e.g., 1.5 K, 2.0 M).
--mtime, --no-mtime Toggle modification timestamps. Default: active.
--code, --no-code Toggle lightweight programming language.
--project, --no-project Toggle configurations parsing for project metadata (e.g., package names and version).

Filtering & Exclusions

Argument Short Description
--all -a Process hidden files and directories (starting with .).
--dirs-only -d Exclude file entries entirely from visualization layout.
--exclude -I Exclude paths matchin literal strings or wildcard patterns (e.g., dist/, *.log).
--include -A Re-include paths previously matching an exclusion filter.
--re-ex Exclude paths matching a specific Python regular expression.
--gitignore, --no-gitignore Toggle automatic evaluation of .gitignore exclusion configurations.
--ex-dirs Legacy: Exclude specific directories.
--ex-files Legacy: Exclude files (supports wildcards like *.log).
--ex-ext Legacy: Exclude by file extension (e.g., .log).
--ex-prefix Legacy: Exclude items by prefix.
--add-dirs Legacy: Re-include specific excluded directories.
--add-files Legacy: Re-include specific excluded files.

Display Configurations

Argument Short Description
--max-depth -L Restruct recursive scanning depth to a maximum integer.
--full-path -f Print the full relative path prefix instad of just the entry name.
--dirs-first List directories before files.
--ellipsis Render an ellipsis (...) showing truncated file statisticss on depth-limited branches.

Examples

# Display current directory structure
ltree tree

# Output to console with color
ltree tree . -o - --color

# Save tree to a file
ltree tree /path/to/dir -o tree.txt

# For more help
ltree tree --help

Quick Configuration Presets

Click to expand configuration presets
Use Case Command
Export structure as JSON ltree tree -F json -o data.json
Markdown List layout ltree tree -F md -o report.md
Markdown Text Block layout ltree tree -F block -o report.md
Restrict sacn depth ltree tree -L 2 --ellipsis
Filter by Pattern ltree tree -I *.log -I *.tmp
Filter by Regex ltree tree --re-ex "test_.*\.py"
Directories-only Visualization ltree tree -d --dirs-first
File size metrics ltree tree -s -H
Rich + Nerd Fonts ltree tree . -F rich --theme nerd

2. The theme Subcommand

Discovers, lists, or previews available icon mappings.

ltree theme [action] [argument]

Actions & Options

Click to expand action details
Action Argument Default Description
list Lists all registered icon themes with descriptions.
preview theme_name Renders directory, file, and symlink mockups for a specific theme. Choices: emoji, nerd, none.

Examples

# Discover what themes are built-in
ltree theme list

# Verify how Nerd Font glyphs render on your terminal environment
ltree theme preview nerd

3. The config Subcommand

Manage configuration files and setting profiles across workspaces.

ltree config [action] [start_path]

Actions & Options

Click to expand action details
Action Argument Default Description
show [start_path] . Resolves configurations at start_path (respecting settings hierarchies) and prints active configuration properties.
locate [start_path] . Searches upwards from start_path and prints the locations of discovered .ltreerc or pyproject.toml files.
validate [start_path] . Inspects and validates the formatting syntax of setting profiles found in the recursive path.

Examples

# Print the merged configuration properties currently in effect.
ltree config show [start_path]

# Trace and locate setting files up through parent directories
ltree config locate [start_path]

# Validate setting syntaxes and formats for setting profiles
ltree config validate [start_path]

Configuration

You can store configuration options in local files to aviod passing them manually on every run. ltree automatically scan upwards for the following configuration targets:

  • .ltreerc (JSON formatted configuration)
  • pyproject.toml (defined under the [tool.ltree] section)

Precedence Priority

Settings are merged and overridden with the following priority order:

  1. Command Line Arguments
  2. Local Configuration File (.ltreerc or pyproject.toml)
  3. Global Default Configurations

Examples

.ltreerc (JSON)

{
  "theme": "nerd",
  "size": true,
  "human": true,
  "dirs_first": true,
  "exclude": ["dist", "build", "target", "*.log", "*.tmp"]
}

pyproject.toml (TOML)

[tool.ltree]
theme = "emoji"
full_path = true
color = true
size = true
include = ["output", "temp"]

Output Examples

Plain Text (-F text)

ltree/
โ”œโ”€โ”€ ltree/
โ”‚   โ”œโ”€โ”€ core.py
โ”‚   โ””โ”€โ”€ exporters.py
โ”œโ”€โ”€ tests/
โ””โ”€โ”€ README.md

Summary:
Visible:   2 directories,   3 files
Total  :   2 directories,   3 files

Rich UI & Nerd Fonts (-F rich --theme nerd)

๏ป ltree/
โ”œโ”€โ”€ ๏ป ltree/
โ”‚   โ”œโ”€โ”€ ๎˜† core.py
โ”‚   โ””โ”€โ”€ ๎˜† exporters.py
โ”œโ”€โ”€ ๏’™ tests
โ””โ”€โ”€ ๏’Š README.md

Summary:
Visible:   2 directories,   3 files
Total  :   2 directories,   3 files

Markdown Lists (-F md)

  • ๐Ÿ“‚ ltree/
    • ๐Ÿ core.py
    • ๐Ÿ exporters.py
  • ๐Ÿ“‚ tests/
  • ๐Ÿ“– README.md

System Architecture

ltree is designed as a modular pipeline, where each stage has a single responsibility.

              CLI
               โ”‚
               โ–ผ
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚     Configuration    โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
               โ”‚
               โ–ผ
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚       Scanner        โ”‚
    โ”‚ โ€ข Traversal          โ”‚
    โ”‚ โ€ข Filters            โ”‚
    โ”‚ โ€ข Metadata Providers โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
               โ”‚
               โ–ผ
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚      Tree Model      โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
               โ”‚
               โ–ผ
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚      Serializer      โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
               โ”‚
               โ–ผ
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚       Renderer       โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
               โ”‚
               โ–ผ
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚       Exporter       โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
               โ”‚
               โ–ผ
        Console / File
  • Configuration โ€“ Resolves command-line arguments and configuration files into a unified TreeConfig.
  • Scanner โ€“ Traverses the filesystem, applies filters, and collects metadata.
  • Tree Model โ€“ Stores the scanned directory hierarchy in memory.
  • Serializer โ€“ Converts the tree model into a renderer-independent representation.
  • Renderer โ€“ Produces output in the selected format.
  • Exporter โ€“ Writes the rendered output to the console or a file.

Each layer has a single responsibility and can be extended independently, making ltree easy to customize and maintain.


License

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

ltree_cli-0.3.0.tar.gz (45.0 kB view details)

Uploaded Source

Built Distribution

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

ltree_cli-0.3.0-py3-none-any.whl (61.3 kB view details)

Uploaded Python 3

File details

Details for the file ltree_cli-0.3.0.tar.gz.

File metadata

  • Download URL: ltree_cli-0.3.0.tar.gz
  • Upload date:
  • Size: 45.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ltree_cli-0.3.0.tar.gz
Algorithm Hash digest
SHA256 37c598476f93ed654c6cbd0c4a719f136351af39c1de9c280cca2eb068363f12
MD5 9fbd2033cbb76cb563c5aefd5598adf9
BLAKE2b-256 fd8a3e7f925a04ca007675e1f475f2c94487124be1dab809228197ed4f13ced2

See more details on using hashes here.

Provenance

The following attestation bundles were made for ltree_cli-0.3.0.tar.gz:

Publisher: publish.yml on YuHao-Yeh/ltree

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ltree_cli-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: ltree_cli-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 61.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ltree_cli-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dadbc42ffabd674aefb92f6a46ce7e3b44c06193c9a7339099df92d1933896ed
MD5 c8d0a7370e912353bc37d8822704b194
BLAKE2b-256 bf1d8f95b21949d527d57933cbc55399eaab588ee378e85166a3e541aeedc780

See more details on using hashes here.

Provenance

The following attestation bundles were made for ltree_cli-0.3.0-py3-none-any.whl:

Publisher: publish.yml on YuHao-Yeh/ltree

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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