Skip to main content

astraguard

Official AstraGuard SDK for Python - license validation, HWID binding, and AES-256-GCM offline cache for server-side applications.

Server-Side Only This SDK is for Python server applications (Flask, FastAPI, Django, etc.). Do NOT embed it in client-side software - Python offers no meaningful anti-debug or anti-VM protection. For desktop protection use the C++ header or Rust SDK.

Installation

pip install astraguard

Async support (FastAPI, asyncio):

pip install "astraguard[async]"

Sync (Flask / Django)

from astraguard import AstraGuardClient

client = AstraGuardClient(
    api_url="https://api.astraguard.io",
    product_id="your-product-id",
    # Response Key from Dashboard -> Products -> Response Key. Without this,
    # validate()/activate() refuse to trust any response (fail closed) -
    # see the Security section below.
    response_auth_key="YOUR-RESPONSE-KEY-BASE64",
)

result = client.validate("XXXX-XXXX-XXXX-XXXX")
if result.valid:
    print("License valid!")

Async (FastAPI)

from astraguard import AsyncAstraGuardClient

client = AsyncAstraGuardClient(
    api_url="https://api.astraguard.io",
    product_id="your-product-id",
    response_auth_key="YOUR-RESPONSE-KEY-BASE64",
)

result = await client.validate("XXXX-XXXX-XXXX-XXXX")

Features

  • validate() / activate() with fully typed responses
  • HMAC-SHA256 response verification (fail-closed)
  • AES-256-GCM encrypted offline cache (configurable grace period)
  • Background heartbeat thread
  • Cross-platform HWID (Windows registry, /etc/machine-id, IOPlatformUUID)
  • validate_or_exit() for CLI tools
  • has_feature() / get_variable() shortcuts
  • Update check via /check-update
  • Full type annotations + py.typed marker

Error Handling

from astraguard import NetworkError, ServerError, SignatureMismatch

try:
    result = client.validate(license_key)
except NetworkError:
    pass  # unreachable + no cache
except ServerError as e:
    print(f"HTTP {e.status}")
except SignatureMismatch:
    pass  # tampered response

Security - Response Integrity

Every /validate response is signed by the server with X-AstraGuard-Signature: sha256=<hex>, an HMAC-SHA256 over the exact response body. Pass response_auth_key at construction time with the Response Key from Dashboard -> Products -> Security -> Response Key to enable verification (shown in both quick-start examples above).

  • Fail-closed: without a configured key, validate()/activate() never trust a response - they raise SignatureMismatch instead of silently treating an unsigned reply as valid.
  • Whole-body coverage: the signature check covers the entire response - features, cloud variables, security flags, everything - so a man-in-the-middle can't quietly alter a value in transit.
  • Server-side secret: the Response Key must stay on the server - never send it to a browser or embed it in a distributed client. This SDK is already server-only (see the notice at the top of this README), so this is the natural place for it to live.

Heartbeat

import sys

client.start_heartbeat(
    license_key="XXXX-XXXX-XXXX-XXXX",
    interval=300,
    on_lapse=lambda: sys.exit(1),
)

License

MIT

Links

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.3.0.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

astraguard-1.3.0-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file astraguard-1.3.0.tar.gz.

File metadata

  • Download URL: astraguard-1.3.0.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for astraguard-1.3.0.tar.gz
Algorithm Hash digest
SHA256 e7f03d9c388ef8eebd3f7001b039b11e2bfd952d618a81c6e6045225732a9e98
MD5 7a34b520762c5f79a0a3557c64e7631f
BLAKE2b-256 8baf6eb6e9b8519775c20b61595e407178cc99659ca4d9a3458af7b0f9d4bc2d

See more details on using hashes here.

File details

Details for the file astraguard-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: astraguard-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 15.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for astraguard-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 62fb43c84fb8d888965b1c90691daa23e90ede6eed84e737382aae208819a349
MD5 29eac1798a9046b78e9b3c979a50f0bf
BLAKE2b-256 2942cfc7ca69b02898b301bd37a54f8bb003de03122e90d24430e3d95684b830

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.3.0 This release

2 files

1.2.1

2 files

1.2.0

2 files

1.1.0

2 files

1.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page