The CLV1 protocol is now publicRead the spec
Browse the library

Documentation libraryGet started by language

Get started with Python

This guide takes a Python program from nothing to its first activated license, and on to the build you hand to customers: install the SDK, a few lines of code, a test run, the result on the dashboard, errors, and release.

5 min read

What you need

  • Python 3.9 or later. The SDK needs one more package, cryptography, which pip installs with it.
  • An app on the dashboard. Its Integration › Connect software page has the API address, the App ID, the public key and a Make a test key button. The API address ends in /api, with no /v1: https://<your ClavisAUH site>/api.

1. Install the SDK

Download clavisauh-0.1.0-py3-none-any.whl from Downloads and check its SHA-256 as that page shows. Install it into your project's virtual environment:

python -m venv .venv
.venv/bin/pip install clavisauh-0.1.0-py3-none-any.whl

On Windows, in PowerShell:

python -m venv .venv
.venv\Scripts\pip install clavisauh-0.1.0-py3-none-any.whl

The first install needs a network, for pip to fetch cryptography. If your file has a newer version number, change the file name in the command to match. The SDK is not on PyPI yet; once it is, this guide will show that way too.

Want a test run first? Download the starter (.zip) on the Connect software page gives a folder with the SDK, the five scenarios K1 to K5 and run scripts that set up the virtual environment themselves.

2. The minimal code

The blocks below are parts of one file; the whole file, with its imports and helpers, is in step 3.

Create the client once, when your software starts. The API address, App ID and public key are the three values on the Connect software page: the sample reads them from environment variables, your software writes them in its code. The device key lives in a file only the current user can read: sessions and offline tokens are bound to it, while the seat on the license follows the machine's hashed identifiers:

client = ClavisClient(
    os.environ["CLAVIS_BASE_URL"],
    os.environ["CLAVIS_APP_ID"],
    [os.environ["CLAVIS_APP_KEY"]],
    default_device(),
    # The same key every run: sessions and offline tokens stay with this machine.
    device_key=load_or_create_device_key(STATE / "device.key"),
    app_version="1.0.0",
)

The public key goes in a list: while you rotate signing keys, a build trusts the current key and the next one (Signing keys and rotation).

Activate the customer's key. Without a network, the offline token saved last time keeps the software running:

try:
    client.init()
    grant = client.activate(os.environ["CLAVIS_LICENSE"])
except ClavisError as err:
    # No answer (network_error, timeout...): a token saved last time keeps the software working.
    offline = client.verify_offline(SAVED.read_text()) if err.retryable and SAVED.exists() else None
    if not offline:
        print(err.user_message(LANG))
        print("FAIL", err.code)
        sys.exit(1)
    print("Offline: using the license saved on this machine")
    grant = None

The public key only checks signatures, so embedding it in your software is safe. Never embed any secret key.

3. Run it

  1. On the Connect software page, select Make a test key. A TEST key expires after 24 hours and does not count against your limits.
  2. Save the whole file below as k1_key.py (the starter has it), set the four settings and run it with the virtual environment's Python:
"""K1 · License key only: activate on this machine, keep the session alive, work offline for a while.

Run: CLAVIS_BASE_URL=... CLAVIS_APP_ID=... CLAVIS_APP_KEY=... CLAVIS_LICENSE=... python k1_key.py
"""

import os
import sys
from pathlib import Path

from clavisauh import ClavisClient, ClavisError, default_device, load_or_create_device_key

# Messages in Vietnamese need a UTF-8 console (the default on Linux and in Windows Terminal).
sys.stdout.reconfigure(encoding="utf-8")
LANG = os.environ.get("CLAVIS_LANG", "en")
STATE = Path(os.environ.get("CLAVIS_STATE_DIR", ".clavis"))
SAVED = STATE / "offline.token"

client = ClavisClient(
    os.environ["CLAVIS_BASE_URL"],
    os.environ["CLAVIS_APP_ID"],
    [os.environ["CLAVIS_APP_KEY"]],
    default_device(),
    # The same key every run: sessions and offline tokens stay with this machine.
    device_key=load_or_create_device_key(STATE / "device.key"),
    app_version="1.0.0",
)

try:
    client.init()
    grant = client.activate(os.environ["CLAVIS_LICENSE"])
except ClavisError as err:
    # No answer (network_error, timeout...): a token saved last time keeps the software working.
    offline = client.verify_offline(SAVED.read_text()) if err.retryable and SAVED.exists() else None
    if not offline:
        print(err.user_message(LANG))
        print("FAIL", err.code)
        sys.exit(1)
    print("Offline: using the license saved on this machine")
    grant = None

if grant:
    print("License", grant["license"]["status"], "until", grant["license"]["expiresAt"] or "forever")
    # Every few minutes while the software runs; sessions end after an hour without one.
    client.heartbeat()
    if client.offline_token:
        SAVED.write_text(client.offline_token)
    client.logout()
