skillfed

python-minifier

Transform Python source code into it's most compact representation

python-minifier v3.2.0 271.8K downloads/30d#8,219 on PyPI718
Permissive license MIT Active released

What it is and what it does

python-minifier rewrites Python source code into a functionally identical but much smaller form by collapsing whitespace, shortening variable names, and simplifying syntax. It was originally built to embed AWS Lambda functions in CloudFormation templates, which have a 4 KiB size limit for inline code.

The tool works as both a command-line utility (pyminify) and a Python API. It supports Python 2.7 and Python 3.3 through 3.14, and the minified output is compatible with the same Python version that ran the minifier. There are no runtime dependencies, making installation straightforward.

Use it for:

  • Embed Python Lambda functions in AWS CloudFormation templates under the 4 KiB inline code limit
  • Reduce deployment package size for serverless functions or edge computing environments
  • Obfuscate source code for distribution when combined with other techniques
  • Minimize Python code for resource-constrained environments or IoT devices
  • Compress utility scripts or one-off tools before transmission or storage

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Transforms Python source code into compact, functionally equivalent minified code by removing whitespace, renaming variables, and optimizing syntax.

Yes, if you need to shrink Python source code for deployment or embedding. The package is stable (Production/Stable status), has no dependencies, and carries no security vulnerabilities. The main caveat is that minified code runs only on the Python version that performed the minification, so test carefully if you minify on a different version than your target runtime.

Install

python-minifier on PyPI

pip

pip install python-minifier

uv

uv add python-minifier

poetry

poetry add python-minifier

Installing python-minifier

Before you install

Low friction: pure Python wheels for both Python 2 and 3, no runtime dependencies. Repository is active with recent commits and 718 stars; last release 226 days ago.

License in practice

MIT license is permissive; you can use, modify, and distribute this package freely in commercial and private projects with minimal restrictions.

Quickstart

pip install python-minifier

import python_minifier

with open('hello.py') as f:
    minified = python_minifier.minify(f.read())
    print(minified)

The minifier's output is compatible only with the Python version running the minifier itself; minifying Python 3.11 code with a Python 3.12 interpreter produces Python 3.12-only output.

Verify before relying

  • Whether minified code preserves all runtime semantics (e.g., introspection, dynamic imports, metaclass behavior)
  • Performance overhead of the minification process itself on large codebases
  • Compatibility guarantees when minifying code written for one Python version using an interpreter running a different version

Package facts

License MIT (permissive)
Python support supports the current Python release (!=3.0.*,!=3.1.*,!=3.2.*,<3.15,>=2.7)
Install friction low — pure-Python wheel
Runtime dependencies none
Maintenance actively maintained — 226 days since the last release
Last repo commit
First released
Downloads 271,756/month — #8,219 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: python_minifier-3.2.0-py2-none-any.whl; python_minifier-3.2.0-py3-none-any.whl

Keywords: minify, minifier

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: PythonProgramming Language :: Python :: 2Programming Language :: Python :: 2.7Programming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.3Programming Language :: Python :: 3.4Programming Language :: Python :: 3.5Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Software Development

Tags

python code minifierreduce python file sizecompact python sourcepython code compressionminify python scriptsshrink python bytecodepython source optimizer
code-compressiondeployment-optimizationaws-lambda

More Software Development packages