--- id: python-minifier version: "3.2.0" license: MIT license_treatment: permissive maintenance: active --- # python-minifier — Transform Python source code into it's most compact representation License: permissive · Maintenance: active · Downloads: 271.8K/mo ## 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 above — 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 pip install python-minifier uv add python-minifier 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_current - Install friction: low - Maintenance: active - Downloads: 271.8K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags python code minifier, reduce python file size, compact python source, python code compression, minify python scripts, shrink python bytecode, python source optimizer, code-compression, deployment-optimization, aws-lambda [View on SkillFed](https://skillfed.io/packages/python-minifier) · [View on PyPI](https://pypi.org/project/python-minifier/)