LLM prompt/context preparation utility
Project description
contextualize
contextualize is a package to quickly retrieve and format file contents for use with LLMs.
Installation
You can install the package using pip:
pip install contextualize
Usage (reference.py)
Define FileReference objects for specified file paths and optional ranges.
- set
rangeto a tuple of line numbers to include only a portion of the file, e.g.range=(1, 10) - set
formatto "md" or "xml" to wrap file contents in Markdown code blocks or<file>tags - set
labelto "relative" (default), "name", or "ext" to determine what label is affixed to the enclosing Markdown/XML string- "relative" will use the relative path from the current working directory
- "name" will use the file name only
- "ext" will use the file extension only
Retrieve wrapped contents from the output attribute.
CLI
A CLI (cli.py) is provided to print file contents to the console from the command line.
cat: Prepare and concatenate file referencespaths: Positional arguments for target file(s) or directories--ignore: File(s) to ignore (optional)--format: Output format (mdorxml, default ismd)--label: Label style (relativefor relative file path,namefor file name only,extfor file extension only; default isrelative)
- Example usage:
contextualize cat README.mdwill print the wrapped contents ofREADME.mdto the console with default settings (Markdown format, relative path label).contextualize cat README.md --format xmlwill print the wrapped contents ofREADME.mdto the console with XML format.contextualize cat contextualize/ dev/ README.md --format xmlwill prepare file references for files in thecontextualize/anddev/directories andREADME.md, and print each file's contents (wrapped in corresponding XML tags) to the console.
Related projects
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file contextualize-0.0.1.tar.gz.
File metadata
- Download URL: contextualize-0.0.1.tar.gz
- Upload date:
- Size: 15.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1767fc6ae3c621c00c2747edde3d3611a6e3634b358fe2694e8c7058d0108a12
|
|
| MD5 |
e9d95adb33b0146840d206691a1342eb
|
|
| BLAKE2b-256 |
3c701b580347ce0c8dd3ce7c1ac4d702bcf882246a46237408d54a51a94a267c
|
File details
Details for the file contextualize-0.0.1-py3-none-any.whl.
File metadata
- Download URL: contextualize-0.0.1-py3-none-any.whl
- Upload date:
- Size: 16.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
989e217adb04174d8b662488660fccb69862570aa83cb3779ab04fc454c914ad
|
|
| MD5 |
8e738b58d197e8bf9ba39c0eae82141b
|
|
| BLAKE2b-256 |
ec179654fedecaa90676f2910034d6725e686f4588bfa0b2ab083e49968223f9
|