Skip to main content

Licensing library

Project description

licensekey2

Installation

pip install licensekey2

Usage

API license keys

Keys is generated and verifyed on the server.

from licensekey2 import RemoteLicense

license = RemoteLicense("https://example.com/api/license")

# Check if the license is valid
license.validate("1234-5678-9012-3456")

Crypto license keys

from datetime import datetime
from licensekey2 import CryptoLicense

# Generate keys. Private key MUST BE kept secret.
public_key, private_key = CryptoLicense.generate_key_pair()
print(public_key, private_key)

# Initialize license object
license = CryptoLicense(public_key, private_key)

# Prepare license subject
license_data = {
    "name": "John Doe",
    "product": "My Product",
    "type": "Ultimate License"
}

# Generate key
key = license.generate_key({}, until=datetime(2025, 1, 1))
print(key)

# Check key and return our license_data
license_subject = license.validate(key)

# Check license type
if license_subject["type"] == "Ultimate License":
    print("You have an ultimate license!")

Custom checkers

def custom_checker(license_subject):
    if license_subject["type"] == "Ultimate License":
        return
    raise ValueError("You don't have an ultimate license!")

license = CryptoLicense(public_key, private_key, custom_checker=custom_checker)

key = license.generate_key({"type": "Ultimate License"}, until=datetime(2025, 1, 1))
license.validate(key)
# Key is valid

key = license.generate_key({"type": "Another license"}, until=datetime(2025, 1, 1))
license.validate(key)
# Key is invalid. ValueError raised.

Authors and license

Licensed under the MIT license.

First version by Marat Budkevich (@marat2509)

This version by Egor Ternovoy cofob@riseup.net (@cofob)

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

licensekey2-0.1.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

licensekey2-0.1.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file licensekey2-0.1.0.tar.gz.

File metadata

  • Download URL: licensekey2-0.1.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.14 CPython/3.10.6 Linux/6.0.2

File hashes

Hashes for licensekey2-0.1.0.tar.gz
Algorithm Hash digest
SHA256 81cca6ce237457406744ef7aa45bac4b7a4aa52e33b0c9fc89c1e8735752a302
MD5 bc1cad91e0675060773438c6e266cd69
BLAKE2b-256 e31eca3e7a15a7dc8d90466a1b76e61e87f1a570ddd64c543df39be00d75bf60

See more details on using hashes here.

File details

Details for the file licensekey2-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: licensekey2-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.14 CPython/3.10.6 Linux/6.0.2

File hashes

Hashes for licensekey2-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bf7d1aef206466994e74db0ddddf4d4debfe8d134f0eb1bbcc7f916f2f715f54
MD5 de19a52d43ab7702316dc52f661b966d
BLAKE2b-256 b5bb642156aec32feab2fc6df467187bcdc589b2712a9fdb64fff4a6e1aebf1f

See more details on using hashes here.

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