Licensing System¶
This topic explains how PyLocket's licensing and activation system works, including activation flow, device management, offline support, and license lifecycle.
Architecture¶
sequenceDiagram
participant A as End-User App
participant P as PyLocket API
participant D as Developer Portal
A->>P: 1. Activation request (key + device ID)
Note over P: 2. Validate license<br/>Check device limit
P->>A: 3. Signed token
Note over A: 4. Cache token<br/>Decrypt functions<br/>App runs
A->>P: 5. Periodic refresh
P->>A: Refreshed token
License Key Format¶
- Length: 16 alphanumeric characters in 4 groups of 4
- Character set: Uppercase letters A-Z and digits 0-9 (all 36)
- Uniqueness: Globally unique across all PyLocket apps
- Platform-independent: A single key works on all platforms for the same app
Device Fingerprinting¶
When an end-user activates a license, the application generates a one-way device fingerprint based on hardware characteristics.
Key Properties¶
- Per-app isolation: The same physical device produces different fingerprints for different apps, preventing cross-app tracking
- Privacy-preserving: Only a one-way device fingerprint is transmitted to PyLocket servers — raw hardware identifiers never leave the device
- Deterministic: The same device always produces the same fingerprint for the same app, allowing seamless re-activation after restart
- Non-reversible: The stored fingerprint cannot be reversed to reveal hardware details
Activation Flow¶
Step 1: Activation Request¶
When the end-user launches the protected application and enters their license key, the bootstrap sends an activation request to the PyLocket activation service with the license key and a one-way device fingerprint.
Step 2: Server Validation¶
The activation service validates:
- License exists: The key matches a valid license record
- License is active: Status is
ACTIVE(notREVOKEDorEXPIRED) - Device limit check: The number of registered devices does not exceed the limit
- Rate limiting: Activation requests are rate-limited to prevent abuse
- Build check: The build exists and belongs to the correct app
- Key management: The encrypted key material for the build is decrypted server-side using cloud-based key management. The resulting material is re-encrypted for the specific activation before being returned.
Step 3: Token Issuance¶
On success, the activation service returns a cryptographically signed runtime token bound to the device, app, and build, along with encrypted key material and a policy. The token's expiry is the offline allowance: 14 days from the last time the device reached PyLocket (a free trial's token ends with the trial). It is the same for every app.
Step 4: Caching¶
The activation response is cached locally. Subsequent application launches check this cache first, avoiding a network round-trip if the cached token is still valid.
Step 5: Runtime Initialization¶
The bootstrap initializes the native runtime with the received key material. The native runtime:
- Validates the token and verifies the manifest signature
- Uses the key material to enable on-demand function decryption
- Begins decrypting functions as they are called
- Periodically refreshes the token in the background
Offline Support¶
Online Activation¶
The first activation always requires an internet connection. After successful activation:
- The runtime token is cached locally
- The token has a configurable expiry
Offline Use¶
If the device loses internet connectivity:
- The cached token stays valid for up to 14 days since the device last reached PyLocket
- During that time the application starts and runs normally
- Each launch or background refresh while online issues a fresh token, starting the 14 days again
- After 14 days without reaching PyLocket, the application requires re-activation
A free trial's token never outlives the trial, so a trial stops on its end date even offline.
flowchart LR
A["Online activation"] --> B["Token cached (14 days)"]
B --> C["Offline use"]
C --> D["Re-activation required"]
Background Refresh¶
When the device is online, the runtime attempts to refresh the token:
- Before token expiry (proactive refresh)
- On application startup
- Periodically during execution
A successful refresh resets both the token TTL and the offline grace timer.
Device Limits¶
How Limits Work¶
Each license has a device_limit (default: 1, configurable up to 10,000). When a new device activates:
- If
active_devices < device_limit: Activation succeeds, new device registered - If
active_devices >= device_limit: Activation fails with a403whosereasonisdevice_limit_exceeded
Counting Devices¶
A "device" is identified by its unique device identifier. The same physical device always produces the same identifier, so:
- Restarting the application on the same device does not consume an additional slot
- Reinstalling the application on the same device produces the same identifier (unless the OS is reinstalled or hardware changes)
- Running on a VM that migrates to different hardware may produce a different identifier
Resetting Devices¶
Developers can reset device activations when customers replace hardware:
This clears all device records, allowing the customer to activate fresh.
Velocity Controls¶
Activation Rate Limiting¶
Activation requests are rate-limited per license key to prevent: - Automated license key sharing/testing - Brute-force activation attempts - Denial-of-service against the activation endpoint
When the rate limit is exceeded, the API returns 429 Too Many Requests with a Retry-After header.
Download Rate Limiting¶
Download requests are also rate-limited to prevent abuse of signed download URLs.
License Lifecycle¶
flowchart TD
CREATE["CREATE"] --> ACTIVE["Status: ACTIVE"]
ACTIVE --> ACT1["Customer activates → Device registered"]
ACTIVE --> ACT2["Customer activates on new device → Second device registered"]
ACTIVE --> EXTEND["Developer extends expiry → Expiry updated"]
ACTIVE --> REVOKE["Developer revokes"]
REVOKE --> REVOKED["Status: REVOKED → Activation fails on next check"]
ACTIVE --> EXPIRY["Expiry date passes"]
EXPIRY --> EXPIRED["Status: EXPIRED → Activation fails on next check"]
ACTIVE --> RESET["Developer resets devices → All device records cleared"]
When a License Is Refused¶
A refused activation or refresh is a 403 whose reason comes from a fixed
list (revoked, expired, app_disabled, trial_already_used,
device_limit_exceeded, and for a refresh also not_found). A refusal that
arrives while the app is running, on a background refresh, does not stop it:
it takes effect the next time the app starts. The app decides what to do
from reason alone:
expiredandtrial_already_usedare recoverable. The app opens a window with a field for a new license key and, when your app has a purchase link, a link to buy one.- Every other reason ends the app with a message, and the app remembers
the refusal for that user account on that computer. At each later launch
it checks the license again, but only when it can find the key without
asking for it: the key saved in the user's home folder by an earlier
successful activation or, on macOS, by the PyLocket Installer; a
license-key.txtbeside the executable (where the PyLocket Installer puts it on Windows and Linux); or thePYLOCKET_LICENSE_KEYenvironment variable. Once the license is active again (for example after a store subscription is renewed, which keeps the same key), the app starts normally. A user account where the license was refused on its very first activation, with a typed key, has no stored key, so the refusal stays in place there after its cause is fixed.
See Also¶
- Licensing Tutorial — Step-by-step setup
- Configure Licensing — Configuration options
- Security Model — Security architecture overview