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-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]
[--no-remove-builtin-exception-brackets]
[--no-constant-folding] [--no-remove-annotations]
[--no-remove-variable-annotations]
[--no-remove-return-annotations]
[--no-remove-argument-annotations]
[--remove-class-attribute-annotations] [--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, -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-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
Disable preserving any shebang line from the source
--remove-asserts Enable removing assert statements
--remove-debug Enable removing conditional statements that test
__debug__ is True
--no-remove-explicit-return-none
Disable replacing explicit return None with a bare
return
--no-remove-builtin-exception-brackets
Disable removing brackets when raising builtin
exceptions with no arguments
--no-constant-folding
Disable evaluating literal expressions
remove annotations options:
Options that affect how annotations are removed
--no-remove-annotations
Disable removing all annotations
--no-remove-variable-annotations
Disable removing variable annotations
--no-remove-return-annotations
Disable removing function return annotations
--no-remove-argument-annotations
Disable removing function argument annotations
--remove-class-attribute-annotations
Enable removing class attribute annotations
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