Skip to navigation

Python guide

This page walks through the whole Python SDK in the order you would use it. Each step starts with the shortest code that works, then shows the other ways to write it.

Download the Python SDK or install it from PyPI if you have not done so yet.

Requirements

SupportedRecommended
Python3.8 and newer3.11 or newer
Packagesaiohttp 3.8 or newer, cryptography 41 or newer
WindowsWindows 7 SP1 or newer with a supported Python

On Linux and macOS, pass your own systemId and storage when you create the client.

Add the SDK to your project

pip install --pre authlyx-api
from authlyx_api import AuthlyX, AuthlyXError

If you copied AuthlyX.py into your project instead, install aiohttp and cryptography and import from the file:

from AuthlyX import AuthlyX, AuthlyXError

Create the client

app = AuthlyX("YOUR_APP_KEY", "1.0.0")

The first value is your app’s AppKey. Find it in the dashboard under your application’s credentials. The second is the version of the program you are building. AuthlyX compares it with the versions you allow in the dashboard, so raise it each time you ship a new build. See Allowed Versions.

Create one client for the whole program, at module level or on your main app object, and import it wherever you need it. Creating it does not connect; nothing is sent until you call init.

Optional settings go after the version as keywords:

app = AuthlyX("YOUR_APP_KEY", "1.0.0", updatePrompt=False, requestTimeout=15)

All of them are listed in Options.

Three ways to call the SDK

The SDK is built on asyncio. You can use it in three ways. Pick one for your program and stay with it, because the client stays attached to the event loop it first ran on.

StyleLooks likeUse it when
awaitresult = await app.init()Your program already uses asyncio
Blockingresult = run(app.init())Scripts and console tools that do not use asyncio
Callbackapp.init(on_started)Tkinter, PySide and other GUI apps

await

import asyncio
from authlyx_api import AuthlyX
app = AuthlyX("YOUR_APP_KEY", "1.0.0")
async def main():
started = await app.init()
print(started.message)
await app.close()
asyncio.run(main())

Blocking

If you do not want async in your code, give the SDK its own event loop on a background thread and wait on each call with a small helper:

import asyncio
import threading
from authlyx_api import AuthlyX
loop = asyncio.new_event_loop()
threading.Thread(target=loop.run_forever, daemon=True).start()
def run(call):
return asyncio.run_coroutine_threadsafe(call, loop).result()
app = AuthlyX("YOUR_APP_KEY", "1.0.0")
started = run(app.init())
print(started.message)

run(...) waits for the reply and returns the result, or raises the error. Every example on this page that uses await works the same with run(...) around the call instead.

Callback

def on_started(result):
print(result.message)
app.init(on_started)

This returns straight away and calls on_started when the reply arrives. A callback never raises: if something goes wrong, the result it receives has ok set to False with a code and message. Callbacks run on the SDK’s background thread unless you set a callback_dispatcher (see GUI apps).

Callbacks exist for init, initialize, login, registerUser, changePassword, redeemLicense, log, getVariable, updateVariable, getScript, getFeatures, getFeature, getAllMetadata, getMetadata, checkMetadata, checkFeature and sendWebhook. The rest (deviceLogin, checkSession, onResume, setMetadata, saveOfflineAccess, hasAccess, hasOfflineAccess, logout and close) are async only.

Start the SDK

Call init once, before signing in. initialize is the same method with a longer name.

started = await app.init()
if not started.ok:
print(started.message)
raise SystemExit(1)

init gives you a result even when something is wrong, instead of raising:

CodeokWhat happened
APP_INITIALIZEDTrueConnected. Continue to sign-in.
OFFLINE_MODETrueNo internet, but this PC has saved offline access. See Offline access.
NETWORK_...FalseNo internet and nothing saved. Ask the user to try again.
UPDATE_REQUIREDFalseThis version is older than the one in your dashboard. The SDK has already shown an update box.
VERSION_MISMATCHFalseThis version is newer than the dashboard version and is not allowed.
APP_DISABLEDFalseYou paused the app in the dashboard.

Sign in

await app.login("YOUR_LICENSE_KEY")
await app.login("YOUR_USERNAME", "YOUR_PASSWORD")
await app.deviceLogin()

One value is a license key, two values are a username and password, and deviceLogin signs in the current Windows user with no form. Device login only works for devices you approved first; see Device login.

When AuthlyX refuses a sign-in, await raises AuthlyXError:

try:
await app.login(license_key)
print("Welcome")
except AuthlyXError as error:
print(error)

str(error) is a message you can show to the user. error.code is a fixed code for your own checks, such as INVALID_CREDENTIALS, LICENSE_NOT_FOUND, LICENSE_EXPIRED, LICENSE_BANNED, DEVICE_NOT_ALLOWED or DEVICE_LIMIT_REACHED. error.kind says what sort of problem it was:

