Minipy is a minifier and obfuscator for Python source code.
Minipy converts a string (or file) of Python source code into a more compact form, optionally substituting variables with shorter variations where possible.
Variable substitution honors imported modules regardless of whether they are 1st or 3rd party modules, e.g. it will not minifiy imported identifiers such as path
or exists
in os.path.exists()
.
Input:
import os
# Check if the JSON file exists.
def json_exists(filename: str) -> bool:
with_ext = filename + ".json"
return os.path.exists(with_ext)
Minified:
import os
def json_exists(filename:str)->bool:
with_ext=filename+".json"
return os.path.exists(with_ext)
Obfuscated:
import os
def a(b):
c=b+"json
return os.path.exists(c)
Minipy can be consumed as a library or as a standalone command-line program.
Executing the following command from your shell will minify the Python file named filename.py
.
If no file is specified, then Minipy will read from stdin
.
$ minipy filename.py
Minify and obfuscate with:
$ minipy --obfuscate filename.py
The -s
flag suppresses obfuscation of identifiers.
This is useful for preventing public functions, classes, variables, etc. from being obfuscated.
The following command would prevent identifiers foo
and bar
from being obfuscated.
$ minipy --obfuscate -s foo -s bar filename.py
Minipy requires Python 3.12 or newer
Install Minipy by downloading the latest version from the releases page and installing with:
$ pip install minipy-0.9.2-py3-none-any.whl
Minipy is free for non-commercial use. See LICENSE for details.
You can purchase a commercial license from Railgun Labs.