Skip to main content

Concatenate a directory full of files into a single prompt for use with LLMs

Project description

files-to-prompt

PyPI Changelog Tests License

Concatenate a directory full of files into a single prompt for use with LLMs

For background on this project see Building files-to-prompt entirely using Claude 3 Opus.

Installation

Install this tool using pip:

pip install files-to-prompt

Usage

To use files-to-prompt, provide the path to one or more files or directories you want to process:

files-to-prompt path/to/file_or_directory [path/to/another/file_or_directory ...]

This will output the contents of every file, with each file preceded by its relative path and separated by ---.

Options

  • --include-hidden: Include files and folders starting with . (hidden files and directories).

    files-to-prompt path/to/directory --include-hidden
    
  • --ignore-gitignore: Ignore .gitignore files and include all files.

    files-to-prompt path/to/directory --ignore-gitignore
    
  • --ignore <pattern>: Specify one or more patterns to ignore. Can be used multiple times.

    files-to-prompt path/to/directory --ignore "*.log" --ignore "temp*"
    
  • c/--cxml: Output in Claude XML format.

    files-to-prompt path/to/directory --cxml
    
  • -o/--output <file>: Write the output to a file instead of printing it to the console.

    files-to-prompt path/to/directory -o output.txt
    

Example

Suppose you have a directory structure like this:

my_directory/
├── file1.txt
├── file2.txt
├── .hidden_file.txt
├── temp.log
└── subdirectory/
    └── file3.txt

Running files-to-prompt my_directory will output:

my_directory/file1.txt
---
Contents of file1.txt
---
my_directory/file2.txt
---
Contents of file2.txt
---
my_directory/subdirectory/file3.txt
---
Contents of file3.txt
---

If you run files-to-prompt my_directory --include-hidden, the output will also include .hidden_file.txt:

my_directory/.hidden_file.txt
---
Contents of .hidden_file.txt
---
...

If you run files-to-prompt my_directory --ignore "*.log", the output will exclude temp.log:

my_directory/file1.txt
---
Contents of file1.txt
---
my_directory/file2.txt
---
Contents of file2.txt
---
my_directory/subdirectory/file3.txt
---
Contents of file3.txt
---

Claude XML Output

Anthropic has provided specific guidelines for optimally structuring prompts to take advantage of Claude's extended context window.

To structure the output in this way, use the optional --cxml flag, which will produce output like this:

<documents>
<document index="1">
<source>my_directory/file1.txt</source>
<document_content>
Contents of file1.txt
</document_content>
</document>
<document index="2">
<source>my_directory/file2.txt</source>
<document_content>
Contents of file2.txt
</document_content>
</document>
</documents>

Development

To contribute to this tool, first checkout the code. Then create a new virtual environment:

cd files-to-prompt
python -m venv venv
source venv/bin/activate

Now install the dependencies and test dependencies:

pip install -e '.[test]'

To run the tests:

pytest

Project details


Download files

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

Source Distribution

files_to_prompt-0.3.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

files_to_prompt-0.3-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file files_to_prompt-0.3.tar.gz.

File metadata

  • Download URL: files_to_prompt-0.3.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for files_to_prompt-0.3.tar.gz
Algorithm Hash digest
SHA256 309ecc23fa7aa1298bbccd86c83fb6d44f9a2ba9f4e2a09dbbea56761899c1cc
MD5 9be04e73ab38076f5b710050c9d3e8b0
BLAKE2b-256 84c070c353ae957c8322d7dd9d524c60b8ab4185980fd82a0bab4c460f612b02

See more details on using hashes here.

File details

Details for the file files_to_prompt-0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for files_to_prompt-0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 47492ff2e99883d325c72478ccc05adb19af7edb2abc004de6e99dddeed1ca60
MD5 f11607fbb69c9b0ca22a0ea5dc8f3e9c
BLAKE2b-256 f0c8d538d9076e15235967003be77976ed312be6a697dc384d8b0125e3c481a8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page