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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b771621d85004aded0aefa6553986306d0c103aef4afa590a64c5e2fdc2c963
|
|
| MD5 |
67225dbe78e6e827b7ad2894f48e3850
|
|
| BLAKE2b-256 |
c467ae90a6cc128df147bfeb21e7fd435676ea12cb6f200ccff65cbb1f6050fe
|
Provenance
The following attestation bundles were made for prompt_token_minifier-0.1.0.tar.gz:
Publisher:
publish.yml on Encephos/prompt-token-minifier
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
prompt_token_minifier-0.1.0.tar.gz -
Subject digest:
0b771621d85004aded0aefa6553986306d0c103aef4afa590a64c5e2fdc2c963 - Sigstore transparency entry: 2596949883
- Sigstore integration time:
-
Permalink:
Encephos/prompt-token-minifier@8ac8b1ad5d1072f5689a36d160e8f9ef3ce0d356 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Encephos
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8ac8b1ad5d1072f5689a36d160e8f9ef3ce0d356 -
Trigger Event:
release
-
Statement type:
File details
Details for the file prompt_token_minifier-0.1.0-py3-none-any.whl.
File metadata
- Download URL: prompt_token_minifier-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f9667010bd985ee6bfdb7df62710d86ec3126f5515304a416c8d98b630ba381
|
|
| MD5 |
d24c26664b63f06c13170a86f6223bb7
|
|
| BLAKE2b-256 |
dc8acd5c613fc1ef75d5131cd755b59af79196542178869c8a259fbc94198fff
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
prompt_token_minifier-0.1.0-py3-none-any.whl -
Subject digest:
9f9667010bd985ee6bfdb7df62710d86ec3126f5515304a416c8d98b630ba381 - Sigstore transparency entry: 2596949936
- Sigstore integration time:
-
Permalink:
Encephos/prompt-token-minifier@8ac8b1ad5d1072f5689a36d160e8f9ef3ce0d356 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Encephos
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8ac8b1ad5d1072f5689a36d160e8f9ef3ce0d356 -
Trigger Event:
release
-
Statement type: