Python Projects
SunLicense Integration Guide for Python Projects
Prerequisites
Integration Steps
1. Create License Validator Class
import requests
from typing import Optional
import platform
class SunLicenseValidator:
def __init__(self, license_key: str, product_id: int, version: str = "1.0.0"):
self.license_key = license_key
self.product_id = product_id
self.version = version
self.api_url = "YOUR_API_URL/api/v1/validate"
def validate(self) -> bool:
data = {
"licenseKey": self.license_key,
"productId": self.product_id,
"productVersion": self.version,
"hwid": self.get_hwid(), # Optional
"operatingSystem": platform.system(),
"operatingSystemVersion": platform.version()
}
try:
response = requests.post(
self.api_url,
json=data,
headers={"Content-Type": "application/json"}
)
response.raise_for_status()
return response.status_code == 200
except requests.exceptions.RequestException as e:
raise ValueError(f"License validation failed: {str(e)}")
@staticmethod
def get_hwid() -> str:
# Implement your HWID generation logic here
return "YOUR-HWID"2. Basic Implementation
3. Advanced Implementation (Using Decorators)
Best Practices
Common Issues
Last updated