When distributing software that runs locally on client hardware—such as Raspberry Pi edge nodes or on-premise gateways—you run the risk of code reverse-engineering. Because Python is an interpreted language, standard compiled bytecode (.pyc files) can be decompiled back into readable source code within minutes using open-source utilities. To protect intellectual property, dynamic connection tokens, and parsing logic, developers must implement code obfuscation before building binaries.
By integrating PyArmor into the release pipeline, we can encrypt Python bytecode, restrict execution authorization, and bind binaries to specific physical hardware signatures.
1. Running Obfuscation with PyArmor
PyArmor encrypts the Python code objects at runtime. We run obfuscation checks on the source code, targeting entry scripts and modules:
# Install PyArmor
$ pip install pyarmor
# Obfuscate the Python project
$ pyarmor obfuscate --recursive --output dist/obfuscated_app/ main.py
# Run the obfuscated program
$ cd dist/obfuscated_app
$ python main.py
2. Restricting Execution and Binding to Hardware
To prevent clients from copying and running the edge daemon on unauthorized hardware, we use PyArmor to generate a license file bound to the target server's MAC address and set an expiration date:
# Generate a license bound to MAC address and set expiration to Dec 31, 2026
$ pyarmor licenses --expired 2026-12-31 --bind-mac "00:11:22:33:44:55" dev_license_01
# Apply the license to the obfuscated distribution
$ pyarmor obfuscate --with-license licenses/dev_license_01/license.lic main.py
3. Automated Verification Script
We write a script to verify that the target executable checks license validity and handles license expiry exceptions gracefully without leaking traceback details:
# license_verifier.py
import sys
def verify_runtime_execution():
try:
# Import an obfuscated module
import pyarmor_runtime
print("Obfuscation runtime loaded successfully.")
except ImportError as e:
print("CRITICAL: License invalid or expired! Exiting execution.", file=sys.stderr)
sys.exit(1)
if __name__ == "__main__":
verify_runtime_execution()
Implementing license checks and code encryption safeguards proprietary algorithms at the edge, maintaining system security even when clients have physical root access to devices.