Python Projects
Integrate abystrixLicense into your Python application.
Using requests
python
import requests
import platform
class abystrixLicense:
def __init__(self, server_url: str, api_token: str = None):
self.base_url = server_url.rstrip('/')
self.api_token = api_token
def validate(self, license_key: str, product_id: int, hwid: str = None) -> dict:
response = requests.post(
f"{self.base_url}/api/v1/validate",
json={
"licenseKey": license_key,
"productId": product_id,
"hwid": hwid or platform.node(),
"operatingSystem": platform.system(),
"osVersion": platform.version(),
"osArchitecture": platform.machine(),
"javaVersion": platform.python_version(),
}
)
return response.json()
def get_license(self, license_key: str) -> dict | None:
headers = {"TOKEN": self.api_token} if self.api_token else {}
response = requests.get(
f"{self.base_url}/api/v2/licenses/by-license-key/{license_key}",
headers=headers
)
return response.json() if response.ok else None
def list_licenses(self) -> list:
headers = {"TOKEN": self.api_token}
response = requests.get(
f"{self.base_url}/api/v2/licenses",
headers=headers
)
return response.json() if response.ok else []
# Usage
license = abystrixLicense("https://your-server.com")
result = license.validate("XXXXX-XXXXX-XXXXX-XXXXX", 1)
if result.get("valid"):
print("License is valid!")
else:
print(f"License invalid: {result.get('message', 'Unknown error')}")Using aiohttp (Async)
python
import aiohttp
import asyncio
class AsyncabystrixLicense:
def __init__(self, server_url: str, api_token: str = None):
self.base_url = server_url.rstrip('/')
self.api_token = api_token
async def validate(self, license_key: str, product_id: int) -> dict:
async with aiohttp.ClientSession() as session:
async with session.post(
f"{self.base_url}/api/v1/validate",
json={"licenseKey": license_key, "productId": product_id}
) as resp:
return await resp.json()
async def check_license(self, license_key: str) -> bool:
result = await self.validate(license_key, 1)
return result.get("valid", False)
# Usage
async def main():
client = AsyncabystrixLicense("https://your-server.com")
valid = await client.check_license("XXXXX-XXXXX-XXXXX-XXXXX")
print("Valid!" if valid else "Invalid!")
asyncio.run(main())CLI Tool Example
python
import argparse
import requests
def main():
parser = argparse.ArgumentParser(description="abystrixLicense CLI")
parser.add_argument("key", help="License key to validate")
parser.add_argument("--product", type=int, default=1, help="Product ID")
parser.add_argument("--server", default="https://your-server.com", help="Server URL")
args = parser.parse_args()
response = requests.post(
f"{args.server}/api/v1/validate",
json={"licenseKey": args.key, "productId": args.product}
)
data = response.json()
if data.get("valid"):
print("✅ License is valid!")
else:
print(f"❌ {data.get('message', 'Invalid license')}")
if __name__ == "__main__":
main()