abbrcompress
Token-saving abbreviation compression for OpenAI-compatible LLM prompts.
abbrcompress identifies frequently repeated phrases in a prompt, replaces them with short abbreviations, and decodes the model response back to the original text — helping reduce token usage for long or repetitive prompts. Testing on real datasets shows reductions of 1-2% of tokens sending to OpenAI.
What this library does
✅ Detects repeated n-grams
✅ Computes net token savings using tiktoken
✅ Applies abbreviations only when savings are positive
✅ Decodes model responses safely
❌ Does not modify OpenAI tokenization
❌ Does not guarantee savings for short prompts
Install
pip install abbrcompress
# or
uv pip install abbrcompress
Usage
from abbrcompress.core import build_abbreviations, compress_prompt, decode_abbreviations, token_len
prompt = """your prompt text here"""
# Build abbreviation dictionary
abbr_dict, _ = build_abbreviations(prompt)
# Compress prompt
compressed_prompt = compress_prompt(prompt, abbr_dict)
# TODO: send compressed_prompt to OpenAI and get return_message as response
return_message = _ # Placeholder for OpenAI response
# Decode return from OpenAI
decoded_text = decode_abbreviations(return_message, abbr_dict)
Metadata
Release files for abbrcompress 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| abbrcompress-0.1.4.tar.gz | 4.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| abbrcompress-0.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.1 kB
Release files / abbrcompress-0.1.4.tar.gz
| Download URL | abbrcompress-0.1.4.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1b144b2bafef86b7ffcd2f1fbc0c5bd199c55b42679c2d45a2366d21f4153fb7
|
|
BLAKE2b-256 checksum How to use checksums |
42818cb6351a406994af33792370f46d0f3f9b41ba0fbc012cef319e039c73ad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Release files / abbrcompress-0.1.4-py3-none-any.whl
| Download URL | abbrcompress-0.1.4-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
068221c327be8db7ab357e4aa6a03c1a3a219846b0facc4ab254a0811e549e33
|
|
BLAKE2b-256 checksum How to use checksums |
d2afdd4d9b3c1b8e23bdacd8f3bf14e10990ae2a6da6346564e0b8d413db2d4b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Security for abbrcompress 0.1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.