Command Usage
The pyminify command is installed with this package. It can be used to minify python files, and outputs the result to stdout.
usage: pyminify [-h] [--output OUTPUT | --in-place] [--no-combine-imports]
[--no-remove-pass] [--remove-literal-statements]
[--no-remove-annotations] [--no-hoist-literals]
[--no-rename-locals] [--preserve-locals LOCAL_NAMES]
[--rename-globals] [--preserve-globals GLOBAL_NAMES]
[--no-remove-object-base] [--no-convert-posargs-to-args]
[--no-preserve-shebang] [--remove-asserts] [--remove-debug]
[--no-remove-explicit-return-none] [--version]
path [path ...]
Minify Python source code
positional arguments:
path The source file or directory to minify. Use "-" to
read from stdin. Directories are recursively searched
for ".py" files to minify. May be used multiple times
options:
-h, --help show this help message and exit
--output OUTPUT, -o OUTPUT
Path to write minified output. Can only be used when
the source is a single module. Outputs to stdout by
default
--in-place, -i Overwrite existing files. Required when there is more
than one source module
--version, -v show program's version number and exit
minification options:
Options that affect how the source is minified
--no-combine-imports Disable combining adjacent import statements
--no-remove-pass Disable removing Pass statements
--remove-literal-statements
Enable removing statements that are just a literal
(including docstrings)
--no-remove-annotations
Disable removing function and variable annotations
--no-hoist-literals Disable replacing string and bytes literals with
variables
--no-rename-locals Disable shortening of local names
--preserve-locals LOCAL_NAMES
Comma separated list of local names that will not be
shortened
--rename-globals Enable shortening of global names
--preserve-globals GLOBAL_NAMES
Comma separated list of global names that will not be
shortened
--no-remove-object-base
Disable removing object from base class list
--no-convert-posargs-to-args
Disable converting positional only arguments to normal
arguments
--no-preserve-shebang
Preserve any shebang line from the source
--remove-asserts Remove assert statements
--remove-debug Remove conditional statements that test __debug__ is
True
--no-remove-explicit-return-none
Replace explicit return None with a bare return
examples:
# Minifying stdin to stdout
pyminify -
# Minifying a file to stdout
pyminify example.py
# Minifying a file and writing to a different file
pyminify example.py --output example.min.py
# Minifying a file in place
pyminify example.py --in-place
# Minifying all *.py files in a directory
pyminify src/ --in-place
# Minifying multiple paths in place
pyminify file1.py file2.py src/ --in-place