promptprep package
- class promptprep.BaseFormatter[source]
Bases:
ABCThe foundation for all our formatters.
- abstract format_code_content(content: str, file_path: str) str[source]
Format code content with line numbers.
- 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_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.
- class promptprep.ConfigManager[source]
Bases:
objectLets 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 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
- class promptprep.FileSelector(start_path: str)[source]
Bases:
objectLets 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
- class promptprep.HighlightedFormatter(html_output: bool = True)[source]
Bases:
BaseFormatterAdds 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
- class promptprep.HtmlFormatter[source]
Bases:
BaseFormatterCreates a nice-looking webpage with your code.
- class promptprep.MarkdownFormatter[source]
Bases:
BaseFormatterMakes your code look great in Markdown documents.
- class promptprep.PlainTextFormatter[source]
Bases:
BaseFormatterKeeps things simple with plain text output.
- 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
- promptprep.aggregator module
CodeAggregatorCodeAggregator.DEFAULT_EXCLUDE_DIRSCodeAggregator.DEFAULT_EXCLUDE_FILESCodeAggregator.DEFAULT_MAX_FILE_SIZE_MBCodeAggregator.DEFAULT_PROGRAMMING_EXTENSIONSCodeAggregator.DEFAULT_TOKEN_MODELCodeAggregator.aggregate()CodeAggregator.aggregate_code()CodeAggregator.collect_metadata()CodeAggregator.compare_files()CodeAggregator.compare_runs()CodeAggregator.copy_to_clipboard()CodeAggregator.count_text_tokens()CodeAggregator.file_mod_timesCodeAggregator.is_file_size_within_limit()CodeAggregator.is_programming_file()CodeAggregator.should_exclude()CodeAggregator.should_include()CodeAggregator.write_to_file()
DirectoryTreeGenerator
- promptprep.cli module
- promptprep.config module
- promptprep.formatters module
BaseFormatterCustomTemplateFormatterCustomTemplateFormatter.__init__()CustomTemplateFormatter.format_code_content()CustomTemplateFormatter.format_directory_tree()CustomTemplateFormatter.format_error()CustomTemplateFormatter.format_file_header()CustomTemplateFormatter.format_metadata()CustomTemplateFormatter.format_skipped_files()CustomTemplateFormatter.render_template()
HighlightedFormatterHighlightedFormatter.__init__()HighlightedFormatter.format_code_content()HighlightedFormatter.format_directory_tree()HighlightedFormatter.format_error()HighlightedFormatter.format_file_header()HighlightedFormatter.format_metadata()HighlightedFormatter.format_skipped_files()HighlightedFormatter.get_full_html()
HtmlFormatterMarkdownFormatterPlainTextFormatterget_formatter()
- promptprep.tui module