Light Docs

Integrating in Python

A guide integrating the licensing system in your Python app.

Introduction

This guide will help you integrate the OmegaLicensing system into your Python application.

It assumes the usage of Python 3.6 or higher.

It also assumes the prior setup of the OmegaLicensing web API. That implies that it's available on a public URL and you have a license key to validate.

Code

Add the following code in the initialization of your Python application.

import requests
import sys

def validate_license(api_url, license_key, product_id):
    try:
        response = requests.get(f"{api_url}/licenses/validate?key={license_key}&product={product_id}")
        json = response.json()

        if json.get('valid'):
            print("License key is valid.")
        else:
            print("Invalid license key. Exiting program.")
            sys.exit(1)
    except Exception as e:
        print(f"Error validating license: {str(e)}")
        sys.exit(1)

# Replace this API URL with your own api url.
API_URL = "http://your-api-url"
# Replace this license key with the one you want to validate.
LICENSE_KEY = "user-submitted-key"
# Replace this with the product ID of the product you want to validate the license for.
PRODUCT_ID = 1

validate_license(API_URL, LICENSE_KEY, PRODUCT_ID)

On this page