Py2Native Python to native compilerPython-zu-Native-Compiler

← All posts

2026-11-04

Cython vs Nuitka vs Py2Native: Which Protects Python Code?

Cython vs Nuitka vs Py2Native: Which Protects Python Code?
python compiler cython code protection open source

Cython vs Nuitka vs Py2Native: Which Protects Python Code?

You have a Python codebase that is your product. You want to ship it as a native binary, not as a folder of readable .py files someone can open in an editor thirty seconds after installing your package. So you start comparing tools, and three names keep coming up: Cython, Nuitka, and Py2Native.

This is a buying decision, and the three options are not equivalent. They differ in how much work you do before the first build, how much of your source survives compilation, and whether licensing or integration is a first-class concern or a DIY project.

One thing to get straight up front: this is not a performance article. Cython and Nuitka can both make Python faster, and that is a legitimate reason to use them. But if your problem is “how do I ship proprietary Python without shipping the source,” you should evaluate on a different axis — build effort, protection, and deployment simplicity.

The core question this comparison answers: which tool lets you keep writing plain Python and still get a protected native binary with minimal build configuration?

The Landscape: Three Approaches to Python Code Protection

Freezing tools like PyInstaller bundle an interpreter and your .py files; the source is still there. The three options below actually compile code, which is why they’re in this comparison.

Cython: the low-level transpiler

Cython turns Python-like code into C, which you then compile with a C compiler. It is powerful, mature, and the engine under several commercial tools — including this one.

But the workflow is on you. Realistically that means:

  • Rewriting or annotating modules as .pyx files, with .pxd declarations for anything crossing a module boundary.
  • Running a cythonize step yourself, then compiling the generated .c.
  • Knowing enough about C extensions to debug linking problems, include paths, and platform differences.
  • Extending the build every time you add a module or a platform.

You can absolutely protect code this way. You can also spend a week on build infrastructure before shipping anything.

Nuitka: the Python-to-C compiler

Nuitka takes standard Python and compiles it to C, which is a friendlier starting point than Cython’s dialect. Protection depends heavily on how you configure the build — options, module inclusion strategy, and what gets left as dynamic Python. In practice, teams often end up writing build configuration to get the level of hiding they expected out of the box.

It is a solid compiler. It is not a zero-config answer, and it does not ship license-key verification.

Py2Native: Cython without the Cython

Py2Native compiles your custom Python into native machine code and uses Cython internally to do it — but you never see that layer. No .pyx files. No .pxd declarations for your modules. No manual cythonize. No C extensions to write. You run one command:

uv run py2native build main.py *.py

The core compiler is MIT-licensed and open source. A proprietary Pro plugin adds signed JWT license verification when you need to gate the binary.

The shared caveat: third-party libraries

All three approaches focus on your code. Third-party Python libraries you depend on are generally left as Python source unless you also compile them. That’s normal and even desirable — it keeps upgrades and LGPL compliance simple. When this article says “protects your code,” it means the code you wrote.

Selection Criteria: How to Compare Protection Tools

Five criteria matter for a commercial Python product:

  • Ease of use. Do you write plain Python, or do you learn Cython syntax and C-extension plumbing? This is the biggest hidden cost, because it’s paid on every future change, not once.
  • Automation. Can the tool run as a single CI step, or does it need custom scripts, per-module flags, and platform-specific glue? See Automate Compiling Python to Native Binaries in CI/CD for what that pipeline should look like.
  • Security. How hard is it to recover your logic from the artifact? Any compiled binary can be reverse-engineered with enough effort — Is Compiled Python Really Unreadable? An Honest Look covers the realistic threat model.
  • Integration. Does it produce artifacts your deployment already understands — wheels, uv-managed environments, executables — or a bespoke output you have to wrap?
  • Price. Open-source compiler versus open-source core plus a commercial add-on. Python Code Protection Tools: What You Get for the Price breaks down the tiers.

Side-by-Side Comparison: Cython vs Nuitka vs Py2Native

Cython Nuitka Py2Native
Input format .pyx / .pxd (Cython dialect) plain .py plus build config plain .py
Build steps write .pyx, run cythonize, compile .c, link tool-driven compile, flags often needed one command: uv run py2native build
C / C-extension knowledge required for non-trivial projects not required, but config helps not required
Output type shared object per compiled module executable or module, depending on flags shared library (.pyd / .so / .dylib), PEP 427 wheel, or executable via --embed
Third-party libraries you manage the build for each mostly works, configuration sometimes needed left unmodified, work as-is with minimal or no configuration
License verification not built in not built in Pro plugin: ES256 JWT, public key and verifier baked into the binary
Licensing open-source compiler open-source compiler core compiler MIT; Pro plugin proprietary
CI integration custom scripts custom scripts and flags single command, --wheel and --embed produce deployable artifacts

The row that matters most is the first one. Py2Native is built on Cython, but it requires zero Cython knowledge from you. That’s the whole differentiator: you get Cython-grade native output without adopting Cython’s authoring model or maintaining its build.

