Skip to main content

Stackure Python SDK

Check build PyPI version Python versions PyPI - Downloads Trusted publisher License: MIT

Passwordless magic-link authentication SDK for Python — drop-in ASGI and WSGI middleware, zero dependencies.

Protect an app with one line, or verify sessions and send magic links directly against the Stackure auth API.

Install

pip install stackure

Requires Python 3.14+.

Protect an app

import stackure

app_id = "7f3c1a2e-9b4d-4e6f-8a1b-2c3d4e5f6071"  # your app's UUID in Stackure

# ASGI — FastAPI, Starlette, Quart
app = stackure.auth(app_id, "view_any_app")(app)

# WSGI — Flask, Django
flask_app.wsgi_app = stackure.auth(app_id, "view_any_app")(flask_app.wsgi_app)

The same wrapper handles both; it detects the protocol it was called under.

Access the authenticated user in your view:

user = stackure.user_from_request(request)
print(user.user_email, user.user_permissions)
  • API requests get JSON errors
  • Browser requests get redirected to sign-in
  • The sign-in handoff is automatic: Stackure hands the browser back with a session_token, the middleware stores it as a cookie on your domain and strips it from the URL

Requirements

Stackure binds sessions to the browser's user agent and IP. The SDK validates from your server, so it forwards the original User-Agent and X-Forwarded-For. Your app must see the real client IP — if it runs behind a proxy or CDN, make sure that layer sets X-Forwarded-For.

Every request is validated against Stackure, so revocation is immediate.

Verify manually

result = stackure.verify(app_id, request)

if not result.authenticated:
    # result.error.code, result.error.message, result.error.sign_in_url
    ...

# result.user

verify never raises — transport and API failures come back as a 500 result. It accepts a WSGI environ, an ASGI scope, or a framework request object (Starlette, FastAPI, Flask, Django).

Send a magic link

resp = stackure.send_magic_link("user@example.com", app_id)
# resp.message

Log out

r = stackure.logout(request)

Returns the status and headers that clear the app's cookie and redirect to Stackure's sign-out. Your framework builds the response:

# Flask
return "", r.status, r.headers

# Starlette / FastAPI
return Response(status_code=r.status, headers=dict(r.headers))

Configuration

Set STACKURE_BASE_URL to point at a non-production environment:

STACKURE_BASE_URL=https://stage.stackure.com python app.py

Retry-on-5xx (one retry after 500ms) and the 2-second request timeout are hard-coded. Timeouts are never retried.

Errors

Everything except verify raises StackureError. Switch on .code:

from stackure import StackureError

try:
    stackure.send_magic_link(email)
except StackureError as err:
    match err.code:
        case "validation": ...  # bad input
        case "auth": ...        # 401 from the API
        case "forbidden": ...   # 403 from the API
        case "timeout": ...     # request exceeded the 2s timeout
        case "network": ...     # everything else

Contributing

Open a PR. Tag a release when ready: git tag vX.Y.Z && git push --tags — the release workflow builds, signs, and publishes.

Security

Report vulnerabilities via GitHub Security Advisories. Releases publish to PyPI via OIDC trusted publishing with GitHub build-provenance attestations.

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stackure-1.20260906.5.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

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

stackure-1.20260906.5-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file stackure-1.20260906.5.tar.gz.

File metadata

  • Download URL: stackure-1.20260906.5.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for stackure-1.20260906.5.tar.gz
Algorithm Hash digest
SHA256 c4935ae216051b11e76dd94234047da8162251a98da8cd8c833ffae481a507a0
MD5 a61f388869e111d30a7a63681d4a5843
BLAKE2b-256 7b86e8b97c9414689b5d4b9e3a6d0ab2d5200530870d15d8614c8d02afa6182a

See more details on using hashes here.

Provenance

The following attestation bundles were made for stackure-1.20260906.5.tar.gz:

Publisher: release.yml on syi-stackure/sdk-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file stackure-1.20260906.5-py3-none-any.whl.

File metadata

File hashes

Hashes for stackure-1.20260906.5-py3-none-any.whl
Algorithm Hash digest
SHA256 523de0030895dab974803aed62682e7b30b8650beb9aff9a42d4c2b03cfa59be
MD5 21000212bd5c009681acdd203f023bd7
BLAKE2b-256 71fef6e3c67fbc03b7e744e0200b6d9fccd8494087ae8b28fda065bdf0472a5b

See more details on using hashes here.

Provenance

The following attestation bundles were made for stackure-1.20260906.5-py3-none-any.whl:

Publisher: release.yml on syi-stackure/sdk-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

1.20260906.7

2 files

1.20260906.6

2 files

This release

1.20260906.5 This release

2 files

1.20260720.4

2 files

1.20260417.3

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