Activate a licence in Python
In this guide
In a Python app, make the HTTPS request off the UI thread and verify its result before enabling paid features. The examples use HTTPX and cryptography.
To use the SDK, follow the client SDK integration guide.
Prepare the app
Reuse an httpx.Client(timeout=10). Create the fingerprint once and keep it in private installation storage so it survives upgrades. The protocol verifier download supplies a complete Python function for processing the certificate. The functions below call the public API directly. Download python_licence.py.
Pin your product slug (here dropsmith) and your organisation’s test public keys in the build. Obtain those keys at build time as described in the verification protocol. Keep management credentials and privileged calls on the publisher’s server.
Activate the first machine
Pass the key the buyer just typed and the local fingerprint to this function. Replace the sample machine name, platform, version and build date with your app’s values. A successful POST /v1/activate returns 200 with activation_id and certificate.
def activate(http: httpx.Client, key: str, fingerprint: str) -> httpx.Response:
return http.post(
API + "activate",
json={
"key": key,
"product": PRODUCT,
"fingerprint": fingerprint,
"machine_name": "Studio",
"platform": "linux",
"app_version": "1.0.0",
"build_date": "2026-11-17",
},
)
If every seat is taken (seats_exhausted), let the buyer release a machine. You can discard the entered key. Refresh sends activation_id, the original fingerprint and the current app_version.
Verify before granting access
Require two canonical base64url segments after keyseal:v1:. Read the kid from the UTF-8 JSON to select its pinned public key. Pass that key, the original payload segment as received and the 64 signature bytes to the function below. Cryptography’s verify raises InvalidSignature if the bytes have changed. The complete verifier also checks the envelope, claims and machine binding.
def valid_signature(public_key: bytes, segment: str, signature: bytes) -> bool:
try:
Ed25519PublicKey.from_public_bytes(public_key).verify(signature, segment.encode("ascii"))
except (InvalidSignature, ValueError):
return False
return True
The signature is one step in the complete verification procedure. Check every signed claim, the expected product and the fingerprint’s SHA-256. Match act to the ID in the response, then replace the stored ID and certificate together. Run the protocol’s 19 vectors, including modified signatures and retired keys.
Place verify_vectors.py beside python_licence.py. At build time, bundle the unchanged JSON response from GET /v1/keys/{organization}/{product}?environment=test as pinned-keys.json. At startup, call load_bundled_pins with the path to that installed resource. It decodes the base64 strings in keys into Ed25519 public keys. Pass the resulting map to verified_activation for each successful activation or refresh.
def load_bundled_pins(path: Path) -> dict[str, Ed25519PublicKey]:
encoded = json.loads(path.read_text(encoding="utf-8"))["keys"]
return decode_pins(encoded)
def verified_activation(
reply: httpx.Response, pins: dict[str, Ed25519PublicKey], fingerprint: str
) -> tuple[str, str]:
if reply.status_code != 200:
raise ValueError("Activation unavailable")
body = reply.json()
claims = verify(body["certificate"], pins, PRODUCT, fingerprint)
if claims["act"] != body["activation_id"]:
raise ValueError("Activation mismatch")
return body["activation_id"], body["certificate"]
Start offline, refresh and release
Verify the stored certificate on every launch. When the network is unavailable, an active lease allows use. At or beyond lease_until, open preserves the last verified entitlements and closed blocks use until a successful refresh. Check the build’s date against updates_until as well.
def refresh(http: httpx.Client, activation_id: str, fingerprint: str) -> httpx.Response:
return http.post(
API + "refresh",
json={"activation_id": activation_id, "fingerprint": fingerprint, "app_version": "1.0.0"},
)
def deactivate(http: httpx.Client, activation_id: str, fingerprint: str) -> httpx.Response:
return http.post(
API + "deactivate", json={"activation_id": activation_id, "fingerprint": fingerprint}
)
Call POST /v1/refresh in the background once a day when online. Verify a new certificate before replacing the previous one. Immediately persist a blocked state on revoked, suspended or expired, retain the ID and continue refreshing. For released, unknown_activation or wrong_machine, clear the activation and offer to activate again. A network failure or 429 preserves the previous state according to its lease.
The “Release this machine” action calls POST /v1/deactivate. On 204, clear the certificate and ID without reading a JSON body. An unknown activation or one belonging to a different machine can also be forgotten. On network failure, leave the release pending.