Chapter 04
PyArmor Setup
⏱ 5 minutes · You will check the PyArmor version, read its license status, and learn which features the free trial includes.
PyArmor is already installed
uv sync installed PyArmor from the protect dependency group in pyproject.toml:
[dependency-groups]
# The obfuscator. Needed on the build machine only, never in the runtime image.
protect = ["pyarmor==9.2.7"]It is a separate group on purpose: PyArmor is a build tool. The machine that runs the protected app never needs it. (PyArmor's own docs say the same: do not install it on the target device.)
Installing it on its own, anywhere else:
pip install pyarmor==9.2.7Check the version
uv run pyarmor --versionWhat it does: prints the PyArmor version and the license it runs under. Why: PyArmor's command line changed a lot between major versions, so always know which one you have. This workshop was written and tested with 9.2.7. Expected:
Pyarmor 9.2.7 (trial), 000000, non-profits
License Type : pyarmor-trial
License No. : pyarmor-vax-000000
...
BCC Mode : No
RFT Mode : No
CI/CD Mode : No
Notes
* Can't obfuscate big script and mix strThe commands you will use
uv run pyarmor gen --helpWhat it does: shows the options of pyarmor gen, the command that generates protected
scripts and their runtime.
Why: almost everything in this workshop is one pyarmor gen call with different options.
Expected: a usage line starting usage: pyarmor gen [-h] [-O PATH] ...
| Option | Meaning | Chapter |
|---|---|---|
-O PATH | output folder (default dist/) | 05 |
-r | recurse into sub-packages | 05 |
--exclude PATTERN | leave paths out | 05 |
-i | put the runtime inside the package | 06 |
-e DATE / -e DAYS | expire the build | 06 |
-b DEV | bind the build to a device | 06 |
--pack onedir|onefile | bundle with PyInstaller | 08 |
Version-sensitive commands
The trial, and licensing
The trial never expires and covers everything in this workshop. Its limits, from PyArmor's license page and our own tests:
| Trial | Paid licenses | |
|---|---|---|
| Obfuscate scripts and packages, runtime, expiry, device binding, PyInstaller packing | ✓ | ✓ |
| Big scripts (a module above a certain size) | ✗ out of license | Basic and above |
--mix-str (protect string constants) | ✗ | Basic and above |
| BCC mode (compile functions to C), RFT mode (rename names) | ✗ | Pro, Group, CI |
| CI/CD pipelines, local Docker builds | ✓ (fewer than 100 runs a month) | depends on the plan |
How big is "big"? PyArmor does not publish the threshold. In our tests on 9.2.7, a module with 30 realistic functions passed, and one with 200 tiny functions failed. The limit depends on the compiled code, not on the file size in bytes. That is one reason this app is split into small, focused modules (which is good design anyway).
If you have a license, register it on the build machine with pyarmor reg <regfile>. In CI, store
the registration file as an encrypted secret, never in the repository (chapter 12).