Python tools for Keygen.sh licensing
Project description
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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distributions
Close
Hashes for keygen_licensing_tools-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbc50dca9129d6fa61d5ace82c17baea4cf090d111b08c5605d225e87f0d39fd |
|
MD5 | 0141d5316306c419c14a04546c0c7ecb |
|
BLAKE2b-256 | 54214d3234e84503e30be26142c48d549b07f922bc17d3488c805a3ef4e59ef3 |
Close
Hashes for keygen_licensing_tools-0.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 933ddd7e177cb078b04a7f011ba8fbf7ebba9b90d3c3e05c1e815aaf22830b96 |
|
MD5 | ec858eabd0a1a816593432d6bda7acd3 |
|
BLAKE2b-256 | 1e36bfb963771b36f3e2617cb81ac769f53d8199bc675e5f12ccab1d7213f143 |
Close
Hashes for keygen_licensing_tools-0.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83b230edb61205b3b720f3ff5eea8543fd71c786289124a5c50c20d08af02f4f |
|
MD5 | 0457f87c693c0a3a1f8e9cf9fd7be9d6 |
|
BLAKE2b-256 | d296058ea69c2135e9868b437716cbc54468006a3dbbf67fb475877f0953f888 |
Close
Hashes for keygen_licensing_tools-0.3.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4cbeda04f43e087ba51037b489cd001fab105350e0a0ebbc5edbfce23b416312 |
|
MD5 | 05f7f8b77abc70caea00a3464645a48a |
|
BLAKE2b-256 | f3ba5fb7aed1b0556dfb71f4d6a5989d14f92c4d681a586c5874e2b9f21f0d45 |