Skip to main content
Guides

Python Obfuscator vs Compiler vs Packager: What's the Difference?

By Mithun··9 min read
Quick Answer

They do different jobs. An obfuscator (like Pyobfuscate) rewrites your source so it's hard to read but still runs as Python. A compiler (Cython, Nuitka) turns Python into native machine code with no bytecode to decompile, but string literals stay readable. A packager (PyInstaller) bundles your bytecode and the interpreter into one file so people can run it; it protects nothing. I tested all three on one file on 25 October 2026: only the obfuscator hid the secret. Obfuscating and *then* compiling worked with Nuitka but failed with Cython, and obfuscate-then-package worked with one extra PyInstaller flag.

PyInstaller, Cython, Nuitka, PyArmor, "obfuscators": these get lumped together as "tools that protect Python", and people pick the wrong one all the time. They're three different categories doing three different jobs.

So I took one small file with a hard-coded license key, ran it through each category, and then tried the combinations people recommend. Everything below is from 25 October 2026 on Windows 11 with Python 3.14.2: our obfuscator engine, Cython 3.3.0, Nuitka 4.3.1 and PyInstaller 6.22.3.

Three different jobs

CategoryExample toolsWhat it doesProtection
ObfuscatorPyobfuscate, PyArmorRewrites source to be unreadable (still Python)Hides names, strings and structure
CompilerCython, NuitkaTurns Python into native machine codeRemoves bytecode; strings still readable
PackagerPyInstaller, cx_Freeze, py2exeBundles bytecode + interpreter into one fileNone (distribution only)

All three change how your code ships, which is why they get confused. Only the first two aim at *protection*, and they protect different things. Here's the evidence.

The test: one file through all three

The input is deliberately tiny, so the difference each tool makes is easy to see: 6 lines, 165 bytes, with a license key hard-coded the way a lot of real apps do it.

KEY = "PYOB-2026-PRO-9f83kd"
def check(code):
if code == KEY:
return "licensed"
return "trial mode"
print(check("PYOB-2026-PRO-9f83kd"), check("x"))
lic.py — the test input

For each output I checked three things: does it still run (it should print licensed trial mode), how big is it, and can the key be found. For the packaged exe I didn't stop at a byte search; I used PyInstaller's own archive reader to pull the script back out and listed its strings.

CategoryToolOutputRuns?Key recoverable?
ObfuscatorPyobfuscate (basic)13.3 KB .pyYesNo
ObfuscatorPyobfuscate (pro)55.7 KB .pyYesNo
CompilerCython 3.3.036.9 KB native .pyd (built in 4 s)YesYes: plain byte search finds it
CompilerNuitka 4.3.1 --module233 KB native .pyd (built in 5 s)YesYes: found twice
PackagerPyInstaller 6.22.3 --onefile9.2 MB .exe (built in 12 s)YesYes: extracted in seconds

The packaged exe is the sneaky one. Searching the .exe file for the key finds nothing, because PyInstaller zlib-compresses the bytecode. But one call to PyInstaller's own CArchiveReader gave me the script back, and the first string in it was PYOB-2026-PRO-9f83kd. Compressed isn't hidden. Full walk-through: does PyInstaller protect source code?

Obfuscator: still Python, just unreadable

An obfuscator transforms your source into equivalent, runnable Python. Our Python Obfuscator renames identifiers, encrypts strings, flattens control flow and injects junk. In the test the 165-byte file became 13.3 KB in basic mode and 55.7 KB in pro mode; both ran correctly, and the key wasn't in either output.

What it protects: readability, names, structure and string literals. What it doesn't: it's still Python bytecode at runtime, so a decompiler gives back the *obfuscated* version, not your original. PyArmor is also an obfuscator; its differentiator is a licensing runtime (expiry, hardware binding). See PyArmor vs Pyobfuscate.

Compiler: native code, no bytecode to decompile

A compiler turns Python into a native binary. Cython compiles a module to a `.pyd`/`.so`: my file became a 36.9 KB lic.cp314-win_amd64.pyd in 4 seconds, and there is no bytecode in it, so .pyc decompilers can't touch it. Nuitka made a 233 KB module from the same file in 5 seconds (it bundles more of its own runtime) and can also compile a whole app to a standalone binary.

What it protects: the logic, strongly (someone would have to read machine code). What it doesn't: string literals. A plain byte search found PYOB-2026-PRO-9f83kd in the Cython .pyd and twice in the Nuitka one. You also need a C compiler and a separate build for every OS and Python version. Compare Nuitka vs PyArmor and Cython vs Nuitka.

Packager: bundles, but doesn't protect

A packager like PyInstaller solves distribution: it bundles the interpreter plus your bytecode into one executable, so users don't need Python installed. My 165-byte script became a 9.2 MB `.exe` that ran standalone. But your bytecode is inside, unchanged, and PyInstaller ships the reader that gets it back out; the third-party pyinstxtractor does the same in one command. From there it's the same decompile story as any `.pyc`.

A PyInstaller .exe is packaging, not protection. If your logic matters, protect it before packaging. Full walk-through: convert Python to EXE and protect it.

