Name | files-to-prompt JSON |
Version |
0.4
JSON |
| download |
home_page | None |
Summary | Concatenate a directory full of files into a single prompt for use with LLMs |
upload_time | 2024-10-16 23:26:35 |
maintainer | None |
docs_url | None |
author | Simon Willison |
requires_python | >=3.8 |
license | Apache-2.0 |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# files-to-prompt
[![PyPI](https://img.shields.io/pypi/v/files-to-prompt.svg)](https://pypi.org/project/files-to-prompt/)
[![Changelog](https://img.shields.io/github/v/release/simonw/files-to-prompt?include_prereleases&label=changelog)](https://github.com/simonw/files-to-prompt/releases)
[![Tests](https://github.com/simonw/files-to-prompt/actions/workflows/test.yml/badge.svg)](https://github.com/simonw/files-to-prompt/actions/workflows/test.yml)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/simonw/files-to-prompt/blob/master/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](https://simonwillison.net/2024/Apr/8/files-to-prompt/).
## Installation
Install this tool using `pip`:
```bash
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:
```bash
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
- `-e/--extension <extension>`: Only include files with the specified extension. Can be used multiple times.
```bash
files-to-prompt path/to/directory -e txt -e md
```
- `--include-hidden`: Include files and folders starting with `.` (hidden files and directories).
```bash
files-to-prompt path/to/directory --include-hidden
```
- `--ignore-gitignore`: Ignore `.gitignore` files and include all files.
```bash
files-to-prompt path/to/directory --ignore-gitignore
```
- `--ignore <pattern>`: Specify one or more patterns to ignore. Can be used multiple times.
```bash
files-to-prompt path/to/directory --ignore "*.log" --ignore "temp*"
```
- `c/--cxml`: Output in Claude XML format.
```bash
files-to-prompt path/to/directory --cxml
```
- `-o/--output <file>`: Write the output to a file instead of printing it to the console.
```bash
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](https://docs.anthropic.com/claude/docs/long-context-window-tips) 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:
```xml
<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:
```bash
cd files-to-prompt
python -m venv venv
source venv/bin/activate
```
Now install the dependencies and test dependencies:
```bash
pip install -e '.[test]'
```
To run the tests:
```bash
pytest
```
Raw data
{
"_id": null,
"home_page": null,
"name": "files-to-prompt",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": null,
"author": "Simon Willison",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/47/01/ae9d0081f74df8de4149de31db4acdc864822dc2dec026b43c8facf7876b/files_to_prompt-0.4.tar.gz",
"platform": null,
"description": "# files-to-prompt\n\n[![PyPI](https://img.shields.io/pypi/v/files-to-prompt.svg)](https://pypi.org/project/files-to-prompt/)\n[![Changelog](https://img.shields.io/github/v/release/simonw/files-to-prompt?include_prereleases&label=changelog)](https://github.com/simonw/files-to-prompt/releases)\n[![Tests](https://github.com/simonw/files-to-prompt/actions/workflows/test.yml/badge.svg)](https://github.com/simonw/files-to-prompt/actions/workflows/test.yml)\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/simonw/files-to-prompt/blob/master/LICENSE)\n\nConcatenate a directory full of files into a single prompt for use with LLMs\n\nFor background on this project see [Building files-to-prompt entirely using Claude 3 Opus](https://simonwillison.net/2024/Apr/8/files-to-prompt/).\n\n## Installation\n\nInstall this tool using `pip`:\n\n```bash\npip install files-to-prompt\n```\n\n## Usage\n\nTo use `files-to-prompt`, provide the path to one or more files or directories you want to process:\n\n```bash\nfiles-to-prompt path/to/file_or_directory [path/to/another/file_or_directory ...]\n```\n\nThis will output the contents of every file, with each file preceded by its relative path and separated by `---`.\n\n### Options\n\n- `-e/--extension <extension>`: Only include files with the specified extension. Can be used multiple times.\n\n ```bash\n files-to-prompt path/to/directory -e txt -e md\n ```\n\n- `--include-hidden`: Include files and folders starting with `.` (hidden files and directories).\n\n ```bash\n files-to-prompt path/to/directory --include-hidden\n ```\n\n- `--ignore-gitignore`: Ignore `.gitignore` files and include all files.\n\n ```bash\n files-to-prompt path/to/directory --ignore-gitignore\n ```\n\n- `--ignore <pattern>`: Specify one or more patterns to ignore. Can be used multiple times.\n ```bash\n files-to-prompt path/to/directory --ignore \"*.log\" --ignore \"temp*\"\n ```\n\n- `c/--cxml`: Output in Claude XML format.\n\n ```bash\n files-to-prompt path/to/directory --cxml\n ```\n\n- `-o/--output <file>`: Write the output to a file instead of printing it to the console.\n\n ```bash\n files-to-prompt path/to/directory -o output.txt\n ```\n\n### Example\n\nSuppose you have a directory structure like this:\n\n```\nmy_directory/\n\u251c\u2500\u2500 file1.txt\n\u251c\u2500\u2500 file2.txt\n\u251c\u2500\u2500 .hidden_file.txt\n\u251c\u2500\u2500 temp.log\n\u2514\u2500\u2500 subdirectory/\n \u2514\u2500\u2500 file3.txt\n```\n\nRunning `files-to-prompt my_directory` will output:\n\n```\nmy_directory/file1.txt\n---\nContents of file1.txt\n---\nmy_directory/file2.txt\n---\nContents of file2.txt\n---\nmy_directory/subdirectory/file3.txt\n---\nContents of file3.txt\n---\n```\n\nIf you run `files-to-prompt my_directory --include-hidden`, the output will also include `.hidden_file.txt`:\n\n```\nmy_directory/.hidden_file.txt\n---\nContents of .hidden_file.txt\n---\n...\n```\n\nIf you run `files-to-prompt my_directory --ignore \"*.log\"`, the output will exclude `temp.log`:\n\n```\nmy_directory/file1.txt\n---\nContents of file1.txt\n---\nmy_directory/file2.txt\n---\nContents of file2.txt\n---\nmy_directory/subdirectory/file3.txt\n---\nContents of file3.txt\n---\n```\n\n### Claude XML Output\n\nAnthropic has provided [specific guidelines](https://docs.anthropic.com/claude/docs/long-context-window-tips) for optimally structuring prompts to take advantage of Claude's extended context window.\n\nTo structure the output in this way, use the optional `--cxml` flag, which will produce output like this:\n\n```xml\n<documents>\n<document index=\"1\">\n<source>my_directory/file1.txt</source>\n<document_content>\nContents of file1.txt\n</document_content>\n</document>\n<document index=\"2\">\n<source>my_directory/file2.txt</source>\n<document_content>\nContents of file2.txt\n</document_content>\n</document>\n</documents>\n```\n\n## Development\n\nTo contribute to this tool, first checkout the code. Then create a new virtual environment:\n\n```bash\ncd files-to-prompt\npython -m venv venv\nsource venv/bin/activate\n```\n\nNow install the dependencies and test dependencies:\n\n```bash\npip install -e '.[test]'\n```\n\nTo run the tests:\n\n```bash\npytest\n```\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "Concatenate a directory full of files into a single prompt for use with LLMs",
"version": "0.4",
"project_urls": {
"CI": "https://github.com/simonw/files-to-prompt/actions",
"Changelog": "https://github.com/simonw/files-to-prompt/releases",
"Homepage": "https://github.com/simonw/files-to-prompt",
"Issues": "https://github.com/simonw/files-to-prompt/issues"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "fb30923fa6daf3f50e6ed2d4762a4769b804c66a8afdfe20f366d83d070b594c",
"md5": "bd3c49e486aea5178280469ac85e5c5a",
"sha256": "81a3746dfd976b8b76a69ddf8c01c4cfafa7a01d1d5069e9f2dbb8a98b6aca9b"
},
"downloads": -1,
"filename": "files_to_prompt-0.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "bd3c49e486aea5178280469ac85e5c5a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 9187,
"upload_time": "2024-10-16T23:26:34",
"upload_time_iso_8601": "2024-10-16T23:26:34.282415Z",
"url": "https://files.pythonhosted.org/packages/fb/30/923fa6daf3f50e6ed2d4762a4769b804c66a8afdfe20f366d83d070b594c/files_to_prompt-0.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4701ae9d0081f74df8de4149de31db4acdc864822dc2dec026b43c8facf7876b",
"md5": "0e1c080eeb7f6b2c520cfb87681bed6f",
"sha256": "aa1c65bdb7fa123a3a36c5f105af34aa8f3f70495fc90dcb5f7fa995fda3463d"
},
"downloads": -1,
"filename": "files_to_prompt-0.4.tar.gz",
"has_sig": false,
"md5_digest": "0e1c080eeb7f6b2c520cfb87681bed6f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 9522,
"upload_time": "2024-10-16T23:26:35",
"upload_time_iso_8601": "2024-10-16T23:26:35.523182Z",
"url": "https://files.pythonhosted.org/packages/47/01/ae9d0081f74df8de4149de31db4acdc864822dc2dec026b43c8facf7876b/files_to_prompt-0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-16 23:26:35",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "simonw",
"github_project": "files-to-prompt",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "files-to-prompt"
}