Skip to Content
SDKsPython

Python SDK

A typed client, with Pydantic models. It requires Python 3.10 or later.

pip install licenseman-sdk

PyPI  · GitHub  · API Reference 

How it works

The SDK has one class per section of the API Reference , like LicensesApi or CustomersApi, and one method per endpoint, named after it: Create a license is create_license. Each method takes the endpoint’s parameters and body as keyword arguments, in snake case, and returns the response as a Pydantic model.

The API Reference lists every endpoint with its parameters and response: the SDK’s methods take and return the same ones.

Authentication

Pass a Configuration to the ApiClient the classes use:

import os import licensemanager # With an API key, from your backend: configuration = licensemanager.Configuration( api_key={"apiKey": os.environ["LICENSEMANAGER_API_KEY"]}, ) # With a token scoped to a customer, license or machine: configuration = licensemanager.Configuration(access_token=token) with licensemanager.ApiClient(configuration) as api_client: licenses = licensemanager.LicensesApi(api_client)

Never ship an API key in your application: anyone could extract it. Keep it on your servers.

Examples

Create a license after a sale, and email its key to the customer:

license = licenses.create_license( product_id="x7Kp2QaZ", create_license=licensemanager.CreateLicense(email="jane@example.com", send_key=True), )

Validate a key from your application, which needs no credentials:

with licensemanager.ApiClient() as api_client: license_token = licensemanager.LicensesApi(api_client).validate_key( product_id="x7Kp2QaZ", validate_key=licensemanager.ValidateKey( key="7KQ2M-X9ZPA-H4TRC-WN6EY-B3JDF", fingerprint="4c:32:75:8f:9a:1e", version="1.4.2", ), ) # license_token.license is the signed license token.

List the licenses of a product, one page at a time:

page = licenses.list_licenses(product_id="x7Kp2QaZ", page=2, page_size=50, sort="-createdAt") # page.data holds the licenses, page.pagination the totals.

Errors

A failed request raises a licensemanager.ApiException, holding the status and the body with the error’s stable code:

try: licenses.get_license(id="l3Nv8KwB") except licensemanager.ApiException as error: # The body is { "error": { "code", "message" } }. print(error.status, error.body)