Skip to main content

Prompt Token Minifier

A zero-dependency Python micro-tool to shrink your LLM prompts before sending them to the API. It saves tokens and reduces costs by:

  • Minifying JSON schemas and examples inside Markdown blocks.
  • Stripping comments (//, #, /* */) from code blocks.
  • Collapsing redundant whitespaces and newlines.

Installation

pip install prompt-token-minifier

Usage

from prompt_token_minifier import minify_prompt

raw_prompt = """
You are a helpful assistant.
    
Here is the JSON schema you must follow:

{
  "type": "object",
  "properties": {
    "name": {
      "type": "string"
    }
  }
}

And some context code:

# This function calculates the sum
def add(a, b):
    return a + b
print(minify_prompt(raw_prompt))

Output: (Saves ~40% tokens depending on formatting)

You are a helpful assistant.

Here is the JSON schema you must follow:

{"type":"object","properties":{"name":{"type":"string"}}}

And some context code:

def add(a, b):
    return a + b

Download files

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

Source Distribution

prompt_token_minifier-0.1.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

prompt_token_minifier-0.1.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file prompt_token_minifier-0.1.0.tar.gz.

File metadata

  • Download URL: prompt_token_minifier-0.1.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for prompt_token_minifier-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0b771621d85004aded0aefa6553986306d0c103aef4afa590a64c5e2fdc2c963
MD5 67225dbe78e6e827b7ad2894f48e3850
BLAKE2b-256 c467ae90a6cc128df147bfeb21e7fd435676ea12cb6f200ccff65cbb1f6050fe

See more details on using hashes here.

Provenance

The following attestation bundles were made for prompt_token_minifier-0.1.0.tar.gz:

Publisher: publish.yml on Encephos/prompt-token-minifier

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file prompt_token_minifier-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for prompt_token_minifier-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9f9667010bd985ee6bfdb7df62710d86ec3126f5515304a416c8d98b630ba381
MD5 d24c26664b63f06c13170a86f6223bb7
BLAKE2b-256 dc8acd5c613fc1ef75d5131cd755b59af79196542178869c8a259fbc94198fff

See more details on using hashes here.

Provenance

The following attestation bundles were made for prompt_token_minifier-0.1.0-py3-none-any.whl:

Publisher: publish.yml on Encephos/prompt-token-minifier

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.0 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