Playground
Original source next to real PyArmor output.
Generated by scripts/gen_playground.py with Pyarmor 9.2.7 (trial), 000000, non-profits on Python 3.12.13, which also checks both builds return the same result. Nothing runs in your browser.
examples/playground/simple_function.pyOriginal Python
readable source"""A single function: the smallest thing PyArmor can protect."""
def apply_discount(price: float, loyalty_years: int) -> float:
"""Loyal customers get 2% off per year, capped at 10%."""
discount = min(loyalty_years * 0.02, 0.10)
return round(price * (1 - discount), 2)Protected output
3,595 bytes, shortened# Pyarmor 9.2.7 (trial), 000000, non-profits, 2026-10-08T15:12:01.817852
from pyarmor_runtime_000000 import __pyarmor__
__pyarmor__(__name__, __file__, b'PY000000\x00\x03\x0c\x00\xcb\r\r\n\x80\x00\x01\x00\x08\x00\x00\x00\x04\x00\x00\x00@\x00\x00\x00_\x04\x00\x00\x12\t\x04\x00\xd5\x1e\xad\r\xa2Z#\xa4\xdb?\xbe\x0c+U\xa9(\x00\x00\x00\x00\x00\x00\x00\x00\x9d"6\x90\xe9\x8c\xe7\x85C)\x00\x15M\xd1]4\xd6@h\x01\xa0\x08o \xbcqp\x9f>\xda \xed\xdd\xd4\xa6Z\xffO\xec\xad\xc3D\x84\x97\n\xb7\x97\n\xa5\xcezF\x81v\\b\xdc\'d\xc9\xaa\\[\xbd\x93\x18\xcb\x17\xf9\xf8\x85M\x12\x0c\x07}\xe9\x0fz%\xb2\x80\xbcS\xdd\xf6\x9f\xb4\xfdO\x9fI>\x91\xe2t\xf0\xde\xf0Ir\xf3\xfb\xdf\x06\x06\xeeV\x0f\x84\x99\x93\xb3<\x03V\xa4\x81\xdc\xf7\xcaA\t[\r\x15E\xd4\x07\xb0\xcd=[`\x08u\x9bA\x91\x80\x06h9\xfb\xf4\xa3\x8d\xd8\xd3\x8a\xfe\xed \xad\xa5X\x03e\xfa\xc5+\xd1\x7f\x18\xab\xecR\xf0\x0c\xdf$*\xbf\x01\x01P\xcd\x80\xa8\x06L\xa9\xcc,\xe4\x85\x0f}\xec9I\x0c\'`\xe2+\xb5\xdd\x9ey4a&\x9c\tg\x91\xc5Y\xce\x7fd\x90\x19\xc3\xfaE#\xd99\x81\xf7\xae\xc6ku\xb2\x1 …(shortened)…✓ Same result from both builds
apply_discount(100, 3) → 94.0Explanation
What changed?
- The file is three lines: a comment, an import of the PyArmor runtime, and one call with an encrypted payload.
- Function names, constants, strings and comments cannot be found as text in the file.
- Each function is obfuscated on its own, and restored only while it runs.
What did not change?
- What the code does: every example returns the same value from both builds (below).
- Its interface: names you import, function signatures, HTTP routes.
- Values the code uses at runtime: once loaded, the process can still see them.
Why does it still run?
- On import, the runtime (a compiled extension) decrypts the payload into code objects in memory.
- Python then executes the same instructions as before; they are just not stored readably on disk.
- That is obfuscation, not encryption: the means to run the code ships with the code.