Combining them: what worked and what crashed

The usual advice is "use all three". I tried the combinations people actually mean:

CombinationResultKey recoverable?
Obfuscate → package (PyInstaller)Works (9.25 MB exe, built in 10 s)No: the extracted script had 27 strings, none of them the key
Obfuscate → Nuitka on the same moduleWorks (2.25 MB .pyd, built in 17 s)No
Obfuscate → Cython on the same moduleFails: basic mode won't compile; pro mode compiles (82 s, 525 KB) then crashes on importn/a
Cython for one module + obfuscate the rest → packageWorks (9.27 MB exe), but only with --hidden-import for the compiled moduleOnly from the compiled module

Why obfuscate-then-Cython fails: obfuscated code defines its helpers at runtime (through globals()), and Cython needs to see every name at compile time. Basic-mode output stopped with undeclared name not builtin. Turning on Cython's error_on_unknown_names = False let pro-mode output compile, but importing the module then raised a KeyError. Cython translates names to C at compile time; obfuscated code creates them at runtime. Nuitka is built to run any valid Python, including dynamic code like this, and the obfuscated module compiled and ran with the key still hidden; it just came out much bigger (2.25 MB vs 233 KB) because there's more code to compile.

The split setup needs one extra flag. Obfuscation hides import lic from PyInstaller's scanner, so without --hidden-import lic the exe built fine and then failed with Failed to execute script. With it, the exe ran correctly.

# 1. compile the sensitive module (its .py stays on your machine)
cythonize -i lic.py -> lic.cp314-win_amd64.pyd
# 2. obfuscate everything else, e.g. app.py -> app_obf.py
# 3. package; name the compiled module and the obfuscator's runtime imports
pyinstaller --onefile --paths . --hidden-import lic ^
--hidden-import hmac --hidden-import bz2 --hidden-import lzma --hidden-import zlib app_obf.py
The split setup that worked (Windows, Python 3.14)

Which do you actually need?

  1. "Users don't have Python installed" → Packager (PyInstaller). That's a distribution problem, not a protection one.
  2. "Hide my source, fast and free" → Obfuscator (Pyobfuscate). It hides names *and* strings and needs no toolchain.
  3. "Really protect an algorithm" → Compiler (Cython for a module, Nuitka for the app). Native code, no bytecode. Strings stay readable, so either move secrets out of that module or obfuscate it first and compile with Nuitka (that worked; Cython didn't).
  4. "Enforce licenses / expiry / hardware lock" → an obfuscator with DRM (PyArmor) or a licensing service that checks on a server you control.

For most commercial code the tested answer is: compile the few modules that are your real edge, obfuscate everything else, then package. If a compiled module also needs its strings hidden, obfuscate it and compile it with Nuitka, not Cython. And keep real secrets (API keys, signing keys) off the client entirely: everything here runs on the user's machine. For the honest limits, see can Python code be decompiled? and how to protect Python source code.

Obfuscate your Python — free

Whichever you package or compile with, obfuscate the source first so there's nothing readable to recover. Rename, encrypt strings, flatten flow — in your browser, no install.

Open the Python Obfuscator

Free tools mentioned here

Related guides

Frequently asked questions

What's the difference between a Python obfuscator, compiler, and packager?

An obfuscator rewrites your source to be unreadable but still runnable Python. A compiler (Cython, Nuitka) turns Python into native machine code with no bytecode to decompile, but string literals stay readable. A packager (PyInstaller) bundles your bytecode and the interpreter into one file for distribution and protects nothing. In my October 2026 test on one file, only the obfuscator hid a hard-coded key.

Does PyInstaller protect my Python source code?

No. PyInstaller compresses your bytecode inside the exe, so a byte search finds nothing, but PyInstaller's own archive reader extracted my script in seconds with the license key intact. pyinstxtractor does the same. Obfuscate or compile before packaging if the logic matters.

Can I compile obfuscated Python code with Cython or Nuitka?

With Cython, no. In my test (Cython 3.3.0, Python 3.14), basic-mode obfuscated code wouldn't compile (undeclared name not builtin), and pro-mode code compiled only with error_on_unknown_names = False and then crashed on import with a KeyError. Nuitka 4.3.1 did work: the obfuscated module compiled in 17 seconds, ran correctly and the key stayed hidden.

Is Cython an obfuscator?

No, it's a compiler: it turns Python into C and then native machine code. That removes the bytecode, so decompilers can't rebuild your source, but string literals stay in the binary. In my test a plain byte search found the hard-coded key in the Cython .pyd (and twice in the Nuitka one).

Should I obfuscate, compile, or package my Python app?

Package (PyInstaller) so users without Python can run it, obfuscate (Pyobfuscate) to hide names and strings cheaply, compile (Cython/Nuitka) to protect an algorithm with native code. For commercial code: compile the few key modules, obfuscate the rest, then package with --hidden-import for the compiled module. That worked in my test, and so did obfuscating a module first and compiling it with Nuitka (Cython failed).

Keep reading