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

Metadata

Release files for tokenshrink-ai 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tokenshrink-ai 0.1.1
File Size Uploaded Provenance Actions
tokenshrink_ai-0.1.1.tar.gz 3.5 kB Without provenance Details for tokenshrink_ai-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tokenshrink-ai 0.1.1
File Interpreter ABI Platform Actions
tokenshrink_ai-0.1.1-py3-none-any.whl Python 3 none any Details for tokenshrink_ai-0.1.1-py3-none-any.whl

Total release size: 8.0 kB

Release files / tokenshrink_ai-0.1.1.tar.gz

Download URL tokenshrink_ai-0.1.1.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
6c5c66ab38ee69b5aebdce05f55ce57175b64a56852f3781e39bc9083fa9060e
BLAKE2b-256 checksum
How to use checksums
8bb8ddcc60cbd3772c367eb5edb01abf716b814e04b980f33d78ca103c35d179
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.15

Release files / tokenshrink_ai-0.1.1-py3-none-any.whl

Download URL tokenshrink_ai-0.1.1-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
585b979a3eca80ad30b7981313f0282da2739bb9fc30caee951dbd988ab7fa3a
BLAKE2b-256 checksum
How to use checksums
e7c6d079df7df4dc7023c4eee91d80bc22d9907f035b3a1da28dd122fe15fb90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.15

Security for tokenshrink-ai 0.1.1

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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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