Strips comments, type hints, docstrings, and unnecessary whitespace from source files. Paste the output into LLM context windows — save tokens without losing functional code.
cd minifier
pip install -e .
# Single file to stdout
minify app.py
# With stats
minify app.py --stats
# Write to file
minify app.py -o app.min.py
# Process directory
minify src/ --ext .py,.ts
# Pipe mode
cat file.py | minify -l python -
# Force language
minify script.ts --language javascript
| Flag |
Effect |
--no-types |
Keep type hints |
--no-docs |
Keep docstrings |
--no-comments |
Keep comments |
--stats |
Print byte reduction to stderr |
-o FILE |
Write output to file |
-l LANG |
Force language (python, javascript, generic) |
--ext .py,.ts |
Filter by extension in directory mode |
| Language |
Method |
Strips |
| Python |
AST (ast.unparse) |
Types, docstrings, comments |
| JavaScript / TypeScript |
Regex |
Comments, TS types, interfaces, type aliases |
| Generic (Go, Rust, Ruby, C, Java, Shell, SQL, YAML, ...) |
Regex |
# comments, // comments, /* */ comments, blank lines |
# Before
from typing import List
def search(query: str, limit: int = 10) -> List[str]:
"""Search the database."""
results: List[str] = [] # type hint on variable
return results
# After
def search(query, limit=10):
results = []
return results
// Before
interface SearchParams {
query: string;
limit: number;
}
function search({ query, limit }: SearchParams): Promise<string[]> {
const results: string[] = [];
return results as string[];
}
// After
function search({ query, limit }) {
const results = [];
return results;
}