Skip to main content

A project that splits files and copies them to paste buffer with context for an LLM.

Reason this release was yanked:

Another pyproject.toml gotcha

Project description

chunkwrap

A Python utility for splitting large files into manageable chunks and wrapping them with custom prompts for Large Language Model (LLM) processing.

Overview

chunkwrap helps you process large files with LLMs by automatically splitting them into smaller chunks and wrapping each chunk with your specified prompt. It maintains state between runs, so you can process one chunk at a time without losing track of your progress.

Features

  • Automatic chunking: Split files into configurable chunk sizes (default 10,000 characters)
  • State management: Remembers which chunk you're on between runs
  • Clipboard integration: Automatically copies wrapped chunks to your clipboard
  • Custom prompts: Use different prompts for regular chunks vs. the final chunk
  • Progress tracking: Shows current chunk number and total chunks

Installation

  1. Clone or download the script
  2. Install the required dependency:
    pip install pyperclip
    

Usage

Basic Usage

python chunkwrap.py --prompt "Analyze this code:" --file myfile.txt

Advanced Usage

# Custom chunk size
python chunkwrap.py --prompt "Review this code:" --file large_file.py --size 5000

# Different prompt for the last chunk
python chunkwrap.py --prompt "Analyze this code chunk:" --file code.py --lastprompt "Analyze this final code chunk and provide a summary:"

# Reset state to start over
python chunkwrap.py --reset

Command Line Arguments

  • --prompt (required): The prompt text to wrap around each chunk
  • --file (required): Path to the file you want to process
  • --lastprompt (optional): Different prompt for the final chunk
  • --size (optional): Chunk size in characters (default: 10,000)
  • --reset (optional): Reset the chunk counter and start from the beginning

How It Works

  1. First run: Reads your file, splits it into chunks, wraps the first chunk with your prompt, and copies it to clipboard
  2. Subsequent runs: Continues from where you left off, processing the next chunk
  3. State tracking: Uses a .chunkwrap_state file to remember your progress
  4. Completion: Notifies you when all chunks are processed

Example Workflow

# Start processing a large Python file
python chunkwrap.py --prompt "Please review this Python code for bugs:" --file large_script.py

# Output: "Chunk 1 of 5 is now in the paste buffer. Run this script again for the next chunk."
# Paste into your LLM, get response, then run again...

python chunkwrap.py --prompt "Please review this Python code for bugs:" --file large_script.py

# Output: "Chunk 2 of 5 is now in the paste buffer. Run this script again for the next chunk."
# Continue until all chunks are processed...

# When done with this file, reset for a new file
python chunkwrap.py --reset

Output Format

Each chunk is wrapped in triple quotes with your prompt:

Your prompt here (chunk 1 of 3)
"""
[chunk content here]
"""

The final chunk omits the chunk counter and uses --lastprompt if provided.

State File

chunkwrap creates a .chunkwrap_state file in the current directory to track progress. Delete this file or use --reset to start over with a new file or prompt.

Use Cases

  • Processing large codebases with LLMs
  • Analyzing lengthy documents in sections
  • Breaking down large text files for review
  • Sequential processing of any large text content

Requirements

  • Python 3.6+
  • pyperclip library

License

This project is licensed under the GNU General Public License v3.0. See the LICENSE file for more details.

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

chunkwrap-0.2.0.tar.gz (43.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chunkwrap-0.2.0-py3-none-any.whl (29.1 kB view details)

Uploaded Python 3

File details

Details for the file chunkwrap-0.2.0.tar.gz.

File metadata

  • Download URL: chunkwrap-0.2.0.tar.gz
  • Upload date:
  • Size: 43.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for chunkwrap-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c727f75d1249223d947ac7db56d93a0e042fcabaa857ccf33d1612fd04313e6a
MD5 7465727d991fe57f322e3cc2f5850425
BLAKE2b-256 6e190813eb233dc6c17b97e302e2dc9a5159cbf49ae0ad43d0039dfad419d4b4

See more details on using hashes here.

File details

Details for the file chunkwrap-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: chunkwrap-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 29.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for chunkwrap-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3b2fadf4d7c45138bb208f3b3baaf26f8da9a03215685d87646aaf7915b47134
MD5 f23e9095d336be6a85ffada792c62be0
BLAKE2b-256 a41f7cdc7924d14c92dd638777e038f7ea528158d9059107bc433d79b1f6a39a

See more details on using hashes here.

Supported by

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