A command-line tool for obfuscating Python scripts, binding obfuscated scripts to specific machines, and setting expiration dates
npx @tessl/cli install tessl/pypi-pyarmor@9.1.0A comprehensive Python script obfuscation tool that protects Python intellectual property through code obfuscation, hardware binding, and license management. PyArmor provides seamless replacement of original scripts with obfuscated versions while maintaining compatibility, offering multiple protection strategies from basic obfuscation to advanced machine-code compilation.
pip install pyarmorimport pyarmorFor programmatic access to legacy API:
from pyarmor import utils, project
from pyarmor.pyarmor import main_entry, main_entry_8For modern CLI components (advanced usage):
from pyarmor.cli.context import Context
from pyarmor.cli.generate import Builder
from pyarmor.cli.register import Register, WebRegister
from pyarmor.cli.config import Configer# Install PyArmor
pip install pyarmor
# Basic script obfuscation
pyarmor gen foo.py
# Obfuscate with options
pyarmor gen --recursive --output dist --mix-str src/
# Advanced obfuscation with hardware binding
pyarmor gen --bind-device "00:11:22:33:44:55" --expired "2024-12-31" foo.py
# Pack with PyInstaller
pyarmor gen --pack onefile foo.py
# Check configuration
pyarmor cfg
# Register license
pyarmor reg pyarmor-regcode-xxxx.txtimport os
from pyarmor import utils, project
# Initialize PyArmor environment
utils.pytransform_bootstrap()
# Create and configure project
proj = project.Project()
proj.name = "MyProject"
proj.src = "src"
proj.output = "dist"
proj.entry = "main.py"
proj.obf_code = 1 # Enable code obfuscation
proj.obf_mod = 1 # Enable module obfuscation
proj.save("myproject.json")
# Obfuscate scripts
capsule = utils.make_capsule(None)
utils.make_runtime(capsule, "dist")
utils.encrypt_script(capsule, "src/main.py", "dist/main.py")PyArmor employs a multi-layered protection architecture:
The tool supports multiple interface generations:
Primary interface for PyArmor providing obfuscation, configuration, and license management through intuitive commands. Supports both modern streamlined interface and legacy full-featured commands.
# Modern CLI Commands (pyarmor, pyarmor-8)
def gen(*args, **kwargs): ... # Generate obfuscated scripts
def cfg(*args, **kwargs): ... # Configuration management
def reg(*args, **kwargs): ... # License registration
def man(*args, **kwargs): ... # Interactive help system
# Legacy CLI Commands (pyarmor-7)
def obfuscate(*args, **kwargs): ... # Direct obfuscation without project
def init(*args, **kwargs): ... # Initialize project
def build(*args, **kwargs): ... # Build project
def config(*args, **kwargs): ... # Configure project
def licenses(*args, **kwargs): ... # Generate license files
def pack(*args, **kwargs): ... # Package with external toolsCreate, configure, and manage PyArmor projects for organized obfuscation workflows with persistent settings and batch processing capabilities.
class Project(dict):
def open(self, path: str) -> None: ...
def save(self, path: str) -> None: ...
def check(self) -> bool: ...
def get_build_files(self, force: bool = False, excludes: list = []) -> list: ...
def info(self) -> str: ...
def _update(self, **kwargs) -> None: ...Core obfuscation engine providing multiple protection levels from basic name mangling to advanced binary code compilation with machine instruction generation.
def encrypt_script(pubkey, filename: str, destname: str, wrap_mode: int = 1, obf_code: int = 1, obf_mod: int = 1, adv_mode: int = 0, rest_mode: int = 1, entry: int = 0, protection: int = 0, platforms = None, plugins = None, rpath = None, suffix: str = '', sppmode: bool = False, mixins = None) -> None: ...
def make_runtime(capsule, output: str, licfile = None, platforms = None, package: bool = False, suffix: str = '', supermode: bool = False) -> None: ...
def make_capsule(filename: str) -> None: ...
def make_entry(entris: str, path: str, output: str, rpath = None, relative = None, suffix: str = '', advanced: int = 0) -> None: ...
def make_bootstrap_script(output: str, **kwargs) -> None: ...Generate and manage licenses with hardware binding, expiration dates, and custom restrictions for controlling access to obfuscated scripts.
def make_license_key(capsule, code: str, output: str = None, key = None, legency: int = 0) -> None: ...
def query_keyinfo(key: str) -> dict: ...
def activate_regcode(ucode: str) -> dict: ...
def register_keyfile(filename: str, upgrade: bool = False, legency: bool = False) -> None: ...
def get_registration_code() -> str: ...System-wide and project-specific configuration with hierarchical settings and interactive configuration shell for managing obfuscation parameters.
class Configer:
def list_sections(self, local: bool = True, name: str = None) -> list: ...
def list_options(self, sect: str, local: bool = True, name: str = None) -> list: ...
def run(self, options: list, local: bool, name: str) -> None: ...
def reset(self, options: list, local: bool, name: str) -> None: ...
class Context:
def __init__(self, *paths): ...
def push(self, options: dict) -> None: ...
def get_res_options(self, fullname: str, catalog: str) -> dict: ...Cross-platform obfuscation with automatic platform detection, library downloading, and support for 40+ target platforms including embedded systems.
def show_hd_info(name: str = None) -> str: ...
def download_pytransform(platname: str, **kwargs) -> None: ...
def check_cross_platform(platforms: list, **kwargs) -> None: ...
def get_platform_name() -> str: ...
def format_platform(system: str = None, machine: str = None) -> str: ...# Project Configuration
class ProjectConfig:
name: str
title: str
src: str
output: str
entry: str
obf_code: int # 0=disable, 1=enable, 2=advanced
obf_mod: int # 0=disable, 1=enable
wrap_mode: int # 0=disable, 1=enable
advanced_mode: int # 0-5 protection levels
restrict_mode: int # 0=none, 1=import, 2=private, 3=restrict
runtime_path: str
platform: str
package_runtime: int
cross_protection: int
license_file: str
# Obfuscation Options
class ObfuscationOptions:
recursive: bool
output: str
obf_module: int
obf_code: int
mix_str: bool
enable_bcc: bool
enable_jit: bool
enable_rft: bool
enable_themida: bool
assert_call: bool
assert_import: bool
restrict_module: int
platforms: list
outer: bool
expired: str
period: int
devices: list
bind_data: str
# Registration Info
class RegistrationInfo:
product: str
version: str
lictype: str
features: list
expired: str
devices: int
platform: str