Py2Native Python to native compilerPython-zu-Native-Compiler

← All posts

2026-10-31

Python Licensing for On-Premise Deployments

Python Licensing for On-Premise Deployments
python compiler cython code protection open source

Python Licensing for On-Premise Deployments

Priya runs a two-person software agency. She spent five months building a billing-reconciliation application for a mid-sized logistics company — a real product, with a scheduler, a rules engine, and a reporting layer she is quietly proud of. The deal closed last week. The catch: the customer runs everything in their own data center, behind their own firewall, on servers Priya will never log into.

So the deliverable is a tarball. install.sh, a README, and a binary the customer’s ops team starts with systemd. The customer expects something they can deploy and forget. Priya expects her source code not to walk out of the building the moment she ships it — and she expects the per-seat, per-year commercial terms in the contract to be enforceable by something other than goodwill.

That gap — between “here’s a deployable package” and “here’s my intellectual property, please be nice to it” — is what python licensing for on-premise deployments actually means in practice. This article is the playbook Priya used: how to ship Python into customer-controlled environments, keep the source compiled, and enforce a signed license key that verifies offline.

The On-Premise Reality: When Your Python Code Leaves the Building

On-premise is a different business model than SaaS, not just a different deployment target.

  • You lose the runtime. No shared tenancy, no server you control, no ability to hotfix at 2 a.m. without a customer change ticket.
  • You lose the network. Corporate security teams routinely block outbound traffic from production hosts. Anything that “phones home” becomes a procurement blocker.
  • You lose the code. The customer’s admins have root. They can read, copy, and modify whatever you hand them.

For a SaaS product, licensing is mostly an authentication problem: the customer logs in, your server decides what they can do. For on-premise, licensing is a packaging problem. The entitlement has to travel with the artifact and be checkable by the artifact itself, with no help from you.

That’s why the handover moment feels so uncomfortable. The customer wants a binary. Your codebase wants to stay a codebase. Bridging that gap is the whole job.

Why Python Licensing Matters for On-Premise Deployments

Four pressures push on every on-premise Python deal:

1. Air-gapped and restricted networks are normal, not exotic. A plant floor, a hospital basement, a government enclave. If your license check requires an HTTPS call to licenses.yourcompany.com, it fails on install day — and you find out from an angry ops engineer, not from monitoring.

2. Python leaks by default. A .py file is a plain-text business document. Even a shipped .pyc is bytecode that can be disassembled back into something recognizable. If your edge scoring logic or your pricing algorithm is the product, shipping it as source is shipping the product twice.

3. Without a technical control, compliance is a hope. Contracts are for lawyers; procurement teams want a mechanism. “The license expires on this date and the software stops serving reports after that” is a technical control. “Please renew by Q3” is an email.

4. Signed JWT licenses solve the offline problem cleanly. A JSON Web Token signed with an elliptic-curve private key can be verified by the customer’s machine using only an embedded public key — no network, no shared secret in the binary, no callback. You can express expiry, customer identity, and feature entitlements as claims in the token itself.

If you want the broader code-protection picture first, read How to Protect Python Source Code Before You Ship It. If you’ve already got a license scheme and just need the runtime mechanics, Verify a License Key Inside a Compiled Python Binary goes deeper on that.

A Practical Playbook for Shipping Licensed Python On-Premise

Five steps, roughly in order. Total time on a small project: an afternoon.

Step 1: Design your license model and its claims

Decide what the license says before you decide how it’s checked. The three models that cover most on-premise deals:

Model Token signal Typical use
Perpetual no exp, or a far-future one one-time purchase, paid support optional
Subscription exp in the near future annual/metered contracts
Feature-based custom claims list tiered editions on one binary

A workable payload looks like this:

{
  "iss": "RSJ Software GmbH",
  "aud": "TimestampGIT",
  "sub": "acme-logistics",
  "exp": 1798761600,
  "features": ["reconcile", "exports"]
}

Keep the payload boring. Put the customer identifier in sub, expiry in exp, and entitlements in a custom claim your application reads. Every claim you add is something your code must handle when it’s missing — so add them deliberately.

Step 2: Generate a keypair, then sign licenses

Py2Native’s Pro plugin adds the license tooling to the same CLI you already use to build:

uv run py2native keygen private.pem public.pem

private.pem never leaves your machine or your secrets store. public.pem is what ships — and even then, it gets baked into the compiled binary, not dropped next to it.

When a deal closes, mint the license:

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

And confirm what you actually signed before emailing it to a customer:

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

show prints the claims and, with --public, verifies the signature. Run it. Every time. Sending a customer a token signed with last quarter’s rotated key is a bad week.

Step 3: Wire verification into your code

This is the only part that touches the compiled layer, and Py2Native Pro ships the declaration file so you don’t hand-write anything. The .pxd file declares the runtime entry point:

cdef _runtime_verify_es256_jwt(token, expected_iss=*, expected_aud=*)

Your license module pulls that declaration in and calls it with the token you were given:

from _p2n_bootstrap cimport _runtime_verify_es256_jwt

