Skip to main content

Python tools for Keygen.sh licensing

Project description

keygen_licensing_tools

PyPi Version PyPI pyversions GitHub stars Downloads

gh-actions codecov LGTM Code style: black

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

from keygen_licensing_tools import validate_license_key_online

out = validate_license_key_online(
    account_id="demo", key="DEMO-DAD877-FCBF82-B83D5A-03E644-V3"
)

if not out.is_valid:
    print(f"Error: Invalid license ({out.code}). Exiting.")
    exit(1)

The out object contains useful information such as

out.is_valid
out.code
out.timestamp
out.license_creation_time
out.license_expiry_time

The validation result can also be safely cached with

from datetime import datetime, timedelta
from keygen_licensing_tools import validate_license_key_cached

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),
)

if not out.is_valid:
    print(f"Error: Invalid license ({out.code}). Exiting.")
    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.")
    exit(1)

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 Distribution

keygen_licensing_tools-0.1.0.tar.gz (5.6 kB view hashes)

Uploaded Source

Built Distribution

keygen_licensing_tools-0.1.0-py3-none-any.whl (6.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page