Skip to content

Minify and obfuscate Python source code.

License

Notifications You must be signed in to change notification settings

railgunlabs/minipy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Minipy

Minipy is a minifier and obfuscator for Python source code.

Homepage  Documentation

Example

Minipy converts a string (or file) of Python source code into a more compact form, optionally substituting variables with shorter variations where possible. Variable substitution honors imported modules regardless of whether they are 1st or 3rd party modules, e.g. it will not minifiy imported identifiers such as path or exists in os.path.exists().

Input:

import os

# Check if the JSON file exists.
def json_exists(filename: str) -> bool:
    with_ext = filename + ".json"
    return os.path.exists(with_ext)

Minified:

import os
def json_exists(filename:str)->bool:
 with_ext=filename+".json"
 return os.path.exists(with_ext)

Obfuscated:

import os
def a(b):
 c=b+"json
 return os.path.exists(c)

Command-line Usage

Minipy can be consumed as a library or as a standalone command-line program. Executing the following command from your shell will minify the Python file named filename.py. If no file is specified, then Minipy will read from stdin.

$ minipy filename.py

Minify and obfuscate with:

$ minipy --obfuscate filename.py

The -s flag suppresses obfuscation of identifiers. This is useful for preventing public functions, classes, variables, etc. from being obfuscated. The following command would prevent identifiers foo and bar from being obfuscated.

$ minipy --obfuscate -s foo -s bar filename.py

Installation

Minipy requires Python 3.12 or newer

Install Minipy by downloading the latest version from the releases page and installing with:

$ pip install minipy-0.9.2-py3-none-any.whl

Support

License

Minipy is free for non-commercial use. See LICENSE for details.

You can purchase a commercial license from Railgun Labs.

About

Minify and obfuscate Python source code.

Resources

License

Stars

Watchers

Forks

Packages

No packages published