Skip to main content

Requirements

  • Python 3.9 or later
  • Dependencies: cryptography and typing_extensions (installed automatically with the PyPI package).

Installation

Install from PyPI as authforge-sdk. In code, import the authforge module:
Need a vendored single file? Copy authforge.py from the GitHub repository and ensure cryptography is declared in your environment. The published wheel is recommended for most projects.

Quick start

Constructor parameters

ttl_seconds

Requested session token lifetime in seconds for /auth/validate. Pass None (or omit) to accept the server default of 24 hours. The server clamps to [3600, 604800] (1 hour to 7 days). The requested TTL is preserved across heartbeat refreshes so long-running apps in LOCAL mode can extend their offline window up to 7 days.

Billing

  • Each successful login() or validate_license() costs 1 credit (one /auth/validate debit).
  • Heartbeats cost 1 credit per 10 successful calls (billed on every 10th heartbeat). Any heartbeat_interval ≥ 1 is economically safe.
  • Revocations take effect on the next heartbeat regardless of interval.

Login

Returns True if authentication succeeded, False otherwise. On success, the SDK starts a background heartbeat thread automatically.

Validate license (no heartbeat)

Same /auth/validate flow and signatures as login, without storing session state on the client or starting the heartbeat thread. On success, the result includes optional entitlement convenience fields when the server sends them: session_expires_at, license_expires_at (None for lifetime keys after a JSON null), max_hwid_slots, hwid_count, and license_label. The full signed payload remains in session_data.

Failure callback

If authentication or a heartbeat fails, the SDK calls your on_failure callback. If no callback is set (or the callback raises an exception), the SDK calls os._exit(1).
If you don’t set on_failure, the SDK terminates the process immediately on any failure. Always set a callback in production to handle graceful shutdown.

Reading variables

After a successful login, app variables and license variables are available on the client:

Heartbeat modes

See Heartbeat Modes for a detailed comparison.

Full example

GitHub

Full source, changelog, and issues: AuthForgeCC/authforge-python