Catalog PyPI
PACKAGE EXPLORERView in registry

abbrcompress

PyPI

Token-saving abbreviation compressor for OpenAI LLM prompts

Versions collected1
Direct dependencies1From release 0.1.4
Last observed20 Oct, 17:11 UTC

README

Version 0.1.4 documentation

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)

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
0.1.49 Jan 20261

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 17:11 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:ee42bcf423162a2088dbfb6b1606ee8dc218b56b229dc459c800b7cd6d5d0491