promptprep package

class promptprep.BaseFormatter[source]

Bases: ABC

The foundation for all our formatters.

__init__()[source]

Initialize the formatter.

abstract format_code_content(content: str, file_path: str) str[source]

Format code content with line numbers.

abstract format_directory_tree(tree: str) str[source]

Format the directory tree.

abstract format_error(error_msg: str) str[source]

Format error messages.

abstract format_file_header(file_path: str) str[source]

Format a file header.

abstract format_metadata(metadata: Dict[str, Any]) str[source]

Format metadata section.

abstract format_skipped_files(skipped_files: List[tuple]) str[source]

Format skipped files section.

get_file_extension(file_path: str) str[source]

Get the extension of a file.

class promptprep.CodeAggregator(directory: str | None = None, output_file: str = 'full_code.txt', include_files: Set[str] | None = None, programming_extensions: Set[str] | None = None, exclude_dirs: Set[str] | None = None, exclude_files: Set[str] | None = None, max_file_size_mb: float | None = None, summary_mode: bool = False, include_comments: bool = True, collect_metadata: bool = False, count_tokens: bool = False, token_model: str = 'cl100k_base', output_format: str = 'plain', line_numbers: bool = False, template_file: str | None = None, incremental: bool = False, last_run_timestamp: float | None = None)[source]

Bases: object

DEFAULT_EXCLUDE_DIRS = {'.git', '__pycache__', 'build', 'dist', 'flask_session', 'node_modules', 'old_files', 'temp', 'venv'}
DEFAULT_EXCLUDE_FILES = {'full_code.txt'}
DEFAULT_MAX_FILE_SIZE_MB = 100.0
DEFAULT_PROGRAMMING_EXTENSIONS = {'.bat', '.c', '.cmake', '.cmd', '.cpp', '.cs', '.css', '.db', '.fish', '.go', '.gradle', '.h', '.hpp', '.html', '.ini', '.java', '.js', '.json', '.jsx', '.kt', '.less', '.lua', '.md', '.ninja', '.php', '.pl', '.pq', '.pqm', '.ps1', '.psql', '.py', '.r', '.rb', '.rs', '.rst', '.sass', '.scala', '.scss', '.sh', '.sql', '.sqlite', '.swift', '.toml', '.ts', '.tsx', '.vb', '.xml', '.yaml', '.yml', '.zsh', 'Makefile'}
DEFAULT_TOKEN_MODEL = 'cl100k_base'
aggregate()[source]
aggregate_code() str[source]

Brings together the directory tree and content of programming files into a single document.

collect_metadata() dict[source]

Gathers stats about the codebase like lines of code and comment ratio.

compare_files(file1: str, file2: str, output_file: str | None = None, context_lines: int = 3) str[source]

Compares two code files and shows their differences with clear formatting.

Parameters:
  • file1 – Path to the first file

  • file2 – Path to the second file

  • output_file – Optional path to write the diff results to

  • context_lines – Number of context lines to include in the diff (default: 3)

Returns:

String containing the formatted differences

compare_runs(prev_output: str, current_output: str | None = None, output_file: str | None = None, context_lines: int = 3) str[source]

Compares the current aggregation run with a previous one.

Parameters:
  • prev_output – Path to the previous aggregation output file

  • current_output – Path to the current output file (defaults to self.output_file)

  • output_file – Optional path to write the diff results to

  • context_lines – Number of context lines to include in the diff

Returns:

String containing the formatted differences

copy_to_clipboard(content: str | None = None) bool[source]

Copies the content to clipboard, with platform-specific handling.

count_text_tokens(text: str) int[source]

Count the number of tokens in a text string using our tokenizer.

is_file_size_within_limit(file_path: str) bool[source]

Check if the file size is within our configured limit.

is_programming_file(filename: str) bool[source]
should_exclude(path: str) bool[source]
should_include(file_path: str) bool[source]
write_to_file(content: str | None = None, filename: str | None = None) None[source]

Writes the aggregated content to a file with appropriate extension based on format.

class promptprep.ConfigManager[source]

Bases: object

Lets you save and load your PromptPrep settings.

DEFAULT_CONFIG_DIR = '/home/docs/.promptprep'
DEFAULT_CONFIG_FILE = '/home/docs/.promptprep/config.json'
static apply_config_to_args(config_dict: Dict[str, Any], args: Namespace) Namespace[source]

Updates your current settings with values from a config file.

Parameters:
  • config_dict – Settings loaded from your config file

  • args – Your current command-line arguments

Returns:

Your updated settings

classmethod ensure_config_dir() None[source]

Creates the config directory if it doesn’t exist yet.

classmethod load_config(config_file: str | None = None) Dict[str, Any][source]

Loads your saved settings from a file.

Parameters:

config_file – Where to load from. Uses ~/.promptprep/config.json if not specified

Returns:

Your saved settings as a dictionary

Raises:

FileNotFoundError – When the config file doesn’t exist

