Guide
How to Add License Keys to a Python App (Offline-Ready)
If you distribute a commercial Python desktop application (PyQt, PySide, Tkinter) or a paid local CLI tool, hardcoding a plain HTTP check against /verify?key=... can be bypassed in under a minute by editing /etc/hosts or running a local proxy.
Using asymmetric Ed25519 signatures, your Python client embeds only the public key, validates activation responses mathematically, and supports verified offline launches when you enable a lease window. For the full API reference see the Keyfern documentation.
Step 1: Install the Keyfern Python SDK
The Keyfern Python package is a lightweight single-dependency wrapper (relying only on cryptography, which pip installs for you):
pip install keyfern
No access to PyPI? pip install https://keyfern.com/dl/keyfern-1.0.0-py3-none-any.whl
Step 2: Configure offline leases (optional)
In Keyfern, offline validation is disabled by default (lease_days = 0), meaning the app checks online on startup. To allow paying customers to launch your Python app offline (for example on flights or isolated workstations), open your Product settings in the Keyfern dashboard and set a lease duration between 1 and 3,650 days (supported on every plan, including Free).
Step 3: Activate and verify licenses
Follow our full working repository on GitHub: velopre/python-license-key-example.
from keyfern import Keyfern, KeyfernError
kf = Keyfern(
product="prod_xxx",
public_key="<public key from the dashboard>", # safe to embed in your app
cache_path="license.cache",
)
try:
lic = kf.activate_or_cached(user_key) # online check, verified cache when offline
except KeyfernError as e: # blocked, expired, invalid_key, machine_limit, lease_expired...
print("License problem:", e.code)
else:
if lic.has(1): # feature flag F1
unlock_pro()
Using the SDK’s activate_or_cached flow:
- On every start the SDK calls
POST /v1/activatewith the user’s license key, a machine fingerprint hash, and a random anti-replaynonce. - The server returns a signed payload (
{payload, sig}). - The client checks the Ed25519 signature using your embedded Public Key, checks the nonce, and saves the signed answer locally.
- When the server cannot be reached, the app unlocks from that cached answer, but only if its signature is valid, it belongs to this machine, the lease (
lease_until) is still valid and no system clock rollback of more than 1 hour is detected.
Why Keyfern for Python builders
- Free up to 50 keys: test and ship your first Python tool at $0/month without a credit card.
- No monthly API call limits: paid tiers start at $10/month (1,000 keys) with unlimited validations.
- Stripe delivery (Starter $10/month and up): connect your own Stripe account to email keys automatically on purchase, with 0% Keyfern commission.
Getting started
Get started in 5 minutes in the Keyfern Quickstart or view our Cryptolens & Devolens comparison. To create your keys and your first product for free, create an account.