print("OK k1", grant["license"]["status"] if grant else "offline")
export CLAVIS_BASE_URL="<API address>"
export CLAVIS_APP_ID="<App ID>"
export CLAVIS_APP_KEY="<public key>"
export CLAVIS_LICENSE="<test key>"
.venv/bin/python k1_key.py

On Windows, in PowerShell:

$env:CLAVIS_BASE_URL = "<API address>"
$env:CLAVIS_APP_ID = "<App ID>"
$env:CLAVIS_APP_KEY = "<public key>"
$env:CLAVIS_LICENSE = "<test key>"
.venv\Scripts\python k1_key.py

It prints License active until <date>, then OK k1 active on the last line. Run it again on the same machine and it still succeeds without using another seat: the server knows the machine by its hashed identifiers (Devices, HWID and transfers). The device key, which signs the requests, stays in the .clavis folder under the folder you run it from (or in CLAVIS_STATE_DIR). A container started afresh for each run looks like a new machine every time, see Questions.

4. See it on the dashboard

  • Integration › Connect software: step 4 turns to Connected, with python/0.1.0 and the machine's operating system.
  • Licensing & releases › Licenses: the key goes from Unused to Active.
  • End users › Devices & sessions: the machine that ran it, and the session it opened.

5. Handle errors

Every refusal is a ClavisError with three things you need:

  • err.code: a code from the error codes table, such as invalid_credentials or device_limit.
  • err.user_message("en"): a sentence for the person using your software, in English or "vi", ready to show.
  • err.retryable: True when no answer arrived (no network, too slow, a busy server); trying again later may work.

An answer without your app's valid signature is refused with a ClavisVerificationError (also a ClavisError), code unsigned_response, invalid_response_signature, unknown_key or stale_response. Treat it as no answer at all; usually the API address or the public key in your software is wrong.

While your software runs, send a heartbeat regularly to keep the session, every 5 to 30 minutes or so: a session ends after 60 minutes without one.

# Every few minutes while the software runs; sessions end after an hour without one.
client.heartbeat()

Save the latest offline token, so the software still opens next time without a network:

if client.offline_token:
    SAVED.write_text(client.offline_token)

Offline tokens come on every plan and last 7 days by default; Premium chooses the length, and Online-Only Mode turns them off. See Offline licenses. To see every call while tracking a problem down, create the client with debug=True: each call and its outcome go to stderr, keys show only their first and last four characters, and passwords never appear.

6. Package and release

  • Write the API address, App ID and public key in your code or in a config file shipped with the build. Customers' machines need no environment variables.
  • Put the state folder (device key, offline token) where the user can write, one per user: %APPDATA%\YourApp on Windows, ~/Library/Application Support/YourApp on macOS, ~/.config/your-app on Linux. Never in the install folder.
  • Pass app_version as the version you release: the server uses it to block builds that are too old and to announce new ones, see Signed releases and updates.
  • Your software ships with Python and cryptography. If you package it as one executable (PyInstaller, Nuitka…), run the packaged build to OK k1 active on a clean machine before you release it.
  • Vietnamese sentences need a UTF-8 console. The sample calls sys.stdout.reconfigure(encoding="utf-8"); software with a graphical interface does not need it.
  • Before you sell, turn on Publicly released in Integration › App settings. Every TEST key stops working, so a test key that got out cannot be used.

Questions

Does the software need a network every time it opens? Activation and heartbeats do. Without a network, the saved token keeps the software running for 7 days by default, or the length chosen on Premium, checked on the machine without the server.

What if a customer reinstalls the system or changes machines? After a reinstall on the same machine, the server still recognizes it from its hashed hardware identifiers. A new machine takes a new seat; when none is left the customer gets device_limit, and you Reset devices on the Licenses page. See Devices, HWID and transfers.

How do I limit features by license plan? client.has("feature_name") tells whether the license grants that feature; create features in License plans and entitlements.

Can I use the C library through ctypes instead of the SDK? Yes. The C library (clavis.dll, libclavis.so, on Downloads) needs no Python package, which suits places where cryptography cannot be installed, and has the same main calls. The Python SDK returns Python dicts and adds a function that downloads update files and checks their SHA-256.

How can we help?

Frequently asked

What is ClavisAUH?

A licensing and authentication service for desktop software: license keys, device binding, end-user sign-in and signed responses. All run from one dashboard

Why can't a cracker fake your server?

The SDK only trusts answers signed with your app's private key. That key never leaves our servers, so a fake server can't sign and gets rejected

What ends up in my binary?

Your app id and public key. Nothing secret, because each device makes its own key pair on first run

Does it work offline?

Yes. Every plan gets a signed offline token for 7 days, and your app checks it locally. Premium lets you choose how long. A revoked license can keep working offline for that time, unless Online-Only Mode is on

Which languages are supported?

JavaScript and TypeScript today. C++, C# and Python are next, on the same open protocol

Is Basic really free?

Yes. No time limit, no card. Move to Premium when you need more

Get in touch