Skip to main content

⚡ TokenShrink

Run Unit Tests License: MIT

A lightweight Python library for prompt compression and token optimization—reduce LLM input costs by 30-50% without sacrificing context.

Features

  • Prompt Pruning: Automatically strips conversational fluff ("please", "kindly") and collapses unnecessary whitespace.
  • Data Serialization: Converts heavy JSON payloads into token-efficient tabular representations.
  • Zero Overhead: Blazing fast execution using pure Python regular expressions.

Quickstart

pip install -e .

from token_shrink import prune_prompt, compress_struct

# Prune filler words
raw_prompt = "Could you please kindly analyze this data?"
clean_prompt = prune_prompt(raw_prompt)
print(clean_prompt)  # "analyze this data"

# Compress structured data
data = [{"id": 1, "name": "Alice"}, {"id": 2, "name": "Bob"}]
compact = compress_struct(data)
print(compact)
# [2]{id,name}:
# 1,Alice
# 2,Bob

pytest

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tokenshrink_ai-0.1.1.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

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

tokenshrink_ai-0.1.1-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file tokenshrink_ai-0.1.1.tar.gz.

File metadata

  • Download URL: tokenshrink_ai-0.1.1.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.15

File hashes

Hashes for tokenshrink_ai-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6c5c66ab38ee69b5aebdce05f55ce57175b64a56852f3781e39bc9083fa9060e
MD5 d81f965bee09b5b610809112d6632d9f
BLAKE2b-256 8bb8ddcc60cbd3772c367eb5edb01abf716b814e04b980f33d78ca103c35d179

See more details on using hashes here.

File details

Details for the file tokenshrink_ai-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: tokenshrink_ai-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.15

File hashes

Hashes for tokenshrink_ai-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 585b979a3eca80ad30b7981313f0282da2739bb9fc30caee951dbd988ab7fa3a
MD5 8616e7cac6cb849324a2b0c873434bbd
BLAKE2b-256 e7c6d079df7df4dc7023c4eee91d80bc22d9907f035b3a1da28dd122fe15fb90

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page