Pyarmor
Pyarmor is a command-line tool designed for obfuscating Python scripts, binding them to specific machines, and setting expiration dates. It focuses on protecting intellectual property by making Python source code difficult to reverse engineer while maintaining functionality. The library is actively maintained with frequent updates and new features, with its current version being 9.2.4.
Warnings
- breaking Pyarmor 9.0+ introduced significant changes to licensing for CI/CD pipelines. Pyarmor Pro licenses can no longer be used in CI/CD, requiring a new Pyarmor CI license. Basic licenses need an extra CI regfile. Users upgrading Group Licenses must regenerate device regfiles.
- gotcha Obfuscated scripts, especially those utilizing C extensions (`_pytransform`), are often platform and Python version-dependent. Running scripts obfuscated with one Python version (e.g., 3.8) on a different version (e.g., 3.7 or 3.9) can lead to crashes or 'Marshal loads failed' errors.
- gotcha The `pyarmor_runtime` package (or `pytransform` in older versions) and the `license.lic` file are crucial runtime dependencies. Failing to distribute these files with your obfuscated scripts, or placing them where Python cannot find them, will result in runtime errors such as `NameError: name '__pyarmor__' is not defined` or `Could not find _pytransform`.
- gotcha Starting with Pyarmor 9.2.2, default encoding for configuration files (`pyarmor cfg`) and project rule files changed to `utf-8`. Older configurations might implicitly rely on locale-specific encodings, potentially causing issues when reading or writing these files with the updated version.
- gotcha Certain advanced obfuscation modes (e.g., BCC, RFT, `--mix-str`) have historically encountered issues, including script crashes on specific Python versions (e.g., Python 3.9+, 3.12, 3.13) or platforms. While fixes are often released in subsequent patches, aggressive obfuscation can introduce subtle runtime bugs.
Install
-
pip install pyarmor
Imports
- __pyarmor__
from pyarmor_runtime import __pyarmor__
Quickstart
pyarmor gen foo.py python dist/foo.py