Skip to main content

repo_to_prompt

Overview

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.

Features

  • 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 .gitignore and .dixieignore files to exclude specific files and directories.
  • Command-line interface (CLI) for easy usage.

Installation

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.txt

Alternatively, you can install it as a package:

$ pip install repo_to_prompt

Usage

Command-Line Interface

You can use the repo_to_prompt CLI to generate a structured prompt from a local directory or a Git repository.

Basic Usage

$ python -m repo_to_prompt.cli --path <path-to-repo>

Extract Only Interfaces

To extract only class and function signatures from Python files:

$ python -m repo_to_prompt.cli --path <path-to-repo> --interfaces-only

Parsing a Git Repository

If 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

Module Descriptions

repo_to_prompt/cli.py

  • Provides a command-line interface.
  • Accepts a repository path (local or remote Git repository).
  • Calls FolderParser to generate a structured prompt.

repo_to_prompt/folder_parser.py

  • Parses a folder structure, extracting file content and metadata.
  • Uses IgnoreSpec to respect .gitignore and .dixieignore rules.
  • Builds a formatted tree representation of the repository.
  • Calls extract_interfaces.py if the --interfaces-only flag is enabled.

repo_to_prompt/extract_interfaces.py

  • 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.

repo_to_prompt/__init__.py

  • Initializes the repo_to_prompt package.

Example Output

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**.


Metadata

Release files for repo-to-prompt 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for repo-to-prompt 0.1.0
File Size Uploaded
repo_to_prompt-0.1.0.tar.gz 12.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for repo-to-prompt 0.1.0
File Interpreter ABI Platform
repo_to_prompt-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 26.3 kB

Release files / repo_to_prompt-0.1.0.tar.gz

Download URL repo_to_prompt-0.1.0.tar.gz
Size 12.6 kB
Tags Source
SHA-256 checksum
How to use checksums
702e8e4817820bbacd1be7b5491dbcc6841439fe364f004d13a458fddea14749
BLAKE2b-256 checksum
How to use checksums
a2d4f9e628f397b951c038c26883ccac09b9428506481ad37ef440d6ddc8e25f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.12

Release files / repo_to_prompt-0.1.0-py3-none-any.whl

Download URL repo_to_prompt-0.1.0-py3-none-any.whl
Size 13.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
375849d0f397db87b5eebfd900151adee0fc90225ac71610e0e77870a176ec3f
BLAKE2b-256 checksum
How to use checksums
dd9b42df9ceecd44287c0051b51294de6425eafb4d725ddc948a03593499323e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page