error.kindMeaningWhat to do
serverAuthlyX answered and said noShow the message
networkNo answer: no internet, firewall, timeoutAsk the user to retry. Do not treat it as a ban.
securityA reply failed verificationDo not unlock anything
storageThe SDK could not read or save its protected filesUsually a permissions problem
cancelledThe request was cancelled or the client was closedNothing

All codes are on the Errors page.

With a callback, no try is needed:

def on_login(result):
if result.ok:
print("Welcome")
else:
print(result.message)
app.login(license_key, on_login)
app.login(username, password, on_login)

A sign-in function you can reuse:

async def sign_in(license_key):
try:
await app.login(license_key)
return True, ""
except AuthlyXError as error:
return False, str(error)

Create an account, change the password, add time

await app.registerUser("YOUR_USERNAME", "YOUR_PASSWORD", "YOUR_LICENSE_KEY")
await app.changePassword("CURRENT_PASSWORD", "NEW_PASSWORD")
await app.redeemLicense("ANOTHER_LICENSE_KEY")

registerUser creates a user account and signs it in. The other two need a signed-in user. All three raise AuthlyXError when they fail, and all three also accept a callback as their last value.

Read the account

After sign-in, app.userData holds the account details. You can read them as attributes or as keys:

user = app.userData
print(user.Username)
print(user["Plan"])
print(user.ExpiryDate)
FieldExampleNotes
UsernamemayaOnly set for username and password accounts
LicenseKeyMAYA-4R8P-2N6K-9Q3WThe key used to sign in or linked to the account
Emailmaya@example.comNone if none was given
PlanPlus
ExpiryDate2027-04-30T23:59:59.000ZNone for lifetime access
SIDS-1-5-21-...The Windows user ID this sign-in is bound to
DeviceLimit3
Country, IpAddressNGWhere the sign-in came from
typelicenseuser, license or device
registeredAt, lastLogin2026-08-12T14:22:10.000Z
features["aim", "esp"]Enabled on/off features
featureValues, metadata{"fov": 90}See Features and metadata

A field that does not exist returns None as an attribute, so app.userData.Username is safe even for a license sign-in. With keys, use user.get("Plan", "") if the key may be missing. Before sign-in and after sign-out, app.userData is empty.

Functions that return text, numbers and yes/no

