pymini is an AST-based Python minifier for scripts and packages. It can
shrink raw Python source code by up to 4x and the associated .whl files
by up to 7.3x.
Package mode preserves the package tree:
pymini package src -o outBundle mode emits one file:
pymini bundle src -o out/bundle.pyYou can also use the Python API directly:
from pymini import minify
sources, modules = minify(
[
"def square(x):\n return x ** 2\n",
"from main import square\nprint(square(3))\n",
],
["main", "side"],
)Representative compression results, using
--rename-modules --rename-global-variables --rename-arguments:
For these results, we validate that all package tests still run and pass, with the minified source code. For the full compression tables, speed results, and package validation, see benchmarks/README.md.
python3 -m pip install pyminigit clone https://github.com/alvinwan/pymini.git
cd pymini
python3 -m pip install -e ".[dev]"