QuantumLockβ’ SDK Reference
Complete reference for the QuantumLockβ’ Python license validation SDK.
Package: quantumlock-sdk
Version: 1.0.0
Python: β₯ 3.9
Overviewβ
The QuantumLockβ’ SDK is a local license validation library. It validates .lic files on the client side without API calls, ensuring:
- π Complete offline validation (zero latency)
- β‘ Local quantum signature verification
- π 2-line code integration
- π Works without internet
Important: The SDK does not generate licenses. To generate licenses, use the API REST or the CLI. The SDK is for validating licenses in your end-customer software.
Installationβ
pip install quantumlock-sdk
Dependenciesβ
requestsβ₯ 2.31.0 (only for optional online validation)
Step-by-Step Guideβ
Complete Flow: From generation to validationβ
ββββββββββββββββββββββββ ββββββββββββββββββββββββ
β YOUR INFRASTRUCTURE β β CUSTOMER SOFTWARE β
β β β β
β 1. Generate licenses β .lic β 3. Validate licenses β
β via API/CLI β βββββββΊ β with the SDK β
β β β β
β 2. Distribute the β β 4. Gate features β
β .lic file β β by license β
ββββββββββββββββββββββββ ββββββββββββββββββββββββ
Step 1: Generate a license (API or CLI)β
# Via CLI
quantumlock generate \
--customer "customer@company.com" \
--features "premium,analytics" \
--days 365 \
--output license.json
Passo 2: Converta e distribua o .lic fileβ
The .lic file is a JSON (optionally Base64-encoded) containing:
{
"license_key": "QCOS-41FB-639F-C30B-14E3-6342-7B3E-6426-9320",
"quantum_signature": "a1b2c3d4e5f6...",
"customer_id": "customer@company.com",
"features": ["premium", "analytics"],
"valid_until": "2026-06-15T10:30:00",
"security_level": "Quantum-QCOS-16Q",
"qcos_fingerprint": {
"fidelity": 0.9847
}
}
Distribute this file along with the customer software.
Step 3: Validate in the customer softwareβ
from quantumlock_sdk import LicenseValidator
validator = LicenseValidator()
if validator.validate("/etc/myapp/license.lic"):
print("β License valid!")
else:
print("β Invalid license!")
Passo 4: Gate features by licenseβ
from quantumlock_sdk import LicenseValidator, FeatureNotLicensed
validator = LicenseValidator("/etc/myapp/license.lic")
validator.validate()
# Check specific feature
if validator.has_feature("premium"):
enable_premium_features()
# Check product
if validator.has_product("analytics"):
enable_analytics_module()
API Referenceβ
Classe LicenseValidatorβ
from quantumlock_sdk import LicenseValidator
Constructorβ
LicenseValidator(
license_path: str | None = None,
online_validation: bool = False,
api_url: str = "https://quantumlock.softquantus.com",
api_key: str | None = None
)
| Parameter | Tipo | Default | Description |
|---|---|---|---|
license_path | str | None | None | Path to .lic file (can be passed in validate()) |
online_validation | bool | False | If True, also validates against the API |
api_url | str | "https://quantumlock.softquantus.com" | API URL (for online validation) |
api_key | str | None | None | API Key (for online validation) |
validate(license_path=None) β boolβ
Validates a license file. Checks:
- File existence
- JSON structure (required fields)
- Expiration date
- Quantum signature integrity
- Online validation (optional)
validator = LicenseValidator()
# Option A: pass path in validate()
is_valid = validator.validate("/path/to/license.lic")
# Option B: pass path in constructor
validator = LicenseValidator("/path/to/license.lic")
is_valid = validator.validate()
Returns: True if valid, False if invalid.
Raises: LicenseError if the file does not exist or is corrupted.
has_feature(feature: str) β boolβ
Checks if a feature is enabled in the license.
if validator.has_feature("premium_api"):
# Premium feature available
pass
Returns: True if the feature is in the license feature list.
Returns
Falseif the license has not been validated or is invalid.
has_product(product_code: str) β boolβ
Checks if a product is licensed. Product codes are included as features in the license.
if validator.has_product("synapsex"):
# SynapseX product licensed
pass
if validator.has_product("qcos"):
# QCOS product licensed
pass
| Product Code | Product |
|---|---|
qcos | QCOS |
synapsex | SynapseX |
quantumlock | QuantumLock |
qsa | QSA |
require_feature(feature: str) β Decoratorβ
Decorator that requires a specific feature. Raises FeatureNotLicensed if the feature is not in the license.
validator = LicenseValidator("/path/to/license.lic")
validator.validate()
@validator.require_feature("premium_api")
def premium_endpoint():
return {"data": "premium content"}
# If "premium_api" is not in the license:
# FeatureNotLicensed: Feature 'premium_api' not licensed.
require_product(product_code: str) β Decoratorβ
Decorator that requires a specific product. Raises FeatureNotLicensed if the product is not licensed.
validator = LicenseValidator("/path/to/license.lic")
validator.validate()
@validator.require_product("qcos")
def qcos_only_function():
return {"data": "qcos exclusive"}
# If "qcos" is not in the license:
# FeatureNotLicensed: Product 'qcos' not licensed.
get_license_info() β dictβ
Returns detailed license information.
info = validator.get_license_info()
print(info)
Retorna:
{
"customer_id": "customer@company.com",
"license_key": "QCOS-41FB-639F-...",
"features": ["premium", "api_access"],
"valid_until": "2026-06-15T10:30:00",
"quantum_verified": True,
"security_level": "Quantum-QCOS-16Q",
"qcos_fidelity": 0.9847
}
is_valid() β boolβ
Checks if the license was validated successfully (after calling validate()).
if validator.is_valid():
print("License active")
get_features() β list[str]β
Returns the list of enabled features.
features = validator.get_features()
# ["premium", "api_access", "analytics"]
Returns
[]if the license is invalid.
get_expiration() β datetime | Noneβ
Returns the license expiration date.
from datetime import datetime
expiration = validator.get_expiration()
if expiration:
print(f"Expires on: {expiration.isoformat()}")
days_until_expiration() β int | Noneβ
Returns the number of days until expiration.
days = validator.days_until_expiration()
if days is not None:
if days < 30:
print(f"β οΈ License expires in {days} days!")
Exceptionsβ
LicenseErrorβ
Base exception for license errors.
from quantumlock_sdk import LicenseError
try:
validator.validate("/path/to/license.lic")
except LicenseError as e:
print(f"Erro: {e}")
Common messages:
| Message | Cause |
|---|---|
"License file not found: /path/..." | File does not exist |
"License file corrupted: ..." | Invalid JSON |
"License missing required field: ..." | Required field missing |
"License missing customer identification field" | No customer_id or end_customer_id |
"License validation failed: ..." | Generic error |
FeatureNotLicensedβ
Exception raised by the require_feature() and require_product() decorators.
from quantumlock_sdk import FeatureNotLicensed
try:
result = premium_endpoint()
except FeatureNotLicensed as e:
print(f"Access denied: {e}")
# "Feature 'premium_api' not licensed. Upgrade at https://portal.softquantus.com"
Convenience Functionsβ
validate_license(license_path: str) β boolβ
Quick validation in one line.
from quantumlock_sdk.validator import validate_license
if validate_license("/etc/myapp/license.lic"):
print("Valid!")
get_license_info(license_path: str) β dictβ
Get license information in one line.
from quantumlock_sdk.validator import get_license_info
info = get_license_info("/etc/myapp/license.lic")
print(f"Customer: {info['customer_id']}")
print(f"Features: {info['features']}")
Integration Examplesβ
Web Application (FastAPI/Flask)β
from fastapi import FastAPI, HTTPException
from quantumlock_sdk import LicenseValidator, FeatureNotLicensed
app = FastAPI()
# Initialize and validate license at startup
validator = LicenseValidator("/etc/myapp/license.lic")
if not validator.validate():
raise RuntimeError("β Invalid license! Application cannot start.")
print(f"β License valid until {validator.get_expiration()}")
print(f"β Features: {validator.get_features()}")
@app.get("/api/data")
def get_data():
"""Endpoint available for all plans."""
return {"data": "basic content"}
@app.get("/api/analytics")
def get_analytics():
"""Endpoint that requires 'analytics' feature."""
if not validator.has_feature("analytics"):
raise HTTPException(403, "Feature 'analytics' not licensed")
return {"analytics": "premium data"}
# Using decorator
@app.get("/api/premium")
@validator.require_feature("premium_api")
def premium_endpoint():
return {"premium": "exclusive content"}
CLI Applicationβ
import sys
from quantumlock_sdk import LicenseValidator, LicenseError
def main():
validator = LicenseValidator()
# Try multiple locations for the license file
license_paths = [
"./license.lic",
"/etc/myapp/license.lic",
"~/.myapp/license.lic"
]
valid = False
for path in license_paths:
try:
if validator.validate(path):
valid = True
break
except LicenseError:
continue
if not valid:
print("β No valid license found!")
print(" Place your license.lic file in one of:")
for p in license_paths:
print(f" {p}")
sys.exit(1)
info = validator.get_license_info()
print(f"β Licensed to: {info['customer_id']}")
print(f" Features: {', '.join(info['features'])}")
print(f" Expires: {info['valid_until']}")
days = validator.days_until_expiration()
if days is not None and days < 30:
print(f" β οΈ License expires in {days} days!")
# Your application here...
if __name__ == "__main__":
main()
Online + Offline Validation (Hybrid)β
from quantumlock_sdk import LicenseValidator
# Offline validation + online verification when available
validator = LicenseValidator(
license_path="/etc/myapp/license.lic",
online_validation=True,
api_url="https://quantumlock.softquantus.com",
api_key="qlk_your_api_key"
)
# If the API is unavailable, online validation is skipped
# and local validation is considered sufficient
is_valid = validator.validate()
Multi-Product Protectionβ
from quantumlock_sdk import LicenseValidator
validator = LicenseValidator("/etc/licenses/enterprise.lic")
validator.validate()
# Check which products are licensed
products = ["qcos", "synapsex", "quantumlock", "qsa"]
for product in products:
status = "β" if validator.has_product(product) else "β"
print(f" {status} {product}")
# Example output:
# β qcos
# β synapsex
# β quantumlock
# β qsa
.lic File Formatβ
The .lic file can be:
- Plain JSON (readable):
{
"license_key": "QCOS-41FB-639F-C30B-14E3-6342-7B3E-6426-9320",
"quantum_signature": "a1b2c3d4e5f6abcdef...(128 hex chars)",
"customer_id": "customer@company.com",
"features": ["premium", "api_access"],
"valid_until": "2026-06-15T10:30:00Z",
"security_level": "Quantum-QCOS-16Q",
"qcos_fingerprint": {
"fidelity": 0.9847
},
"final_signature": "sha3_512_hash..."
}
- Base64-encoded (for distribution):
JSON content encoded in Base64. The SDK automatically detects the format.
Required fields:
| Campo | Description |
|---|---|
license_key | License key |
quantum_signature | Quantum signature (128 hex chars) |
valid_until | Expiration date (ISO 8601) |
customer_id ou end_customer_id | Customer identifier |
Optional fields:
| Campo | Description |
|---|---|
features | List of enabled features |
security_level | Security level |
qcos_fingerprint | Quantum fingerprint with fidelity |
final_signature | SHA3-512 for integrity verification |
Signature Verificationβ
The SDK validates signatures in two ways:
-
With
final_signature: Recalculates the SHA3-512 of the entire JSON (without thefinal_signaturefield) and compares. -
Without
final_signature: Verifies thatquantum_signatureis a valid 128-character hex string (SHA3-512).
Troubleshootingβ
LicenseError: License file not foundβ
Check the file path. Use absolute paths.
LicenseError: License file corruptedβ
The file is not valid JSON or Base64-encoded JSON.
LicenseError: License missing required fieldβ
The .lic file is incomplete. Generate a new license via API/CLI.
Online validation failsβ
If online_validation=True and the API is unavailable, the SDK accepts local validation. This is intentional β it ensures offline operation.
Expired licenseβ
validate() returns False (does not raise an exception). Use days_until_expiration() for proactive alerts.