License Your Python Desktop App with Keymint in 5 Minutes
Clifford2 min read
pythonsdklicense keysdesktop appskeymint
Python desktop apps, CLI tools, and data science pipelines all need licensing if you want to sell them. The Keymint Python SDK gives you license creation, activation, and device-locked verification with type hints and a clean API.
Installation
bash
pip install keymintQuick Start
python
from keymint import KeyMint
admin = KeyMint(api_key="YOUR_ADMIN_API_KEY")
client = KeyMint(api_key="YOUR_CLIENT_API_KEY")
product_id = "YOUR_PRODUCT_ID"Creating a License Key
python
result = admin.create_key({
"productId": product_id,
"allowedHosts": ["workstation-1", "workstation-2"],
})
license_key = result["key"]Activating on a Device
python
result = client.activate_key({
"productId": product_id,
"licenseKey": "T8XTR-AI21B-2990H-85SB5",
"hostId": "workstation-1",
})
print(result["message"]) # "License valid"
# licenseeName is masked and only present when a customer is assigned
print(result.get("licenseeName"))Call activate_key on every launch — it validates the key and confirms the machine is authorized. If the key is expired or blocked, the host isn't allowed, or activations are exhausted, it raises KeyMintApiError (see Error Handling).
Deactivating a Machine
python
client.deactivate_key({
"productId": product_id,
"licenseKey": "T8XTR-AI21B-2990H-85SB5",
"hostId": "workstation-1",
})This frees up an activation slot so the user can move their license to another machine.
Retrieving Key Info
Detailed key lookup requires a read-only or admin API key. Use this from your backend, not from distributed client code.
python
info = admin.get_key({
"productId": product_id,
"licenseKey": "T8XTR-AI21B-2990H-85SB5",
})
# info["data"]["license"]["expirationDate"]
# info["data"]["license"]["maxActivations"]Error Handling
The SDK raises KeyMintApiError for every non-2xx response, with the HTTP status and Keymint code. A 401, 402 or 403 means the license was rejected; anything else (no network, 429, 5xx) is temporary and shouldn't lock the user out:
python
from keymint import KeyMintApiError
try:
result = client.activate_key({...})
except KeyMintApiError as e:
if e.status in (401, 402, 403):
print(f"License rejected: {e.message}")
else:
print(f"Couldn't reach Keymint, try again later: {e.message}")What's Next
The Python SDK also supports block_key, unblock_key, and full customer management (create_customer, get_customer_by_id, update_customer, etc.). Those management calls require an admin API key; detailed get_key lookup requires read-only or admin.
Install it with pip install keymint and check the Python SDK docs for the complete reference.