Package: pyminifier
Pyminifier is a Python code minifier, obfuscator, and compressor.NoteFor the latest, complete documentation:http://liftoff.github.io/pyminifier/For the latest code:https://github.com/liftoff/pyminifierOverviewWhen you install pyminifier it should automatically add a ‘pyminifier’
executable to your$PATH.  This executable has a number of command line
arguments:$pyminifier--helpUsage:pyminifier[options]"<input file>"Options:--versionshowprogram's version number and exit
-h, --help            show this help message and exit
-o <file path>, --outfile=<file path>
                      Save output to the given file.
-d <file path>, --destdir=<file path>
                      Save output to the given directory. This option is
                        required when handling multiple files. Defaults to
                        './minified' and will be created if not present.
--nominify            Don'tbotherminifying(onlyusedwith--pyz).--use-tabsUsetabsforindentationinsteadofspaces.--bzip2bzip2-compresstheresultintoaself-executingpythonscript.Onlyworksonstand-alonescriptswithoutimplicitimports.--gzipgzip-compresstheresultintoaself-executingpythonscript.Onlyworksonstand-alonescriptswithoutimplicitimports.--lzmalzma-compresstheresultintoaself-executingpythonscript.Onlyworksonstand-alonescriptswithoutimplicitimports.--pyz=<nameofarchive>.pyzzip-compresstheresultintoaself-executingpythonscript.Thiswillcreateanewfilethatincludesanynecessaryimplicit(localtothescript)modules.Willinclude/processallfilesgivenasargumentstopyminifier.pyonthecommandline.-O,--obfuscateObfuscateallfunction/methodnames,variables,andclasses.DefaultistoNOTobfuscate.--obfuscate-classesObfuscateclassnames.--obfuscate-functionsObfuscatefunctionandmethodnames.--obfuscate-variablesObfuscatevariablenames.--obfuscate-import-methodsObfuscateglobally-importedmouledmethods(e.g.'Ag=re.compile').--obfuscate-builtinsObfuscatebuilt-ins(i.e.True,False,object,Exception,etc).--replacement-length=1Thelengthoftherandomnamesthatwillbeusedwhenobfuscatingidentifiers.--nonlatinUsenon-latin(unicode)charactersinobfuscation(Python3only).WARNING:ThisresultsinsomeSERIOUSLYhard-to-readcode.--prepend=<filepath>Prependthetextinthisfiletothetopofouroutput.e.g.Acopyrightnotice.For the examples below we’ll be minifying, obfuscating, and compressing the
following totally made-up Python script (saved to/tmp/tumult.py):#!/usr/bin/env python
"""
tumult.py - Because everyone needs a little chaos every now and again.
"""

try:
    import demiurgic
except ImportError:
    print("Warning: You're not demiurgic. Actually, I think that's normal.")
try:
    import mystificate
except ImportError:
    print("Warning: Dark voodoo may be unreliable.")

# Globals
ATLAS = False # Nothing holds up the world by default

class Foo(object):
    """
    The Foo class is an abstract flabbergaster that when instantiated
    represents a discrete dextrogyratory inversion of a cattywompus
    octothorp.
    """
    def __init__(self, *args, **kwargs):
        """
        The initialization vector whereby the ineffably obstreperous
        becomes paramount.
        """
        # TODO.  BTW: What happens if we remove that docstring? :)

    def demiurgic_mystificator(self, dactyl):
        """
        A vainglorious implementation of bedizenment.
        """
        inception = demiurgic.palpitation(dactyl) # Note the imported call
        demarcation = mystificate.dark_voodoo(inception)
        return demarcation

    def test(self, whatever):
        """
        This test method tests the test by testing your patience.
        """
        print(whatever)

if __name__ == "__main__":
    print("Forming...")
    f = Foo("epicaricacy", "perseverate")
    f.test("Codswallop")By default pyminifier will perform basic minification and print the resulting
code to stdout:NoteThe tumult.py script is 1358 bytes.  Remember that.#!/usr/bin/env pythonﵛ=ImportErrorࡅ=print㮀=False搓=objecttry:importdemiurgicexceptﵛ:ࡅ("Warning: You're not demiurgic. Actually, I think that's normal.")try:importmystificateexceptﵛ:ࡅ("Warning: Dark voodoo may be unreliable.")ﵩ=㮀classרּ(搓):def__init__(self,*args,**kwargs):passdef𐨱(self,dactyl):ﱲ=demiurgic.palpitation(dactyl)ꁁ=mystificate.dark_voodoo(ﱲ)returnꁁdef𨠅(self,whatever):ࡅ(whatever)if__name__=="__main__":ࡅ("Forming...")녂=רּ("epicaricacy","perseverate")녂.𨠅("Codswallop")# Created by pyminifier.py (https://github.com/liftoff/pyminifier)This reduced the size of tumult.py from 1358 bytes to 640 bytes.  Not bad!Minifying by itself can reduce code size considerably but pyminifier can go
further by obfuscating the code.  What that means is that it will replace the
names of things like variables and functions to the smallest possible size.To see more examples of pyminifier in action (e.g. compression features) see thefull documentationSpecial SauceSo let’s pretend for a moment that your intentions are not pure; that you
totally want to mess with the people that look at your minified code.  What you
need is Python 3 and the--nonlatinoption…#!/usr/bin/env python3ܗ=ImportErrorܡ=printܪ=Falseٽ=objecttry:importdemiurgicexceptܗ:ܡ("Warning: You're not demiurgic. Actually, I think that's normal.")try:importmystificateexceptܗ:ܡ("Warning: Dark voodoo may be unreliable.")ܬ=ܪclassظ(ٽ):def__init__(self,*args,**kwargs):passdefط(self,dactyl):ټ=demiurgic.palpitation(dactyl)ⶹ=mystificate.dark_voodoo(ټ)returnⶹdefܘ(self,whatever):ܡ(whatever)if__name__=="__main__":ܡ("Forming...")f=ظ("epicaricacy","perseverate")f.test("Codswallop")# Created by pyminifier.py (https://github.com/liftoff/pyminifier)Yes, that code actually worksbut only using Python 3.  This is because Python
3 supports coding in languages that use non-latin character sets.NoteMost text editors/IDEs will have a hard time with code generated using the--nonlatinoption because it will be a random mix of left-to-right
and right-to-left characters.  Often the result is some code appearing on
the left of the screen and some code appearing on the right.  This makes itreallyhard to figure out things like indentation levels and whatnot!There’s even more ways to mess with people in thefull documentation