keygen_licensing_tools
Some handy tools for the Keygen licensing service. (This is a user contribution, not an official Keygen LLC product. For Keygen software, see here.)
Install with
pip install keygen_licensing_tools
and use as
import sys
from keygen_licensing_tools import validate_license_key_online, ValidationError
try:
out = validate_license_key_online(
account_id="demo", key="DEMO-DAD877-FCBF82-B83D5A-03E644-V3"
)
except ValidationError as e:
print(f"Error: Invalid license ({e.code}). Exiting.")
sys.exit(1)
The out
object contains useful information such as
out.code
out.timestamp
out.license_creation_time
out.license_expiry_time
The validation result can also be safely cached with
import sys
from datetime import datetime, timedelta
from keygen_licensing_tools import validate_license_key_cached, ValidationError
try:
out = validate_license_key_cached(
account_id="your accound id",
key="the license key",
keygen_verify_key="your Ed25519 128-bit Verify Key",
cache_path="/tmp/license-cache.json",
refresh_cache_period=timedelta(days=3),
)
except ValidationError as e:
print(f"Error: Invalid license ({e.code}). Exiting.")
sys.exit(1)
now = datetime.utcnow()
cache_age = now - out.timestamp
if cache_age > timedelta(days=3) and cache_age < timedelta(days=7):
print("Warning: Could not validate license. Make sure to get online soon.")
elif cache_age > timedelta(days=7):
print("Error: Could not validate license. Internet connection needed. Exiting.")
sys.exit(1)
For offline validation, use
from keygen_licensing_tools import validate_offline_key
# or "RSA_2048_PKCS1_SIGN_V2", "RSA_2048_PKCS1_PSS_SIGN_V2":
license_scheme = "ED25519_SIGN"
keygen_verify_key = "your public verify key"
license_key = "your offline license key"
try:
data = validate_offline_key(license_scheme, license_key, keygen_verify_key)
except ValidationError as e:
print(f"Error: Invalid license ({e.code}). Exiting.")
sys.exit(1)
print(data)
Testing
To run the keygen_licensing_tools unit tests, check out this repository and do
tox
License
This software is published under the MIT license.