AstraGuard license management SDK for Python
Project description
AstraGuard Python SDK
Official Python SDK for AstraGuard license management.
Installation
pip install astraguard
Requires Python 3.8+ and requests>=2.28.0.
Quick Start
from astraguard import AstraGuard
guard = AstraGuard(
api_url="https://api.astraguard.io",
product_id="your-product-uuid",
)
# Validate a license key
result = guard.validate("XXXX-XXXX-XXXX-XXXX")
if result.valid:
print("License accepted!")
print(f"Expires: {result.expires_at or 'never (lifetime)'}")
else:
print(f"License rejected: {result.reason}")
Activate (first use)
# Binds the hardware ID on first activation
result = guard.activate("XXXX-XXXX-XXXX-XXXX")
if result.valid:
print("Activation successful!")
Validate or Exit
Terminate the process automatically when the license is invalid - ideal for CLI tools and desktop apps:
result = guard.validate_or_exit(
"XXXX-XXXX-XXXX-XXXX",
message="Invalid license. Purchase at https://astraguard.io",
)
# Execution continues only when the license is valid
print(f"Welcome! {result.expires_at}")
Features and Variables
result = guard.validate("XXXX-XXXX-XXXX-XXXX")
# Check a feature flag
if result.has_feature("premium_mode"):
enable_premium()
# Or use the shortcut on the client (uses last result)
if guard.has_feature("premium_mode"):
enable_premium()
# Read a remote variable
api_endpoint = result.get_variable("api_url", default="https://default.example.com")
Anti-Debug Protection
from astraguard import AstraGuard
guard = AstraGuard(api_url="https://api.astraguard.io", product_id="your-uuid")
# Exit immediately when a debugger is detected
guard.check_debug(exit_on_detect=True)
# Or check manually
from astraguard import is_debugger_attached
if is_debugger_attached():
sys.exit(1)
Custom HWID
from astraguard import get_hwid
hwid = get_hwid()
print(f"This machine's HWID: {hwid}") # e.g. A1B2-C3D4-E5F6-7890
# Pass a custom HWID to validate/activate
result = guard.validate("XXXX-XXXX-XXXX-XXXX", hwid=hwid)
Error Handling
from astraguard import AstraGuard, AstraGuardError
guard = AstraGuard(api_url="https://api.astraguard.io", product_id="your-uuid")
try:
result = guard.validate("XXXX-XXXX-XXXX-XXXX")
except AstraGuardError as e:
print(f"Error [{e.code}]: {e}")
# e.code values: NETWORK_ERROR, MAINTENANCE_MODE, RATE_LIMITED, SERVER_ERROR, ...
Debug Logging
guard = AstraGuard(
api_url="https://api.astraguard.io",
product_id="your-uuid",
debug=True, # prints request/response details to stderr
)
Version Enforcement
guard = AstraGuard(
api_url="https://api.astraguard.io",
product_id="your-uuid",
version="1.2.0", # sent with every validate call
)
result = guard.validate("XXXX-XXXX-XXXX-XXXX")
if result.needs_update:
print("Please update the application.")
sys.exit(1)
LicenseResult Reference
| Attribute | Type | Description |
|---|---|---|
valid |
bool |
Whether the license is accepted |
reason |
str or None |
Rejection reason (e.g. expired, hwid_mismatch) |
message |
str or None |
Human-readable message from the server |
expires_at |
str or None |
ISO 8601 expiry date, or None for lifetime |
remaining_days |
int or None |
Days until expiry |
features |
list[str] |
Enabled feature flag names |
variables |
dict[str, str] |
Remote key-value configuration |
license |
LicenseInfo or None |
Full license object |
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
astraguard-1.0.0.tar.gz
(9.6 kB
view details)
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 astraguard-1.0.0.tar.gz.
File metadata
- Download URL: astraguard-1.0.0.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f91fcbcd979021e15ae21aad4dde0c67fb971a2f8228e279de65f1f67a7cb88
|
|
| MD5 |
9a795e4ce7df7134ca308dbe5c06d8e9
|
|
| BLAKE2b-256 |
ad2811e5842566268a275a1d84b68bdd553b0c3958f0bd0f243e05894d73647e
|
File details
Details for the file astraguard-1.0.0-py3-none-any.whl.
File metadata
- Download URL: astraguard-1.0.0-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5e4d68d77889bf790355dbd30bf9d3aa70faa03782a7c63b53771a0dca4e67ba
|
|
| MD5 |
e55415dee854838246730a534ee3f591
|
|
| BLAKE2b-256 |
fd905a6160caeb1a5d9a4341b8d2d03bb052589aed3c93802b7dea5ead259df6
|