LicenPro
DocumentationPython SDKPython guide

Python SDK

The licenpro package brings LicenPro licensing to Python. It is not a rewrite: the licensing logic is the LicenPro .NET SDK itself, compiled into a native library, with a small Python API on top. Licenses, activations and sessions therefore behave exactly as in .NET. No .NET runtime and no other Python packages are needed.

Preview: not on PyPI yet

The package has not been published to PyPI yet, so pip install licenpro does not work today. Until it is published, ask support for the preview build. It runs on Windows 64-bit (x64) only for now: Linux and macOS builds are not available yet, and 32-bit Python cannot load it.

1. Requirements and install

  • Windows x64 with 64-bit Python 3.8 or later.
  • The same three things as every LicenPro client: the customer's license.bin, their license key, and your product public key (Base64, without PEM headers; see RSA keys).

Once the package is on PyPI:

pip install licenpro

2. Validate a license

Use the client in a with block. Leaving the block ends the license session, like Using in VB.NET or using in C#.

from licenpro import LicenseClient

PUBLIC_KEY = "MIIBCgKCAQEA..."       # your product public key (Base64, without PEM headers)
LICENSE_KEY = "XXXX-XXXX-XXXX-XXXX"

with LicenseClient("license.bin", public_key=PUBLIC_KEY, license_key=LICENSE_KEY) as client:
    result = client.validate()
    if not result.is_valid:
        print(result.status, result.error_title, result.error_message)
    else:
        print("Licensed:", result.license.type, result.license.expiration_date)
        if client.features.is_enabled("Premium"):
            ...  # unlock the premium part of your app

validate() runs the full check: the signed file, the server, the activation and the session when the license needs them. A refused license is a result with is_valid set to False, not an exception. result.status is one of Valid, MissingInput, WrongFileType, InvalidFormat, SignatureMismatch, ValidationFailed, Expired, Revoked, DeviceBlocked, WrongLicenseType or CredentialsMismatch, and result.license is None when validation fails.

For a license that is allowed offline, validate_offline() checks the signature and the local rules without calling the server:

result = client.validate_offline()

3. Options

client = LicenseClient(
    "license.bin",
    public_key=PUBLIC_KEY,
    license_key=LICENSE_KEY,
    server_endpoint="https://licenpro.runasp.net/api",   # the default; change it if you host the API
    product_id="00000000-0000-0000-0000-000000000000",   # optional
    expected_license_type="Subscription",               # optional: refuse other license types
    enable_logging=False,                               # True: log files, and errors sent to the server
)

expected_license_type takes Perpetual, Trial, Subscription, NodeLocked, Floating, Concurrent, MeteredToken (Credit-Based) or MeteredCount (Usage-Based). With enable_logging=True the SDK writes log files and sends errors to the server, as the .NET SDK does.

4. Long-running apps

A desktop or server app keeps one client for its whole life and closes it when it exits. Use one client at a time per process, as in .NET. validate() waits until the SDK is done, network included: in a GUI app, call it from a worker thread.

client = LicenseClient("license.bin", public_key=PUBLIC_KEY, license_key=LICENSE_KEY)
try:
    result = client.validate()
    ...  # run your application
finally:
    client.close()  # ends the license session; safe to call more than once

PyQt5 example

Run validate() on a QThread and send the result back to the UI with a signal; only touch Qt widgets on the GUI thread. Tested with PyQt5 5.15 on Windows x64.

import sys

from PyQt5.QtCore import QObject, QThread, pyqtSignal
from PyQt5.QtWidgets import QApplication, QLabel

from licenpro import LicenseClient

PUBLIC_KEY = "MIIBCgKCAQEA..."       # your product public key (Base64, without PEM headers)
LICENSE_KEY = "XXXX-XXXX-XXXX-XXXX"


class LicenseWorker(QObject):
    done = pyqtSignal(object)

    def __init__(self, client):
        super().__init__()
        self.client = client

    def run(self):
        self.done.emit(self.client.validate())  # runs on the worker thread


app = QApplication(sys.argv)
label = QLabel("Checking license...")
label.show()

client = LicenseClient("license.bin", public_key=PUBLIC_KEY, license_key=LICENSE_KEY)
thread = QThread()
worker = LicenseWorker(client)
worker.moveToThread(thread)
thread.started.connect(worker.run)


def on_done(result):  # runs on the GUI thread
    if result.is_valid:
        label.setText(f"Licensed: {result.license.type}")
    else:
        label.setText(f"{result.error_title}: {result.error_message}")


worker.done.connect(on_done)
worker.done.connect(thread.quit)
app.aboutToQuit.connect(thread.wait)
app.aboutToQuit.connect(client.close)  # ends the license session
thread.start()
sys.exit(app.exec_())

5. Features and license details

features = client.features        # empty until a validation succeeds
features.is_enabled("Premium")    # False when the feature is missing
features.get("MaxUsers", 1)       # numbers, strings, ISO 8601 dates, Base64 for bytes
"Edition" in features
features.as_dict()

result.license also has type, license_key, issuer, issued_on, expiration_date (a datetime, or None when the license does not expire), assigned_release_version, requires_online_validation and features.

6. Errors

LicenProError is raised only for misuse or unexpected failures: a closed client (Closed), invalid options (InvalidArgument), a missing native library (NativeLibraryMissing) or an unexpected error inside the SDK (Exception). It has code and message.

from licenpro import LicenseClient, LicenProError

try:
    with LicenseClient("license.bin", public_key=PUBLIC_KEY, license_key=LICENSE_KEY) as client:
        result = client.validate()
except LicenProError as error:
    print(error.code, error.message)   # for example NativeLibraryMissing or InvalidArgument

7. Device id and SDK version

import licenpro

print(licenpro.sdk_version())   # version of the LicenPro SDK inside the package
print(licenpro.hardware_id())   # the device id LicenPro reports for this machine

8. Python and .NET side by side

Python.NET
LicenseClient(license_file, public_key, license_key, ...)new LicenseClient(new LicenseClientOptions { ... })
client.validate(), client.validate_offline()Validate(), ValidateOffline()
result.is_valid, status, error_title, error_message, licenseIsValid, Status, ErrorTitle, ErrorMessage, License
client.features.is_enabled("X"), client.features["X"]FeatureManager.IsFeatureEnabled("X"), FeatureManager.GetFeatureInt("X") …
client.disconnect(), client.close()DisconnectAsync(), DisposeAsync()
licenpro.hardware_id()new PersistedHardwareIdentifier().GetHardwareIdentifier()

9. Not available from Python yet

Python exposes only what this page shows. These need the .NET package for now: metering (ConsumeMeterAsync, GetBalanceAsync), trials and trial extensions, license transfers, node-locked device management, events (session lost, license expiring), and custom loggers and hardware identifiers. One-click updates (SdkUpdateManager) are for .NET apps only, by design.

10. Related reading