classmethod save_config(args: Namespace, config_file: str | None = None) str[source]

Saves your current settings to a file for later use.

Parameters:
  • args – Your command-line arguments

  • config_file – Where to save the config. Uses ~/.promptprep/config.json if not specified

Returns:

The path where your config was saved

class promptprep.DirectoryTreeGenerator(exclude_dirs: Set[str] | None = None, include_files: Set[str] | None = None, exclude_files: Set[str] | None = None, programming_extensions: Set[str] | None = None)[source]

Bases: object

generate(start_path: str) str[source]

Creates an ASCII representation of the directory structure starting from the given path.

class promptprep.FileSelector(start_path: str)[source]

Bases: object

Lets you browse and select files using arrow keys and spacebar.

__init__(start_path: str)[source]

Gets everything ready for file selection.

Parameters:

start_path – Where to start browsing from

get_selections() Tuple[Set[str], Set[str], bool][source]

Get the current selections and return them.

Returns:

A tuple of (include_files, exclude_dirs, save_selections)

run(stdscr) Tuple[Set[str], Set[str], bool][source]

Starts up the file selector interface.

Parameters:

stdscr – The main screen object from curses

Returns:

  • Set of files to include

  • Set of directories to exclude

  • Whether to save these choices

class promptprep.HighlightedFormatter(html_output: bool = True)[source]

Bases: BaseFormatter

Adds syntax highlighting to make your code pop.

__init__(html_output: bool = True)[source]

Gets ready to highlight your code.

Parameters:

html_output – True for web pages, False for terminal colors

format_code_content(content: str, file_path: str) str[source]

Format code content with syntax highlighting (without line numbers).

format_directory_tree(tree: str) str[source]

Format the directory tree with highlighting.

format_error(error_msg: str) str[source]

Format error messages.

format_file_header(file_path: str) str[source]

Format a file header with highlighting.

format_metadata(metadata: Dict[str, Any]) str[source]

Format metadata section.

format_skipped_files(skipped_files: List[tuple]) str[source]

Format skipped files section.

get_full_html(content: str, title: str = 'Code Aggregation') str[source]

Wrap content in a complete HTML document if in HTML mode.

class promptprep.HtmlFormatter[source]

Bases: BaseFormatter

Creates a nice-looking webpage with your code.

__init__()[source]

Initialize HTML formatter with CSS styles.

format_code_content(content: str, file_path: str) str[source]

Format code content in HTML (without line numbers).

format_directory_tree(tree: str) str[source]

Format the directory tree in HTML.

format_error(error_msg: str) str[source]

Format error messages in HTML.

format_file_header(file_path: str) str[source]

Format a file header in HTML.

format_metadata(metadata: Dict[str, Any]) str[source]

Format metadata section in HTML.

format_skipped_files(skipped_files: List[tuple]) str[source]

Format skipped files section in HTML.

get_full_html(content: str, title: str = 'Code Aggregation') str[source]

Wrap content in a complete HTML document.

class promptprep.MarkdownFormatter[source]

Bases: BaseFormatter

Makes your code look great in Markdown documents.

format_code_content(content: str, file_path: str) str[source]

Format code content in Markdown (without line numbers).

format_directory_tree(tree: str) str[source]

Format the directory tree in Markdown.

format_error(error_msg: str) str[source]

Format error messages in Markdown.

format_file_header(file_path: str) str[source]

Format a file header in Markdown.

format_metadata(metadata: Dict[str, Any]) str[source]

Format metadata section in Markdown.

format_skipped_files(skipped_files: List[tuple]) str[source]

Format skipped files section in Markdown.

class promptprep.PlainTextFormatter[source]

Bases: BaseFormatter

Keeps things simple with plain text output.

format_code_content(content: str, file_path: str) str[source]

Format code content in plain text (without line numbers).

format_directory_tree(tree: str) str[source]

Format the directory tree in plain text.

format_error(error_msg: str) str[source]

Format error messages in plain text.

format_file_header(file_path: str) str[source]

Format a file header in plain text.

format_metadata(metadata: Dict[str, Any]) str[source]

Format metadata section in plain text.

format_skipped_files(skipped_files: List[tuple]) str[source]

Format skipped files section in plain text.

promptprep.get_formatter(output_format: str = 'plain', template_file: str | None = None, base_format: str = 'plain') BaseFormatter[source]

Picks the right formatter for your needs.

Parameters:
  • output_format – How you want it to look (plain, markdown, html, highlighted, custom)

  • template_file – Your template file (needed for custom format)

  • base_format – Backup format for custom templates (defaults to plain)

Returns:

The formatter that’ll do the job

Raises:

ValueError – If format is unknown or template is missing when needed

promptprep.select_files_interactive(directory: str) Tuple[Set[str], Set[str], bool][source]

Lets you pick files using an interactive menu.

Parameters:

directory – Where to start browsing

Returns:

  • Set of files you want to include

  • Set of directories you want to skip

  • Whether you want to save these choices

Submodules