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.6.tar.gz (12.9 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.6-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: stackure-1.20260906.6.tar.gz
  • Upload date:
  • Size: 12.9 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.6.tar.gz
Algorithm Hash digest
SHA256 d3d62584effef9240eb3ce9556f2b0f94e7015b2fe7c76b63607a22019139ff1
MD5 cef2befd04c73b77eed8626dc1d272e1
BLAKE2b-256 9e3972d732b593485500a91caf65875932b9f6607910c297253fc52a0454202b

See more details on using hashes here.

Provenance

The following attestation bundles were made for stackure-1.20260906.6.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.6-py3-none-any.whl.

File metadata

File hashes

Hashes for stackure-1.20260906.6-py3-none-any.whl
Algorithm Hash digest
SHA256 7408d4834f3bce045c2297d0b5828fc90683f390d2ab89bc34c17461a1a73f11
MD5 69771728a53bdf0a66ea55691dc29dd0
BLAKE2b-256 e60ed15d71af8a968f719ebfb7d78bfaf399b56819e091efd380c093c01bc5fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for stackure-1.20260906.6-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

This release

1.20260906.6 This release

2 files

1.20260906.5

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