Py2Native Python to native compiler

← All posts

2026-09-03

The Best Python Native Compiler for Proprietary Software

The Best Python Native Compiler for Proprietary Software
python compiler cython code protection open source

The Best Python Native Compiler for Proprietary Software

Maya runs a small software company. Her forecasting engine is built in Python, it has paying customers, and it is growing. There is just one problem: every release ships readable .py files. A competitor who gets a copy of the application can open the code, study the algorithms, and rebuild a competing product without spending months on research.

If you are evaluating a Python native compiler for proprietary software, this is the situation that usually pushes you over the edge. Python is fast to build with, but shipping raw source or bytecode is a weak way to protect the logic that makes your product valuable. This article walks through a practical path from plain Python source to a compiled, protected binary using Py2Native.

The Founder’s Dilemma: Shipping Python Without Giving Away the Farm

Maya’s product is not unusual. Many Python developers ship proprietary software as source files, .pyc bytecode, or lightly obfuscated packages. The problem is that Python bytecode can be decompiled into surprisingly readable code. Obfuscation adds friction but rarely stops a determined person for long.

The traditional “serious” alternative is to rewrite performance-critical or sensitive parts as C extensions, or to manually maintain Cython .pyx and .pxd files. That is the hard way. It works, but it is slow, error-prone, and feels like a second full-time job.

Py2Native takes a different path. It uses Cython under the hood, but hides it completely. You write plain Python, run one command, and get native machine code. No .pyx files to maintain, no manual C extension boilerplate, and no need to become a build engineer.

For a founder like Maya, that is the difference between a security improvement that happens this week and a rewrite that never ships.

Why Native Compilation Matters for Proprietary Python Software

When you distribute .py files or .pyc bytecode, you are exposing your algorithms, business logic, and integration details. Native machine code raises the bar significantly. It is not magic, but reversing optimized native code is much harder than running a Python decompiler.

Py2Native compiles only your custom Python code. Third-party libraries remain normal Python packages and continue to work as-is. That is a deliberate design choice. You keep the full Python ecosystem for things like requests, pandas, FastAPI, or PyQt, while your proprietary logic becomes a compiled native library or executable.

The core compiler is open source under the MIT license, so you can inspect the build process and know exactly what happens to your code. For teams that need stronger licensing controls, the commercial Pro plugin adds JWT-based license verification and string compression on top of the same pipeline.

If you are new to Python code protection, the beginner’s guide to protecting Python source code is a good place to start before diving into native compilation workflows.

A Practical Playbook: From Python Script to Protected Binary

Here is a step-by-step plan for a Python team that ships proprietary software and wants to stop shipping readable source.

Step 1: Set up your project with uv

Py2Native is built around the uv package manager. Start with a clean project and add Py2Native as a development dependency.

uv init acme-engine
cd acme-engine
uv add --dev py2native

Make sure you have a platform C compiler available: MSVC on Windows, GCC on Linux, or Clang on macOS. Py2Native supports Windows 8+, manylinux2014/musl Linux, and macOS on x86-64 or ARM64 CPUs.

If you want a deeper walkthrough of uv-based compilation, see Automate Python Compilation with uv and Py2Native.

Step 2: Compile a plain Python entry point into a native executable

Assume your project has a main.py entry point and several Python modules that contain proprietary logic. Run:

uv run py2native build main.py *.py

Py2Native globs the sources, transpiles them with Cython, compiles the generated C, and links a native executable. Your business logic now ships as machine code instead of readable Python files.

If you are building a Windows GUI application and want to avoid a terminal window, add --no-console:

uv run py2native build main.py *.py --no-console

Step 3: Distribute as a library with --library

Some teams do not ship a standalone executable. They sell a Python package that customers import into their own applications. In that case, compile to a shared library:

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

The wheel contains a single compiled shared object plus two small Python files that bridge the import system. The __init__.py file uses a meta-path finder to redirect imports of your package into the native library, and __main__.py enables python -m yourpackage. Your customers import the package normally, but the implementation is compiled code.

