Python SDK

Python integration using the requests library. Works with Python 3.7+ on all platforms.

Simple setup with pip

Only requires the requests package. Install with pip install requests.

Installation

Install dependencies
bash
pip install requests

SDK Implementation

A complete wrapper class for the Authon API:

authon.py
Python
import requests
import platform
import uuid

class Authon:
    def __init__(self, app_id: str, api_key: str, api_url: str = "https://api.authon.pro"):
        self.app_id = app_id
        self.api_key = api_key
        self.api_url = api_url
        self.session_token = ""
        self.user = {}
        self.app = {}
        self.last_error = ""
        self.initialized = False

    def _post(self, data: dict) -> dict:
        """Send a POST request to the Authon API."""
        try:
            data["appId"] = self.app_id
            data["apiKey"] = self.api_key
            resp = requests.post(f"{self.api_url}/v1", json=data, timeout=10)
            result = resp.json()
            if not result.get("success"):
                self.last_error = result.get("message", "Unknown error")
            return result
        except requests.RequestException as e:
            self.last_error = str(e)
            return {"success": False, "message": str(e)}

    def init(self) -> bool:
        """Initialize the application. Must be called first."""
        result = self._post({"type": "init"})
        if result.get("success"):
            self.app = result.get("data", {})
            self.initialized = True
            return True
        return False

    def login(self, username: str, password: str, hwid: str = "") -> bool:
        """Authenticate with username and password."""
        data = {"type": "login", "username": username, "password": password}
        if hwid:
            data["hwid"] = hwid
        result = self._post(data)
        if result.get("success"):
            self.user = result.get("data", {})
            self.session_token = self.user.get("sessionToken", "")
            return True
        return False

    def register(self, username: str, password: str, license_key: str, hwid: str = "") -> bool:
        """Register a new user with a license key."""
        data = {
            "type": "register",
            "username": username,
            "password": password,
            "licenseKey": license_key,
        }
        if hwid:
            data["hwid"] = hwid
        result = self._post(data)
        if result.get("success"):
            self.user = result.get("data", {})
            return True
        return False

    def license(self, license_key: str, hwid: str = "") -> bool:
        """Authenticate with a license key only."""
        data = {"type": "license", "licenseKey": license_key}
        if hwid:
            data["hwid"] = hwid
        result = self._post(data)
        if result.get("success"):
            self.user = result.get("data", {})
            self.session_token = self.user.get("sessionToken", "")
            return True
        return False

    def check(self) -> bool:
        """Verify the current session is valid."""
        result = self._post({"type": "check", "sessionToken": self.session_token})
        return result.get("success", False)

    def get_var(self, key: str) -> str:
        """Get an application variable."""
        result = self._post({"type": "var", "sessionToken": self.session_token, "key": key})
        if result.get("success"):
            return result.get("data", {}).get("value", "")
        return ""

    def set_var(self, key: str, value: str) -> bool:
        """Set a user variable."""
        result = self._post({
            "type": "setvar",
            "sessionToken": self.session_token,
            "key": key,
            "value": value,
        })
        return result.get("success", False)

    def download_file(self, file_id: str) -> bytes:
        """Download a file by ID. Returns file bytes."""
        result = self._post({"type": "file", "sessionToken": self.session_token, "fileId": file_id})
        if result.get("success"):
            url = result["data"]["downloadUrl"]
            full_url = f"{self.api_url}{url}"
            resp = requests.get(full_url, timeout=30)
            return resp.content
        return b""

    def log(self, message: str) -> bool:
        """Send a log message to the dashboard."""
        result = self._post({"type": "log", "sessionToken": self.session_token, "message": message})
        return result.get("success", False)

    @staticmethod
    def get_hwid() -> str:
        """Generate a hardware ID from system info."""
        node = uuid.getnode()
        return f"HWID-{node:012X}"

Quick Start

main.py
Python
from authon import Authon

APP_ID = "your-app-id"
API_KEY = "your-api-key"

auth = Authon(APP_ID, API_KEY)

# Step 1: Initialize
print("[*] Connecting...")
if not auth.init():
    print(f"[!] Failed: {auth.last_error}")
    exit(1)

print(f"[+] Connected to {auth.app['name']} v{auth.app['version']}")

# Step 2: Login
hwid = Authon.get_hwid()
username = input("Username: ")
password = input("Password: ")

