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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

repo_to_prompt-0.1.0.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

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

repo_to_prompt-0.1.0-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file repo_to_prompt-0.1.0.tar.gz.

File metadata

  • Download URL: repo_to_prompt-0.1.0.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for repo_to_prompt-0.1.0.tar.gz
Algorithm Hash digest
SHA256 702e8e4817820bbacd1be7b5491dbcc6841439fe364f004d13a458fddea14749
MD5 a3cc0265431fca9a285a28bcd2814fe5
BLAKE2b-256 a2d4f9e628f397b951c038c26883ccac09b9428506481ad37ef440d6ddc8e25f

See more details on using hashes here.

File details

Details for the file repo_to_prompt-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: repo_to_prompt-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for repo_to_prompt-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 375849d0f397db87b5eebfd900151adee0fc90225ac71610e0e77870a176ec3f
MD5 7ef82d83e232f8c096a71dafb58db16f
BLAKE2b-256 dd9b42df9ceecd44287c0051b51294de6425eafb4d725ddc948a03593499323e

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Supported by

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