Official KeyThai SDK — license activation, validation, Management API and offline Ed25519 verification for keythai.net
Project description
keythai (Python)
Official KeyThai SDK for Python — license activation, validation, the Management API, and offline Ed25519 signature verification. Requires Python 3.9+.
pip install keythai
Quickstart
from keythai import KeyThaiClient, KeyThaiApiError, get_device_fingerprint
client = KeyThaiClient("kt_live_xxxxxxxxxxxx")
key = "KEYT-AB12-3C4D-5E6F-7G8H-9J0K"
fingerprint = get_device_fingerprint()
try:
# Activate this machine (consumes one seat; idempotent per fingerprint)
res = client.activate(key, fingerprint, name="My PC", platform_name="windows")
print(res["valid"], res["status"], res["expires_at"])
# Later: just check status
v = client.validate(key, fingerprint)
if not v["valid"]:
print("not valid:", v["status"])
except KeyThaiApiError as e:
print(f"[{e.code}] ({e.status}) {e.message}")
Offline verification (Ed25519)
from keythai import verify_signature, verify_lic_file
# Fetch the public JWK once and cache/embed it.
jwk = client.list_keys()["keys"][0]["publicJwk"]
# 1) Verify a live response
res = client.validate(key, fingerprint)
if not verify_signature(jwk, res):
raise RuntimeError("signature mismatch — response was tampered")
# 2) Verify an offline .lic file (checks signature AND expires_at)
lic = verify_lic_file(jwk, lic_file_contents)
if not lic["valid"]:
raise RuntimeError(lic["reason"]) # e.g. "license หมดอายุ"
print(lic["payload"]["expires_at"])
Management API
products = client.list_products()
policies = client.list_policies(products[0]["id"])
# Issue a license — the plaintext key is returned ONCE.
created = client.create_license(
product=products[0]["code"],
policy_id=policies[0]["id"],
holder_name="สมชาย",
holder_email="somchai@example.com",
quantity=1,
)
print(created["licenses"][0]["key"])
page = client.list_licenses(status="active", q="somchai", page=1, limit=25)
client.update_license(created["licenses"][0]["key"], action="suspend")
client.remove_machine(created["licenses"][0]["key"], fingerprint)
Error handling
Every non-2xx response raises KeyThaiApiError with .code (e.g.
SEAT_LIMIT_REACHED), .status (HTTP code) and .message. Codes:
INVALID_KEY, LICENSE_SUSPENDED, LICENSE_REVOKED, LICENSE_EXPIRED,
SEAT_LIMIT_REACHED, MACHINE_NOT_FOUND, RATE_LIMITED, QUOTA_EXCEEDED,
UNAUTHORIZED, VALIDATION_ERROR.
คู่มือภาษาไทย
keythai คือ SDK อย่างเป็นทางการของ KeyThai สำหรับ Python 3.9+
— รองรับ activate / validate license, Management API และตรวจลายเซ็น Ed25519 แบบ offline
ติดตั้ง
pip install keythai
เริ่มต้นใช้งาน
from keythai import KeyThaiClient, KeyThaiApiError, get_device_fingerprint
client = KeyThaiClient("kt_live_xxxxxxxxxxxx")
fp = get_device_fingerprint()
try:
res = client.activate("KEYT-AB12-3C4D-5E6F-7G8H-9J0K", fp, platform_name="windows")
print("สถานะ:", res["status"], "valid:", res["valid"])
except KeyThaiApiError as e:
print(f"ผิดพลาด [{e.code}]: {e.message}")
ตรวจลายเซ็น offline + ไฟล์ .lic
from keythai import verify_lic_file
jwk = client.list_keys()["keys"][0]["publicJwk"]
lic = verify_lic_file(jwk, lic_file_contents)
if not lic["valid"]:
raise RuntimeError(lic["reason"]) # เช่น "license หมดอายุ"
ออก license อัตโนมัติ (Management API)
created = client.create_license(
product="my-app",
policy_id="01J...",
holder_name="สมชาย",
quantity=1,
)
# created["licenses"][0]["key"] คือ plaintext key — แสดงครั้งเดียวเท่านั้น
License
MIT © KeyThai
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file keythai-0.1.0.tar.gz.
File metadata
- Download URL: keythai-0.1.0.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7334a31412d9700eb08ffdb5ee642956783c705b029ef2dd42b0c93adc48a3f9
|
|
| MD5 |
d8b817bb34acbb6545a992e9ab4d171d
|
|
| BLAKE2b-256 |
5e8e76284b45cba4f98267d1dc43b2e5f90bb8cf4e2ac8a370a5ac4d67c409f9
|
File details
Details for the file keythai-0.1.0-py3-none-any.whl.
File metadata
- Download URL: keythai-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75830f21dc9e6d63e879603a6308cb6d8df4b4a04af24b752b40c13a18ee2101
|
|
| MD5 |
8e56c3bc3709c2d427dd289bb9fa5400
|
|
| BLAKE2b-256 |
0322be7ea9b6a14e0c5d00a0a503ab479c664b06a0b30c5377d465a701c5b9d4
|