Skip to content
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
There is a small typo in src/examples/, src/

Should read `executable` rather than `executeable`.
3 contributors

Users who have contributed to this file

@jondy @timgates42 @axxyhtrx

Examples (中文版)

A good example maybe is the best teacher. There are several sample shell scripts distributed with source package of PyArmor. All of them are rich comment used to obfuscate Python scripts in different cases, .bat for Windows, .sh for Linux and MacOS. Find them in the path examples, edit the variables in it according to actual enviroments, then run it to obfuscate your python scripts quickly.

Not only those scripts, but also some really examples are distributed with PyArmor. Just open a command window, follow the instructions in this document, learn how to use PyArmor by these examples.

In the rest sections, assume that Python is installed, it can be called python. And PyArmor has been installed in the /path/to/pyarmor.

Shell commands will shown for Unix-based systems. Windows has analogous commands for each.

Example 1: Obfuscate scripts

Learn from this example

  • How to obufscate python scripts in the path examples/simple
  • How to run obfuscated scripts
  • How to distribute obfuscated scripts
  • How to set expired data of obfuscated scripts
    cd /path/to/pyarmor

    # Obfuscate python scripts in the path `examples/simple`
    pyarmor obfuscate --recursive examples/simple/

    # Obfuscated scripts saved in the output path `dist`
    cd dist

    # Run obfuscated scripts

    # Zip all the files in the path `dist`, distribute this archive
    zip .

    # If you'd like to expired the obfuscated scripts
    cd /path/to/pyarmor

    # Generate an expired license on 2020-10-01, save it in "licenses/r001"
    pyarmor licenses --expired 2020-10-01 r001

    # Obfuscate with --with-license
    pyarmor obfuscate --recursive --with-license licenses/r001/license.lic examples/simple/

    # Zip all the files in the path `dist`, distribute new archive
    cd dist
    zip .

Example 2: Obfuscate package

Learn from this example

  • How to obfuscate a python package mypkg in the path examples/testpkg
  • How to expire this obfuscated package on some day by outer license file
  • How to import obfuscated package mypkg by outer script
  • How to distribute obfuscated package to end user
    cd /path/to/pyarmor

    # Obfuscate all the python scripts in the package, obfuscated package saved in the path `dist/mypkg`
    # Enable outer license by option "--with-license outer"
    pyarmor obfuscate --output=dist/mypkg --with-license=outer examples/testpkg/mypkg/

    # Generate an expired license on 2020-10-01
    pyarmor licenses --expired 2020-10-01 r002

    # Overwrite the default license
    cp licenses/r002/license.lic dist/mypkg

    # Import functions from obfuscated package
    cd dist
    cp ../examples/testpkg/ ./

    # Zip the whole path `mypkg`, distribute this archive
    zip -r mypkg

Example 3: Build with project

Learn from this example

  • How to use project to manage obfuscated scripts
  • How to bind obfuscated scripts to harddisk, network card
  • How to distribute obfuscated scripts to different platform
  • How to generate license for each user

In this example, obfuscated script in the path examples/simple will be distributed to three customers with different licenses:

  • John, run on any Ubuntu 64, but expired on May 5, 2019
  • Lily, run one Windows 10 (64-bit), the serial number of harddisk is 100304PBN2081SF3NJ5T
  • Tom, run on Raspberry Pi, mac address of network card is 70:f1:a1:23:f0:94, and expired on May 5, 2019
    cd /path/to/pyarmor

    # Create a project in the path `projects/simple`
    pyarmor init --src=examples/simple projects/simple

    # Config the project with outer license
    pyarmor config --with-license=outer

    # Change to project path
    cd projects/simple

    # A shell script "pyarmor" is created here (In windows it is "pyarmor.bat")
    # Use command `build` to obfuscate all the `.py` in the project
    pyarmor build

    # Generate licenses for each customer
    # For John, generate an expired license, new license in "licenses/john/license.lic"
    pyarmor licenses --expired 2019-03-05 john

    # For Lily, generate a license bind to harddisk, new license in "licenses/lily/license.lic"
    pyarmor licenses --bind-disk '100304PBN2081SF3NJ5T' lily

    # For Tom, generate an expired license bind to mac address, new license in "licenses/tom/license.lic"
    pyarmor licenses --bind-mac '70:f1:a1:23:f0:94' --expired 2019-03-05 tom

    # Create distribution package for John
    mkdir -p customers/john

    # Copy obfuscated scripts
    cp -a dist/ customers/john

    # Replace default license
    cp licenses/john/license.lic customers/john/dist

    # Replace platform-dependent dynamic library `_pytransform`
    rm -f customer/john/dist/_pytransform.*
    wget -O customer/john/dist/

    # Zip all files in the path `customer/john/dist`, distribute the archive to John

    # Do the same thing for Lily and Tom, except for platform-dependent dynamic library `_pytransform`
    # For Lily

    # For Tom

Example 4: Pack obfuscated scripts

Learn from this example

  • How to pack obfuscated script by command pack

The prefer way is PyInstaller, first install PyInstaller

pip install pyinstaller

Then run command pack to pack obfuscated scripts

cd /path/to/pyarmor
pyarmor pack -O dist examples/simple/

Run the final executable file