Compress LLM prompts 50%+ while preserving meaning. Lightweight API client.
Project description
preduce
Compress LLM prompts 50%+ while preserving meaning. Cut your API costs in half with one line of code.
Install
pip install preduce
Quick Start
from preduce import compress
result = compress("Your verbose text here...", api_key="your-key")
print(result.compressed_text) # compressed output
print(result.category) # GENERAL, FINANCIAL, MEDICAL, CODE, ACADEMIC, SUPPORT, or MARKETING
print(result.token_reduction_pct) # e.g. 52.3
print(result.stats) # full reduction metrics
Category Override
result = compress(
"Total revenue for fiscal year 2025 was $847,300,000, "
"representing an increase of 22.4% year-over-year.",
api_key="your-key",
category="FINANCIAL",
)
# → "Total rev FY2025 $847.3M, +22.4% YoY."
Categories
| Category | What it compresses | Example |
|---|---|---|
| GENERAL | Business docs, emails, reports | "we are pleased to announce" → removed |
| FINANCIAL | Earnings, metrics, filings | "$847,300,000" → "$847.3M" |
| MEDICAL | Clinical notes, discharge summaries | "type 2 diabetes mellitus" → "T2DM" |
| CODE | Preserves code, compresses prose | Code untouched, comments compressed |
| ACADEMIC | Research papers, dissertations | "statistically significant" → "sig." |
| SUPPORT | Support tickets, help desk | "thank you for contacting" → "thanks for contacting" |
| MARKETING | Marketing copy, promotions | "limited time offer" → "limited time" |
Response
result.compressed_text # str — the compressed text
result.category # str — detected or overridden category
result.original_tokens # int — estimated original token count
result.compressed_tokens # int — estimated compressed token count
result.token_reduction_pct # float — percentage reduction
result.char_reduction_pct # float — percentage reduction
result.stats # dict — full metrics
result.to_dict() # dict — serialize everything
Error Handling
from preduce import compress
try:
result = compress("text", api_key="invalid-key")
except PermissionError:
print("Bad API key or quota exceeded")
except ValueError:
print("Invalid input (empty text or bad category)")
except RuntimeError:
print("API error")
Get an API Key
Visit preduce.dev to get your API key.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
preduce-0.2.0.tar.gz
(5.7 kB
view details)
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 preduce-0.2.0.tar.gz.
File metadata
- Download URL: preduce-0.2.0.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c52e3d744d9a4d980ff67e86bc9d3df00f14d281af1a0d6f6d5f702a25a915f
|
|
| MD5 |
8be53dc5e61f39b7d8078c28825e9eee
|
|
| BLAKE2b-256 |
7b7ff975a4d32612af3fc5073c4b7f3597bc811206fa2c3bfd3a310cf86d2ac2
|
File details
Details for the file preduce-0.2.0-py3-none-any.whl.
File metadata
- Download URL: preduce-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e58ceccc5b4d70cc3758baad4cf70c05300e0d7ae71c7c4f5dd5d05616d4a46e
|
|
| MD5 |
ee5d870d7608cca2aad000339dee193e
|
|
| BLAKE2b-256 |
7898a1bf450c2625fea8cf4419f7765804c6e3b9b7dcc9df00bea0b67c93659c
|