licenseString = read_license_file("license.dat")
license = _runtime_verify_es256_jwt(licenseString, expected_iss="RSJ Software GmbH", expected_aud="TimestampGIT")

That’s the entire integration. Pinning expected_iss and expected_aud is not optional bookkeeping — it’s what stops someone from taking a token minted for a different product and feeding it to your binary. The call returns the verified license, which you then inspect like any other Python object: check the expiry, read the feature claims, gate the reporting module.

Note what is not happening here. You are not writing a C extension. You are not running cythonize by hand. You are not linking against a third-party JWT library. The verification routine and the public key get compiled into the executable by the plugin.

Step 4: Compile with the license embedded

Now build. One command, with the license and public key on the command line:

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

The build globs your sources, generates the Cython bootstrap, compiles everything to C, links the objects against the CPython shared library, and produces a native executable. Your plain Python went in; native machine code comes out.

If your customer needs a different shape of artifact, the same command carries it:

# PEP 427 wheel containing the compiled .pyd/.so, for pip-based installs
uv run py2native build --wheel dist --license license.dat main.py app/*.py

# uv-managed deployment directory, ready to hand over as-is
uv run py2native build --embed deploy --license license.dat main.py app/*.py

There is nothing else to configure. Your third-party dependencies stay as they are — you don’t rewrite them, port them, or add build recipes for them.

Step 5: Ship the binary and the license file

The delivery is two artifacts and a README:

acme-reconcile            # compiled binary (public key + verifier inside)
license.dat               # the signed JWT, issued to this customer
README.md                 # how to run it, how to replace the license

Verification happens at process start, on the customer’s machine, with no outbound connection. An expired token means the application refuses to start — and the fix is a new license.dat, not a new build. Renewal becomes a five-minute support task instead of a release.

What to Avoid When Licensing Python for On-Premise

Avoid leaning on obfuscation alone. Renamed variables and shuffled control flow raise the effort bar, but they don’t create an entitlement. You end up with code that’s annoying to read and a license that isn’t enforced.

Avoid license checks written in plain Python. A check inside a readable .py file is a two-line patch, and if licensed: becomes if True:. The comparison has to live in compiled code that the customer can’t edit without breaking the binary.

Avoid heavy build configuration. The moment protecting your code requires a hand-maintained Cython manifest, custom setup.py gymnastics, and a per-dependency build recipe, it stops happening on every release. Zero-config matters more than clever-config. If you’re weighing that tradeoff, Cython Alternatives for Protecting Python Code covers the space.

Avoid online-only checks for isolated networks. A license server is fine for SaaS. For on-premise, assume the host has no route to the internet and verify signatures locally instead.

Avoid shipping the private key. It sounds obvious. It happens anyway, usually in a certs/ directory that got committed during a debugging session. Only the public key belongs in a build.

How Py2Native Simplifies On-Premise Licensing

Py2Native is a Python-to-native compiler. You write plain Python — no .pyx source files, no .pxd authoring, no manual cythonize step, no C extension to maintain. It handles the Cython invocation, platform-specific C compilation and linking (MSVC on Windows, GCC on Linux, Clang on macOS), and produces a native binary or wheel.

For licensing specifically, the Pro plugin adds three things on top of the MIT-licensed core:

  • Signing and inspection commands — keygen, sign, and show live in the same CLI as build.
  • A --license build flag — the build refuses to proceed without a valid Pro license, and embeds the verification routine and public key into the output.
  • String compression — a smaller artifact with less readable residue.

The elliptic-curve verification is compiled into your binary directly; there are no third-party crypto libraries to vendor or audit. Only the public key travels with the customer — the private key stays with you. Because the license is a standard signed JWT, you can mint new tokens without touching the shipped binary, and the customer can renew in an air-gapped room with a USB stick.

The practical upshot: the entitlement becomes part of the artifact. Nothing to phone home to, nothing to configure on the customer’s side.

FAQ

Can I use Py2Native for air-gapped on-premise deployments?

Yes. Py2Native’s Pro plugin verifies signed JWT licenses offline using an embedded public key, so no internet connection is required at runtime.

Do I need to modify my Python code to add license checks?

You need minimal changes: include the provided .pxd file and call _runtime_verify_es256_jwt with your license token and expected issuer/audience. The rest is handled by the compiler.

How does Py2Native compare to using Cython directly for licensing?

Py2Native hides Cython’s complexity — you write plain Python, and it handles compilation and license embedding automatically. Using Cython directly requires manual .pyx files and build steps, and you’d have to implement license verification yourself.

What if the customer needs to update the license?

You can generate a new JWT with updated claims and provide it to the customer. The compiled binary remains the same; only the license file changes.

Conclusion

On-premise deals don’t have to end with you handing over readable source and hoping. Design the license model, sign a JWT with a keypair only you hold, add one verification call, and compile. The customer gets a binary they can deploy in a locked-down network; you get a technical control that expires, scopes, and identifies — without a single outbound packet.

Start with uv run py2native keygen, and build your first licensed binary with:

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

The core compiler is MIT-licensed, so you can validate the whole pipeline before you buy anything. The Pro plugin is what turns a compiled binary into a licensed one.

Related posts

EU label: AI-generated content