Skip to main content

Generate directory structures from ASCII art or Markdown files

Project description

mdirtree

Generate directory structures from ASCII art or Markdown files.

Overview

mdirtree is a command-line tool that converts ASCII directory trees into actual directory structures. It can parse trees from various sources, including plain text files, standard input, or code blocks within Markdown files.

This is useful for quickly setting up project scaffolding, creating test directories, or documenting and implementing directory structures defined in documentation.

Features

  • Generate directory structure from ASCII tree diagrams
  • Support for Markdown and text files
  • Interactive input mode
  • Dry run mode
  • Comment support (using # after file/directory names)
  • Special handling for common files (README.md, init.py, etc.)
  • REST API for remote directory generation

Installation

Via pip

pip install mdirtree

Setting up a development environment

Create a virtual environment:

python -m venv venv

Activate the virtual environment:

source venv/bin/activate  # On Windows: venv\Scripts\activate

Install dependencies:

pip install --upgrade pip
pip install -r requirements.txt

Install in development mode:

pip install -e .

Usage

Basic usage

# Generate from Markdown file
mdirtree structure.md -o ./output_dir

# Generate from text file
mdirtree structure.txt -o ./output_dir

# Generate from stdin
mdirtree - -o ./output_dir

# Dry run (show planned operations without creating files)
mdirtree --dry-run structure.md

# Enable verbose logging
mdirtree -v structure.md -o ./output_dir

Command-line Options

usage: mdirtree [-h] [--output OUTPUT] [--dry-run] [--verbose] [input]

Generate directory structure from ASCII art or Markdown files

positional arguments:
  input                 Input file (*.md, *.txt) or - for stdin

options:
  -h, --help            show this help message and exit
  --output OUTPUT, -o OUTPUT
                        Output directory (default: current directory)
  --dry-run, -d         Show planned operations without creating files
  --verbose, -v         Enable verbose logging

Input Format Example

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

REST API

mdirtree also offers a REST API for generating directory structures:

Starting the server

from mdirtree.rest.server import run_server

run_server(host='0.0.0.0', port=5000)

Using the client

from mdirtree.rest.client import MdirtreeClient

client = MdirtreeClient('http://localhost:5000')

structure = """
project/
├── src/
│   └── main.py
└── tests/
    └── test_main.py
"""

# Generate structure
result = client.generate_structure(structure, output_path="./output")
print(result)

# Dry run mode
result = client.generate_structure(structure, dry_run=True)
print(result)

REST API Endpoints

  • POST /generate
    • Request body:
      {
          "structure": "ASCII art structure",
          "output_path": "optional output path",
          "dry_run": false
      }
      
    • Response:
      {
          "status": "success",
          "operations": ["list of operations"],
          "output_path": "output path"
      }
      

License

LICENSE

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

mdirtree-0.1.3.tar.gz (26.7 kB view details)

Uploaded Source

Built Distribution

mdirtree-0.1.3-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file mdirtree-0.1.3.tar.gz.

File metadata

  • Download URL: mdirtree-0.1.3.tar.gz
  • Upload date:
  • Size: 26.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for mdirtree-0.1.3.tar.gz
Algorithm Hash digest
SHA256 19d3f923ae9973c920caecb149b7ce02c6767b0f19cbeeba4be2173fee11c2da
MD5 b7444bc4ea8dacb745274583aaf10007
BLAKE2b-256 e000391000d3ccdecc553d254b6201f2cef6ca4b9a048f4f63450da38079966d

See more details on using hashes here.

File details

Details for the file mdirtree-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: mdirtree-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for mdirtree-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 352aa447c3f0d8bf840576634bc573ecce7daff96e28a3763ce6d16a970d5fee
MD5 45c1c447e979afacee32d4f4ea677560
BLAKE2b-256 0291a42036551875622767e39c1c3f1846dbc1c97550eedddb7c5aa142baad15

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page