Step 4: Create a self-contained deployment with --embed

If you want an isolated deployment directory that includes your compiled executable and a uv-managed Python environment, use --embed:

uv run py2native build main.py *.py --embed dist/acme-engine

Py2Native creates a deployment directory managed by uv. This is useful for shipping to customers who should not install Python themselves, or for internal deployment where you want a self-contained artifact.

Step 5: Add license key verification with the Pro plugin

If you sell licenses or subscription access, the Pro plugin adds signed JWT verification directly into your compiled executable. Only the public key is stored in the executable, and the elliptic-curve verification runs as compiled code. There is no third-party crypto dependency in the verifier.

First, generate an EC P-256 keypair:

uv run py2native keygen private.pem public.pem

Keep private.pem safe. It never ships with your application.

Next, sign a JWT payload to create a license file:

uv run py2native sign --private private.pem '{"customer":"Acme Corp","exp":"2027-09-03"}' license.dat

You can inspect the claims later with:

uv run py2native show --public public.pem license.dat

Finally, build your application with the license requirement enabled:

uv run py2native build main.py *.py --license license.dat --public public.pem

The Pro plugin includes the .pxd declaration for the native verifier and binds the verification logic into your compiled code. Your Python entry point calls the verifier once at startup, and --license bakes the public key and verification code into the executable. Users without a valid license cannot run the application.

What to Avoid When Protecting Python Code

Do not rely solely on obfuscation or packing. Obfuscation can slow down a beginner, but Python bytecode can still be recovered and studied. Native compilation changes the threat model.

Do not hand-write C extensions or manually maintain Cython .pyx and .pxd files. That is the hard way. It is time-consuming, easy to get wrong, and difficult to maintain as your code changes. Py2Native automates the entire pipeline.

Do not compile third-party libraries unnecessarily. Py2Native leaves third-party packages as normal Python modules. That preserves compatibility, avoids licensing complications, and keeps your build simple. Focus protection on your own code.

Do not forget build pipeline security. The private key used for Pro license signing should never be stored in source control or on a public build server. Treat it like a production secret.

Avoid duplicate module names across your source files. Py2Native does not support modules with identical names, so keep your custom module names unique.

If you want to compare native compilation with other approaches, see Best Open Source Python Compilers Compared.

FAQ

Is Py2Native really zero-config?

Yes. Py2Native automates the entire compilation pipeline: Cython transpilation, C compilation, and linking. You run uv run py2native build main.py *.py and get a native binary. No manual .pyx or .pxd files, and no hand-written C extension code.

Can I still use my favorite Python libraries?

Absolutely. Py2Native only compiles your custom Python code. Third-party libraries remain normal Python packages and are imported at runtime, so you keep the full Python ecosystem without extra configuration.

How does license key verification work with Py2Native?

The Pro plugin adds JWT-based license verification. You generate an EC P-256 keypair, sign a JWT payload with your private key to create a license file, and build your app with the --license flag. The public key and verification logic are baked into the executable, so only users with a valid license can run it.

What platforms and Python versions are supported?

Py2Native supports Windows 8+, manylinux2014/musl Linux, and macOS on x86-64 and ARM64 CPUs. It works with CPython 3.11 through 3.15, including free-threaded builds.

Conclusion

Shipping proprietary Python software does not mean accepting that your code will be read, copied, or repackaged. By compiling your custom Python into native machine code while leaving third-party libraries untouched, Py2Native gives you a practical middle ground: the speed of Python development with a much higher barrier to reverse engineering.

Start with a small module, run the build command, and inspect the artifact. Once you see the pipeline work, add --wheel for package distribution or --embed for a self-contained deployment. If you sell licenses, add the Pro plugin for JWT verification that is baked into the binary.

Try Py2Native at py2native.dev and stop shipping your source code by accident.

Related posts

EU label: AI-generated content