from datetime import datetime, timezone
def expiry_text():
expiry = app.userData.ExpiryDate
if not expiry:
return "Lifetime"
return expiry[:10].replace("-", "/")
def days_left():
expiry = app.userData.ExpiryDate
if not expiry:
return 0
ends = datetime.fromisoformat(expiry.replace("Z", "+00:00"))
seconds = (ends - datetime.now(timezone.utc)).total_seconds()
return max(0, -int(-seconds // 86400))
def build_top_line():
user = app.userData
if not user.LicenseKey:
return " License: Null"
return f" License: {user.LicenseKey} | Expiry: {expiry_text()}"
def remaining_days():
user = app.userData
if not user.Plan:
return "N/A"
if not user.ExpiryDate:
return "Lifetime"
return f"{days_left()}D"
def is_premium():
return app.userData.Plan == "Premium"

days_left() rounds up, so one hour left counts as 1 day.

Features and metadata

Features come from the plan and the account. Some are on/off, some carry a value such as "high" or 90. Metadata is extra information attached to accounts. See Features and metadata.

Read them from the account

These do not contact AuthlyX:

user = app.userData
aim = "aim" in (user.features or [])
quality = (user.featureValues or {}).get("quality", "low")
discord = (user.metadata or {}).get("discord", "")

The values refresh on every heartbeat, so dashboard changes show up without signing in again. Helpers for text, numbers and yes/no values:

def feature(name, fallback=""):
value = (app.userData.featureValues or {}).get(name)
return fallback if value is None else str(value)
def feature_int(name, fallback=0):
try:
return int(float(feature(name, fallback)))
except ValueError:
return fallback
def feature_bool(name, fallback=False):
text = feature(name).lower()
if text in ("true", "1", "yes", "on"):
return True
if text in ("false", "0", "no", "off"):
return False
return fallback
fov = feature_int("fov", 90)
rainbow = feature_bool("rainbow")

Copy the same three functions with metadata in place of featureValues for metadata.

Ask AuthlyX directly

everything = await app.getFeatures()
print(everything.data["features"])
quality = await app.getFeature("quality")
print(quality.data["value"])
aim = await app.checkFeature("aim")
print(aim.data["enabled"])
all_meta = await app.getAllMetadata()
discord = await app.getMetadata("discord")
vip = await app.checkMetadata("vip")
print(discord.data["value"], vip.data["enabled"])

getMetadata() with no key returns all metadata, like getAllMetadata().

Save metadata

await app.setMetadata("discord", "maya#1234")
await app.setMetadata("level", 5)
await app.setMetadata("vip", True)

Only keys you allowed for SDK writes in the dashboard can be changed.

Cloud variables

motd = await app.getVariable("motd")
print(motd.data)
await app.updateVariable("last_build", "1.4.2")

For getVariable, data is the value itself. See Cloud variables.

Scripts

script = await app.getScript("startup")
print(script.data["content"])

The SDK checks the script’s signature before returning it. It does not run the script. See Scripts.

Logs and webhooks

await app.log("Opened the settings page")
await app.sendWebhook("purchase.clicked", {"item": "skin_42", "price": 4.99})

log writes a line to your app’s logs in the dashboard. sendWebhook sends an event to a webhook you set up in the dashboard; the second value is any JSON-compatible dictionary.

Staying signed in

After sign-in the SDK checks in with AuthlyX in the background (a heartbeat), by default about every 10 minutes, and refreshes features and metadata each time. If you ban, pause or expire the account, the next heartbeat ends the session.

if not await app.hasAccess():
show_login_screen()

To be told when the session ends, pass a function when you create the client:

def on_ended(error):
print("Signed out:", error)
def on_connection(state):
print("Connection:", state)
app = AuthlyX(
"YOUR_APP_KEY",
"1.0.0",
on_session_invalidated=on_ended,
on_connection=on_connection,
)

on_connection receives online, disconnected, untrusted or disposed. To check right away, call await app.checkSession(); await app.onResume() does the same and is meant for when your app wakes from sleep. To run the heartbeat yourself, pass heartbeat="manual" and call checkSession() from your own timer. More in Sessions and heartbeats.

Offline access

await app.login(license_key)
await app.saveOfflineAccess()

Later, without internet, init returns OFFLINE_MODE with ok true, and the user signs in with the same license key or username and password. The SDK checks them against the saved permit and the sign-in succeeds with the code OFFLINE_ACCESS. await app.hasOfflineAccess() tells you whether this PC has a valid saved permit. Signing out deletes it. See Offline access.

Updates

When this version is not allowed, init fails with UPDATE_REQUIRED or VERSION_MISMATCH and the SDK shows a message box with the new version, release notes and a button to open your download page. To show your own window, pass updatePrompt=False and read the details:

started = await app.init()
if started.code in ("UPDATE_REQUIRED", "VERSION_MISMATCH"):
update = (started.data or {}).get("update") or {}
print(started.message, update.get("version"), update.get("url"), update.get("notes"))

See Automatic updates.

Sign out and shut down

await app.logout()
await app.close()

logout ends the session, clears userData and deletes saved offline access on this PC. close stops the background work; call it when your program exits. A closed client cannot be used again.

GUI apps

In a GUI, waiting on the UI thread freezes the window. Use callbacks, and pass callback_dispatcher so the SDK hands each callback to your UI thread. With Tkinter:

import tkinter as tk
from authlyx_api import AuthlyX
root = tk.Tk()
status = tk.Label(root, text="Connecting...")
status.pack()
app = AuthlyX("YOUR_APP_KEY", "1.0.0", callback_dispatcher=lambda run: root.after(0, run))
def on_started(result):
status.config(text=result.message)
app.init(on_started)
root.mainloop()

With PySide or PyQt, use callback_dispatcher=lambda run: QTimer.singleShot(0, run).

For the async-only calls, keep the background loop from Blocking and run them on a worker thread, or schedule them with asyncio.run_coroutine_threadsafe(app.logout(), loop).

Results and errors

Every call returns, or passes to your callback, a Result:

MemberMeaning
ok / successTrue when the call worked
failedThe opposite of ok
codeFixed code such as APP_INITIALIZED or LICENSE_EXPIRED
messageText you can show to the user
request_idQuote this when you contact support
dataThe call’s data

AuthlyXError has code, kind, status, request_id and data, and str(error) is the message.

Options

KeywordDefaultWhat it does
updatePromptTrueShow the built-in update boxes
requestTimeout8Seconds one call may take, including retries
retryLimit2How many times a failed request is retried (0 to 5)
heartbeat"server""manual" to run session checks yourself
on_session_invalidatedNoneCalled when AuthlyX ends the session
on_connectionNoneCalled when the connection state changes
callback_dispatcherNoneRuns each callback, for example on your UI thread
build_hash""This build’s hash, if you use Application hashes
storageProtected files in %LOCALAPPDATA%\AuthlyX\v3Another store, such as WindowsProtectedStore(path)
systemIdThe Windows user SIDRequired on Linux and macOS

A complete program

import asyncio
from authlyx_api import AuthlyX, AuthlyXError
app = AuthlyX("YOUR_APP_KEY", "1.0.0")
async def main():
started = await app.init()
if not started.ok:
print(started.message)
return
license_key = input("License key: ")
try:
await app.login(license_key)
except AuthlyXError as error:
print(error)
return
user = app.userData
print("Plan:", user.Plan)
print("Expires:", user.ExpiryDate or "Lifetime")
if "beta" in (user.features or []):
print("Beta features are on")
input("Press Enter to sign out")
try:
await app.logout()
except AuthlyXError:
pass
await app.close()
asyncio.run(main())

Each method also has its own page with every language side by side under SDK methods.