Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Code Minifier

Strips comments, type hints, docstrings, and unnecessary whitespace from source files. Paste the output into LLM context windows — save tokens without losing functional code.

Install

cd minifier
pip install -e .

Quick start

# 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

Flags

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

Supported languages

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

What gets stripped

Python

# 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

TypeScript

// 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;
}

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages