Skip to main content

Python license validation SDK

Project description

lykn Python SDK

Python license validation SDK for applications protected by Lykn.

What this SDK provides

  • Runtime license verification with LicenseValidator.
  • RSA signature, validity period, hardware binding, and feature checks.
  • CLI tools for verification, license inspection, hardware collection, and packaging.
  • FastAPI dependencies for route-level license and feature enforcement.
  • Packaging helpers for bundling protected Python applications with PyInstaller or Nuitka.

Installation

Install the base SDK:

pip install lykn

Install optional integrations when needed:

pip install lykn[fastapi]
pip install lykn[pack]

For local development from this repository:

cd sdk/python
pip install -e ".[dev]"

Verify a license

Use LicenseValidator with a project public key and a signed license file:

from lykn import LicenseValidator

validator = LicenseValidator(
    public_key="./public.pem",
    license_path="./license.lic",
    check_interval=300,
)

license_data = validator.start()
assert validator.has_feature("reports") is True
validator.stop()

LicenseValidator accepts either license_path or license_content. Set check_interval to a positive number of seconds to re-check the license in the background after start() is called.

Common methods:

  • verify(required_features=None): validate once and return LicenseData.
  • start(): validate once and start background re-checks when enabled.
  • stop(): stop the background re-check loop.
  • has_feature(feature): check whether the current license includes a feature.
  • on_invalid(callback): register a callback for background validation failure.

License data

Successful validation returns a LicenseData object with these fields:

  • id: license ID.
  • subject: licensed user or organization information.
  • plan: license plan code.
  • plan_name: license plan display name.
  • issued_at, not_before, not_after: license time window.
  • hardware: optional hardware binding data.
  • features: enabled feature list.
  • limits: structured license limits such as max_users and max_devices.
  • metadata: legacy custom metadata, kept for older licenses.

Validation can raise these SDK errors:

  • LicenseFileError
  • LicenseSignatureError
  • LicenseExpiredError
  • LicenseNotYetValidError
  • HardwareMismatchError
  • FeatureNotLicensedError

CLI

The lykn command is installed with the SDK.

Verify a license and require one or more features:

lykn verify --public-key ./public.pem --license ./license.lic --feature reports

Inspect a signed license payload without verifying it:

lykn inspect --license ./license.lic

Collect local hardware data for hardware-bound licenses:

lykn hardware-info --format json
lykn hardware-info --format table

Bundle a protected Python application:

lykn pack --project ./my-app --engine pyinstaller --entry main.py --out ./dist
lykn pack --project ./my-app --engine nuitka --module my_app --mode onefile

FastAPI

Install the FastAPI extra first:

pip install lykn[fastapi]

Use RequireLicense to require any valid license, or RequireFeatures to require specific licensed features:

from fastapi import Depends, FastAPI
from lykn import LicenseValidator
from lykn.contrib.fastapi import RequireFeatures, RequireLicense

validator = LicenseValidator(public_key="./public.pem", license_path="./license.lic")
app = FastAPI()

@app.get("/health/license")
def license_health(license_data=Depends(RequireLicense(validator))):
    return {"license": license_data.id}

@app.get("/reports")
def reports(license_data=Depends(RequireFeatures(validator, "reports"))):
    return {"plan": license_data.plan}

Invalid licenses or missing features return HTTP 403 from the dependency.

Packaging protected apps

Install the packaging extra first:

pip install lykn[pack]

lykn pack stages the project, includes common Lykn resources such as license.lic and public.pem when present, and delegates the build to PyInstaller or Nuitka.

Use CLI options for one-off builds:

lykn pack \
  --project ./my-app \
  --engine pyinstaller \
  --entry main.py \
  --mode onedir \
  --resource license.lic \
  --resource public.pem \
  --exclude .env \
  --name my-app

Or store defaults in pyproject.toml:

[tool.lykn.pack]
engine = "pyinstaller"
entry = "main.py"
out = "dist"
mode = "onedir"
resources = ["license.lic", "public.pem"]
exclude = [".env", ".env.*", ".git", "__pycache__"]
name = "my-app"
clean = true
extra_args = ["--noconfirm"]

CLI options override values from pyproject.toml.

Compatibility

  • Python 3.10 or newer.
  • Optional FastAPI integration requires fastapi>=0.100.
  • Optional packaging support requires pyinstaller>=6.0 or nuitka>=2.0.

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

lykn-0.0.1.tar.gz (69.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lykn-0.0.1-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file lykn-0.0.1.tar.gz.

File metadata

  • Download URL: lykn-0.0.1.tar.gz
  • Upload date:
  • Size: 69.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for lykn-0.0.1.tar.gz
Algorithm Hash digest
SHA256 239dbe55d9c2823e8f272956a051f85b38dcd60b42f01d9e07dabc6a988042d0
MD5 ea86a7feef1d1698484963d639ce4d1a
BLAKE2b-256 7074270eeb1b9818cbebaa8ce13c7f8c995889b588a455054f38458ab6c8d477

See more details on using hashes here.

File details

Details for the file lykn-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: lykn-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 16.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for lykn-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 627a0d69210022d4bc3e0efaeadffb6c5afa3560ea909a7c4a65019bfd335ea0
MD5 1cf518756d92d2c2cde1af756d17c487
BLAKE2b-256 93358e61501d582283be25d0e0e3088555dd7ef85480e63fae47dc2771e54c20

See more details on using hashes here.

Supported by

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