if not auth.login(username, password, hwid):
    print(f"[!] Login failed: {auth.last_error}")
    exit(1)

print(f"[+] Welcome {auth.user['username']}!")
print(f"    Level: {auth.user['level']}")
print(f"    Expires: {auth.user['expiresAt']}")

# Step 3: Verify session
if auth.check():
    print("[+] Session verified.")

# Get a variable
version = auth.get_var("app_version")
if version:
    print(f"    Server version: {version}")

# Log activity
auth.log("User logged in from Python app")
print("\nApplication ready!")

License-Only Authentication

License key validation
Python
from authon import Authon

auth = Authon("your-app-id", "your-api-key")
auth.init()

key = input("Enter license key: ")
hwid = Authon.get_hwid()

if auth.license(key, hwid):
    print(f"[+] License valid! Level: {auth.user['level']}")
    print(f"    Expires: {auth.user['expiresAt']}")
else:
    print(f"[!] Invalid: {auth.last_error}")

Server Variables

Working with variables
Python
# Get an app-level variable (set by admin in dashboard)
download_url = auth.get_var("download_url")
latest_version = auth.get_var("app_version")

# Set a user-level variable
auth.set_var("theme", "dark")
auth.set_var("last_used", "2025-06-15")

print(f"Download URL: {download_url}")
print(f"Latest version: {latest_version}")

File Download

Download a protected file
Python
# Download file after authentication
file_bytes = auth.download_file("your-file-id")

if file_bytes:
    with open("downloaded_module.exe", "wb") as f:
        f.write(file_bytes)
    print(f"[+] File downloaded ({len(file_bytes)} bytes)")
else:
    print(f"[!] Download failed: {auth.last_error}")

Error Handling

Always check return values and use last_error for the error message:

Error handling pattern
Python
if not auth.login(username, password, hwid):
    error = auth.last_error
    if "Invalid credentials" in error:
        print("Wrong username or password")
    elif "Hardware ID mismatch" in error:
        print("This account is locked to another device")
    elif "Account banned" in error:
        print("Your account has been suspended")
    elif "Subscription expired" in error:
        print("Your subscription has expired")
    else:
        print(f"Error: {error}")

Full Working Example

complete_app.py
Python
from authon import Authon
import sys

APP_ID = "your-app-id"
API_KEY = "your-api-key"

def main():
    auth = Authon(APP_ID, API_KEY)

    # Initialize
    print("[*] Connecting to server...")
    if not auth.init():
        print(f"[!] Connection failed: {auth.last_error}")
        sys.exit(1)

    print(f"[+] {auth.app['name']} v{auth.app['version']}")
    print()

    hwid = Authon.get_hwid()
    print(f"[*] HWID: {hwid}")
    print()

    # Menu
    print("[1] Login")
    print("[2] Register")
    print("[3] License Key")
    print()
    choice = input("Choice: ").strip()
    print()

    if choice == "1":
        username = input("Username: ")
        password = input("Password: ")
        if not auth.login(username, password, hwid):
            print(f"[!] Login failed: {auth.last_error}")
            sys.exit(1)

    elif choice == "2":
        username = input("Username: ")
        password = input("Password: ")
        key = input("License Key: ")
        if not auth.register(username, password, key, hwid):
            print(f"[!] Registration failed: {auth.last_error}")
            sys.exit(1)

    elif choice == "3":
        key = input("License Key: ")
        if not auth.license(key, hwid):
            print(f"[!] Invalid license: {auth.last_error}")
            sys.exit(1)

    else:
        print("[!] Invalid choice")
        sys.exit(1)

    # Success
    print()
    print("[+] Authenticated!")
    print(f"    Level: {auth.user.get('level', 'N/A')}")
    print(f"    Expires: {auth.user.get('expiresAt', 'N/A')}")

    # Log activity
    auth.log("Application loaded successfully")

    # Get server variable
    version = auth.get_var("app_version")
    if version:
        print(f"    Server version: {version}")

    print()
    print("Application ready!")
    input("Press Enter to exit...")

if __name__ == "__main__":
    main()

Notes

Python Version

Requires Python 3.7+. The requests library handles all HTTP and JSON automatically.

Cross-Platform

Works on Windows, macOS, and Linux. HWID generation uses UUID which is platform-independent.

PyInstaller

To distribute as an executable, use PyInstaller: pyinstaller --onefile main.py

Obfuscation

Consider using PyArmor or Cython to protect your credentials in production builds.