Skip to content
LICENTIVO / INTEGRATION

Python Software Licensing: License Key Validation

Add license key validation to a Python app. Create a virtual environment, activate a license, protect features, and test saved credentials and denied access.

Python 3.10+ · command line and desktopUpdated

1. Prepare Python and a licensed feature

Add customer license keys to a commercial Python command-line or desktop application and check permission before a protected feature runs. These checks control access to your application; they do not change the Python interpreter's open-source license. Your app supplies the activation input and business callback.

Device quota counts current activations and is returned on release. Ordinary licenses remain counted while offline; floating licenses also return quota when their leases expire.

  1. Copy the Product ID from Console > Products. Open that product’s Signing public keys and paste every key ID/public key pair into the initialization code, replacing YOUR_PRODUCT_ID, YOUR_KEY_ID and YOUR_PUBLIC_KEY. Quick integration can generate these public code constants. No product configuration file is required; the SDK defaults to https://www.licentivo.com.
  2. Install Python 3.10 or later and create a project directory.
  3. In Licentivo Quick integration, create or select a product with an unmetered export feature allowed by its policy and license.

2. Install in a virtual environment

Run the command below in your application project, or add the build dependency, to install SDK 0.11.6. The package manager retrieves the SDK; no source ZIP, manual extraction or local source path is required.

Windows · PowerShell
python -m venv .venv
./.venv/Scripts/python.exe -m pip install "licentivo-sdk==0.11.6"
Linux / macOS · Bash
python3 -m venv .venv
./.venv/bin/python -m pip install "licentivo-sdk==0.11.6"

3. Validate the license before exporting

Move SDK startup into your application’s startup or activation handler. Read the customer key from your activation form, pass your own product ID and trusted keys, and keep the client alive until shutdown. Put run_feature at the actual business entry point; replace the report writer with your own operation.

Python · complete app.py
"""A protected operation to move into your own application's business handler."""
import os
import sys
from pathlib import Path
from licentivo import Client


# BEGIN LICENTIVO PRODUCT
# Copy Product ID and all key ID/public key pairs from Console > Products > Signing public keys.
PRODUCT_ID = 'YOUR_PRODUCT_ID'
TRUSTED_KEYS = {'YOUR_KEY_ID': 'YOUR_PUBLIC_KEY'}
# END LICENTIVO PRODUCT

def export_report(path):
    # Replace this write with your existing, non-metered export operation.
    Path(path).write_text('A report generated by the licensed application.\n', encoding='utf-8')


def main():
    # In a GUI, read the activation input; later starts pass an empty key.
    with Client.open_product(
        PRODUCT_ID, TRUSTED_KEYS,
        os.getenv('LICENTIVO_LICENSE_KEY', ''),
        on_error=lambda error: print(f'Background verification: {error}', file=sys.stderr),
    ) as client:
        feature = os.getenv('LICENTIVO_FEATURE', 'export')
        path = os.getenv('LICENTIVO_OUTPUT', 'licensed-report.txt')
        action = lambda: export_report(path)
        if os.getenv('LICENTIVO_METERED') == '1':
            client.run_metered_feature(feature, 1, os.getenv('LICENTIVO_OPERATION_ID', ''), action)
        else:
            client.run_feature(feature, action)
        print(f'License OK: {feature} is available\nExport completed: {path}')
    # Keep this context open until your real app exits. No Deactivate on normal exit.


if __name__ == '__main__':
    try:
        main()
    except Exception as error:
        print(str(error), file=sys.stderr)
        sys.exit(2)
Windows · PowerShell
$env:LICENTIVO_LICENSE_KEY = 'YOUR_TEST_LICENSE_KEY'
./.venv/Scripts/python.exe app.py
# On later starts, restore the saved device credential:
Remove-Item Env:LICENTIVO_LICENSE_KEY
./.venv/Scripts/python.exe app.py
Linux / macOS · Bash
export LICENTIVO_LICENSE_KEY='YOUR_TEST_LICENSE_KEY'
./.venv/bin/python app.py
# On later starts, restore the saved device credential:
unset LICENTIVO_LICENSE_KEY
./.venv/bin/python app.py

4. Keep the client alive in a desktop application

For a command-line export, the with block can cover the entire operation. For a desktop application, open the client during activation and keep it until the window closes; do not create and close a client for every button click.

Run online activation and other network work outside the GUI thread, then send results back to the UI thread. The Tkinter desktop example is provided separately through the documentation link below; installing the pip package does not install its source.

Every export button, shortcut or command must invoke client.run_feature("export", lambda: export_report(path)). On shutdown call close; it retains a device-bound registration and attempts to return a floating seat.

Later starts pass an empty license key with the same product, user and cache path to restore the saved device credential. Offline startup still depends on a valid signed grant and the license policy; floating and online-only startup need server confirmation.

5. Verify the allowed and denied paths

  1. Activate using your test key and inspect the resulting report.
  2. Unset LICENTIVO_LICENSE_KEY and restart with the same virtual environment and operating-system user. Confirm the saved device credential restores.
  3. Set LICENTIVO_FEATURE to a feature absent from the license and LICENTIVO_OUTPUT to a new filename. Expect a nonzero exit code and no new export.
  4. If you enable metering, first configure the usage rule, set LICENTIVO_METERED=1 and provide LICENTIVO_OPERATION_ID for the durable business task. Verify successful work decrements its counter once.

Troubleshoot installation and authorization

Check the product ID, every key ID/public key pair and the customer’s license input. Public verification keys belong to a product; customer licenses and saved device credentials are separate. Do not distribute development test keys or vendor management API keys.

ModuleNotFoundError usually means pip and the app are using different Python interpreters. Use the same virtual environment executable for both commands.

An expired license or denied feature must stop the operation. Display the SDK error and request ID when available; do not run the export callback after a failed check.

Metered operations require network access. Keep a stable task ID and durable result so pending confirmation can recover without repeating work. Do not distribute cached grants, device credentials, test keys or vendor management keys.