repo_to_prompt is a Python package that provides utilities for parsing a repository's file structure and source code into a formatted prompt. It can extract full file contents or only interface definitions from Python files. This tool is useful for generating structured representations of codebases, assisting in AI-powered code understanding, documentation, and summarization.
- Parse a repository (local directory or remote Git repository) into a structured prompt.
- Extract and format folder tree structures.
- Process multiple file types, identifying their language based on extensions.
- Extract only interface definitions (classes, functions, and type annotations) from Python source files.
- Support
.gitignoreand.dixieignorefiles to exclude specific files and directories. - Command-line interface (CLI) for easy usage.
To install the package, clone the repository and install dependencies:
# Clone the repository $ git clone https://github.com/your-repo/repo_to_prompt.git # Navigate to the directory $ cd repo_to_prompt # Install dependencies $ pip install -r requirements.txtAlternatively, you can install it as a package:
$ pip install repo_to_promptYou can use the repo_to_prompt CLI to generate a structured prompt from a local directory or a Git repository.
$ python -m repo_to_prompt.cli --path <path-to-repo>To extract only class and function signatures from Python files:
$ python -m repo_to_prompt.cli --path <path-to-repo> --interfaces-onlyIf the provided path is a Git repository URL, it will be cloned into a temporary directory before processing:
$ python -m repo_to_prompt.cli --path https://github.com/user/repo.git- Provides a command-line interface.
- Accepts a repository path (local or remote Git repository).
- Calls
FolderParserto generate a structured prompt.
- Parses a folder structure, extracting file content and metadata.
- Uses
IgnoreSpecto respect.gitignoreand.dixieignorerules. - Builds a formatted tree representation of the repository.
- Calls
extract_interfaces.pyif the--interfaces-onlyflag is enabled.
- Parses Python source files using the AST (Abstract Syntax Tree).
- Extracts class and function signatures, along with docstrings.
- Removes implementation details to create an interface-only representation.
- Initializes the
repo_to_promptpackage.
When running repo_to_prompt on a sample project, the output follows this structure:
* Folder tree * repo/ |-- main.py |-- utils.py |-- config/ | |-- settings.py `-- README.md * Sources * ** FILE: repo/main.py ** ```python import os def hello(): """Prints a greeting message.""" print("Hello, world!") If `--interfaces-only` is specified: ```text ** FILE: repo/main.py ** ```python def hello(): """Prints a greeting message.""" ## License This project is licensed under the Apache License 2.0. See the `LICENSE` file for details. ## Author Created by **Sergei Belousov**.