Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

mnfy — minify/obfuscate Python 3 source code

Web Pages

What the heck is mnfy for?

The mnfy project was created for two reasons:

  • To show that shipping bytecode files without source, as a form of obfuscation, is not the best option available

  • Provide a minification of Python source code when total byte size of source code is paramount

When people ship Python code as only bytecode files (i.e. only .pyo files and no .py files), there are couple drawbacks. First and foremost, it prevents users from using your code with all available Python interpreters such as Jython and IronPython. Another drawback is that it is a poor form of obfuscation as projects like Meta allow you to take bytecode and reverse-engineer the original source code as enough details are kept that the only details missing are single-line comments.

When the total number of bytes used to ship Python code is paramount, then you want to minify the source code. Bytecode files actually contain so much detail that the space savings can be miniscule (e.g. the decimal module from Python’s standard libary, which is the largest single file in the stdlib, has a bytecode file that is only 5% smaller than its source code.

Usage

A note about version numbers and Python version compatibility

The version number for mnfy is PEP 386 compliant, taking the form of PPP.FFF.BBB. The FFF.BBB represents the feature and bugfix version numbers of mnfy itself. The PPP portion of the version number represents the Python version that mnfy is compatible with: '{}{}'.format(*sys.version_info[:2]).

The Python version that mnfy is compatible with is directly embedded in the version number as Python’s AST is not guaranteed to be backwards-compatible. This means that you should use each version of mnfy with specific version of Python. Since mnfy works with source code and not bytecode you can safely use mnfy on code that must be backwards-compatible with older versions of Python, just make sure the interpreter you use with mnfy is correct and can parse the source code (e.g. just because the latest version of mnfy only works with Python 3.3 does not mean you cannot use that release against source code that must work with Python 3.2, just make sure to use a Python 3.3 interpreter with mnfy and that the source code can be read by a Python 3.3 interpreter).

Command-line Usage

TL;DR: pass the file you want to minify as an argument to mnfy and it will print to stdout the source code minifited such that the AST is exactly the same as the original source code. To get transformations that change the AST to varying degrees, use some flags.

See the help message for the project for full instructions on usage:

python3 -m mnfy -h
python3 mnfy.py -h

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mnfy-33.0.0.zip (22.3 kB view details)

Uploaded Source

File details

Details for the file mnfy-33.0.0.zip.

File metadata

  • Download URL: mnfy-33.0.0.zip
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for mnfy-33.0.0.zip
Algorithm Hash digest
SHA256 5206e61087f4630975fc6e0a0958b52717fc50f44b82ac8da7865938a5b5c2fb
MD5 1382e6bf97f0d4d5e970b6c3a632ec15
BLAKE2b-256 5e7a9b16eda0867ee19ddd4f1c5e3c1910d4160f7ef7d0d3ff616a1979dd2b78

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page