Skip to main content

A CLI tool and library to create directory trees from tree strings.

Project description

creatree

PyPI version License

A Python package and CLI tool for creating directory structures from a tree-like string.

Overview

creatree is a simple yet powerful tool that allows you to define directory structures using a human-readable text format and then create those structures automatically in your filesystem. This is particularly useful for quickly setting up project templates, scaffolding applications, or sharing directory structures in documentation.

Motivation

This project was born out of a major pain point I faced repeatedly—manually creating project structures whenever I started a new project. Since I mostly adhere to the same structure unless there’s a specific need to modify it, I wanted a simple and efficient way to automate this process. Unfortunately, I couldn't find any good tools that fit my workflow.

Additionally, I often write proof-of-concept (POC) functionalities in a Jupyter notebook and later ask ChatGPT to break them down into a structured project format, including a tree with comments. creatree bridges this gap by allowing me to quickly generate well-organized project directories without unnecessary manual effort.

Installation

Using uv

To install creatree as a uv tool, run:

uv tool install creatree

Using pip

Alternatively, install creatree via pip:

pip install creatree

Usage

As a Python Library

You can use creatree programmatically to generate directory structures.

Example Usage

from creatree import creatree, tree_to_dict

# Define a directory tree as a string
tree = '''
example_project/ # Project root
├── main.py # Main entry point
├── config.yaml # Configuration file
├── src/ # Source code directory (Not empty)
│   ├── app.py # Application logic
│   └── utils.py # Utility functions
├── empty_directory/ # Empty directory (This will be created as it ends with /)
└── xyz_file # This will be created as a file as it doesn't end with /
'''

# Convert the tree string to a dictionary
tree_dict = tree_to_dict(tree, include_comments=False)
print(tree_dict)

# Create the directory structure in the current directory
# For each file that has a comment, it will be added to the file as a comment (Think of it like a TODO, except it's not explicit)
creatree(tree, where_to_create=".")

As a CLI Tool

Create a directory tree from a file

If you have a text file (for example, tree.txt) containing the directory structure, you can create it using:

creatree tree.txt -w .

Use pipe to create directory trees

You can also define a directory tree inline using pipes:

echo "root1/
├── a # This comment will not be present in the a directory :(
│   ├── b.py # This comment will be added to b.py as a comment :)
│   └── c.py
├── d/
└── e.py" | creatree -w .

Generate a directory tree from an existing structure

You can capture an existing directory structure and replicate it elsewhere using tree and creatree:

tree /path/to/existing/directory | creatree -w /path/to/new/location

Comparison with Other Tools

While there are other tools available for scaffolding projects, creatree offers a unique approach by allowing users to define directory structures in a simple, tree-like string format. This method provides a clear and concise way to visualize and create complex directory hierarchies without the need for extensive configuration files or templates.

Features

  • Convert a tree string to a structured dictionary.
  • Generate directory structures automatically.
  • Supports both Python API and CLI usage.
  • Works with standard input (stdin) for flexible scripting.
  • Useful for setting up project templates and scaffolding.
  • Supports nested directory structures with file placeholders.
  • Lightweight and easy to use.

How to Contribute

We welcome contributions from the community! Here's how you can get involved:

  1. Fork the Repository: Click on the 'Fork' button at the top right of the repository page to create a copy of the repository on your GitHub account.

  2. Clone the Forked Repository: On your local machine, clone the forked repository using:

    git clone https://github.com/[yourusername]/creatree.git
    cd creatree
    
  3. Create a New Branch: Create a new branch for your feature or bug fix:

    git checkout -b feature-name
    
  4. Make Your Changes: Implement your feature or fix the bug in your branch.

  5. Commit Your Changes: Commit your changes with a descriptive commit message:

    git commit -m "Description of the feature or fix"
    
  6. Push to GitHub: Push your changes to your forked repository:

    git push origin feature-name
    
  7. Create a Pull Request: Go to the original repository and create a pull request from your forked repository. Provide a clear description of your changes and the motivation behind them.

Before contributing, please ensure that your code adheres to the project's coding standards and that all tests pass. If you're adding a new feature, consider including tests to cover the new functionality.

License

creatree is released under the MIT License, allowing free use, modification, and distribution.

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

creatree-0.1.3.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

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

creatree-0.1.3-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for creatree-0.1.3.tar.gz
Algorithm Hash digest
SHA256 2df331c09b59207a73c2a75e8e18bc2b4d74c26bd7980ad0da978e737a33b4a1
MD5 e3a5c6ea78a43e0debcf610bd143ce80
BLAKE2b-256 1236f07199b7f5c009702c85f5f478bc3203e9fead658cbfb7dbb90e50a6fe4b

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for creatree-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c2619cd641c96a2ea411f35b73c158e85174c01fec12547d67d0a3e3332089f2
MD5 a13076bf75447637f623120f3e54e79e
BLAKE2b-256 044db7747b967482f028079bade82b3991dfb87509926a220681008484b3143b

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