A note on the Pro plugin

Py2Native Pro adds JWT license verification. You add a .pxd file declaring the verification entry point, and your code calls it:

# _p2n_bootstrap.pxd
cdef _runtime_verify_es256_jwt(token, expected_iss=*, expected_aud=*)
from _p2n_bootstrap cimport _runtime_verify_es256_jwt

def unlock(str licenseString):
    license = _runtime_verify_es256_jwt(licenseString, expected_iss="RSJ Software GmbH", expected_aud="TimestampGIT")
    return license

That’s the entire compiled-boundary surface you touch. Everything else stays ordinary Python. The plugin bakes the signature verification code and the public key into the executable — only the public key ships, and the elliptic-curve verification is compiled into the product with no third-party crypto libraries. Full walkthrough: Verify a License Key Inside a Compiled Python Binary.

Fairness: known constraints

  • No two source files may share the same module name.
  • Monkey-patching still works — third-party libraries remain Python source.
  • LGPL libraries stay replaceable by the end user, for compliance.
  • __init__.py is skipped during compilation (it’s a namespace marker, not compilable code).
  • In library mode, __main__.py is excluded from sources because the wheel builder generates it.
  • You need CPython 3.11–3.15 (including free-threaded 3.14t and 3.15t), a platform C toolchain (MSVC, GCC, or Clang), x86-64 or ARM64, and internet access during the build.

Verdict: Who Should Pick Which?

Pick Cython if you want maximum control over the generated C, you already have C-extension expertise on the team, and you’re comfortable owning the .pyx authoring and build pipeline indefinitely. You’re buying control and paying for it in maintenance.

Pick Nuitka if you want a Python-to-C compiler and are willing to invest in build configuration to reach the protection level you need. It’s a reasonable choice for teams that enjoy tuning compiler flags.

Pick Py2Native if you want to keep writing plain Python, run one build command, and get a protected native artifact — shared library, wheel, or executable — with license verification available as a commercial add-on rather than a homegrown crypto project.

For most teams shipping proprietary software, Py2Native offers the best balance: the protection level of a real compiler, the authoring experience of ordinary Python, and a single-command build.

How Py2Native Delivers Zero-Config Protection (and License Verification)

The build is one command. This produces a shared library plus a wheel:

uv run py2native build main.py *.py --library --wheel dist

Under the hood the pipeline globs your sources, runs platform plugin hooks, generates a Cython bootstrap, compiles everything to C and then to objects, and links a single shared library containing all modules. Optionally it assembles the wheel or — with --embed <dir> — a uv-managed deployment directory instead of an executable.

The wheel is deliberately small and boring:

  • the compiled shared library — every module compiled into one native object;
  • __init__.py — a meta-path finder that redirects import mypkg.submodule into the native library;
  • __main__.py — the entry point, so python -m mypkg still works.

Both bridge files are required: __init__.py connects Python’s import machinery to the native code, and __main__.py makes the package runnable. Downstream consumers just import mypkg — nothing about their code changes.

Adding license verification

Generate a keypair, sign a payload, and inspect the result:

uv run py2native keygen private.pem public.pem
uv run py2native sign --private private.pem payload.json license.dat
uv run py2native show --public public.pem license.dat

Then build with the license artifacts:

uv run py2native build main.py *.py --library --wheel dist \
  --license license.dat --public public.pem

At runtime, your .pxd declaration plus the _runtime_verify_es256_jwt call shown above is the entire integration. The public key is embedded, the verifier is compiled in, and there is no third-party library to audit or ship.

Other useful flags on build: --base <dir> to set the source root for glob expansion, and --no-console for windowed builds.

FAQ

Can I use Py2Native without knowing Cython?

Yes. Py2Native uses Cython internally, but you write plain Python — no .pyx files, no manual cythonize steps, and no C extensions to write. You just run uv run py2native build and get a native binary. The only place you touch a compiled declaration is the optional Pro license check.

Does Nuitka protect all my Python code?

Nuitka compiles Python to C, but protection depends on configuration and may not fully hide source for all modules. It often requires build configuration to achieve strong protection, unlike Py2Native’s zero-config approach.

How does Py2Native handle third-party libraries?

Py2Native leaves third-party Python libraries unmodified and works with them as-is, with minimal or no configuration. Only your custom code is compiled to native machine code.

Is license verification possible with Cython or Nuitka?

Cython and Nuitka do not provide built-in license verification. Py2Native Pro adds JWT license verification via a simple .pxd file and a call to _runtime_verify_es256_jwt, with the public key and verification code baked into the executable.

Conclusion

The choice comes down to where you want to spend effort. Cython and Nuitka ask you to invest in build configuration and, in Cython’s case, a different authoring dialect. Py2Native asks you to run one command and keep writing Python.

If you’re shipping proprietary Python and want a protected native binary without turning your build into a project, start with Py2Native — uv run py2native build main.py *.py --library --wheel dist is the whole setup, and the Pro plugin is there when you need to gate the binary with a signed license.

Related posts

EU label: AI-generated content