Skip to main content

python-minimizer

Minimizes Python code using Python's lexical scanning tokenize module.

Get it on pip

 pip install python-minimizer 

Command-line usage

Currently python-minimizer supports the following options:

usage: minimizer.py [-h] [-o OUT_PATH] [-b] [-c] [-d] [-s]
                    [-w WHITESPACE_CHAR] [-i INDENT_CHAR] [-r] [-v]
                    in_path

Minimizes Python code using Python's lexical scanning tokenize module.

positional arguments:
  in_path               The file to minimize

optional arguments:
  -h, --help            show this help message and exit
  -o OUT_PATH, --out-path OUT_PATH
                        When specified, minimizer will output to the path
                        instead of stdout
  -b, --keep-blank-lines
                        When set, minimizer will not remove blank lines.
  -c, --keep-comments   When set, minimizer will not remove comment lines and
                        inline comments
  -d, --keep-docstrings
                        When set, minimizer will not remove docstrings
  -s, --keep-whitespace
                        When set, minimizer will not remove extraneous
                        whitespace
  -w WHITESPACE_CHAR, --whitespace-char WHITESPACE_CHAR
                        Set the whitespace character to use. Defaults to space
                        (" ")
  -i INDENT_CHAR, --indent-char INDENT_CHAR
                        Set the indentation character to use. Defaults to tab
                        ("\t")
  -r, --recursive       Treat the in-path and --out-path as directories to
                        minimize recursively
  -v, --verbose         Explain what we are doing as we do it, higher levels
                        are useful for debugging

By default, the minimizer removes blank lines, comments, docstrings, and
extraneous whitespace. Where needed, it will insert a space (" ") for
whitespace between operators and use a tab ("\t") for indentation. Use the
command line switches to change any of the defaults.

Library usage

Of course, you can also import the minimizer module and use it as follows:

from minimizer import minimize
with open(code_file, 'r') as f:
    code = f.read()
minimized_code = minimize(code)
with open(minimized_file, 'w') as f:
    f.write(minimized_code)

By default, the minimize function will remove blank lines, comments, docstrings, and whitespace between operators and uses a space (" ") for the whitespace character and a tab ("\t") for the indent character, but accepts keyword arguments to change these options.

Metadata

Release files for python-minimizer 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-minimizer 2.0.1
File Size Uploaded Provenance Actions
python-minimizer-2.0.1.tar.gz 6.5 kB Without provenance Details for python-minimizer-2.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for python-minimizer 2.0.1
File Interpreter ABI Platform Actions
python_minimizer-2.0.1-py3-none-any.whl Python 3 none any Details for python_minimizer-2.0.1-py3-none-any.whl

Total release size: 13.3 kB

Release files / python-minimizer-2.0.1.tar.gz

Download URL python-minimizer-2.0.1.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
74aa842865cb821bfe3b2bcaf3c85a917c3234f98621fcdb7814fe2b5b42c639
BLAKE2b-256 checksum
How to use checksums
18c0883d5e7a44b2ddd7b98a2f2e140faaaf4f384d61b8bf91c5bb1ff8e5f2f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.2.0 requests-toolbelt/0.8.0 tqdm/4.48.0 CPython/3.8.3

Release files / python_minimizer-2.0.1-py3-none-any.whl

Download URL python_minimizer-2.0.1-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a9f2b42e650c255e1d474f29aaff2afc0d179f88553ecbcbc19b26cde7e563fd
BLAKE2b-256 checksum
How to use checksums
618453a5e239b4d44721eaa38f86d7ae2dc6b1f652d86a6569e23860d6923de5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.2.0 requests-toolbelt/0.8.0 tqdm/4.48.0 CPython/3.8.3

Security for python-minimizer 2.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page