Stackure Python SDK
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+.
Configure
export STACKURE_APP_SECRET=... # from the app page in Stackure, shown once
Sent as X-App-Secret on every call. The first call that actually reaches Stackure raises StackureError("validation") if it is missing. STACKURE_BASE_URL optionally overrides the API host.
A newly registered app is not usable by anyone, even its creator, until it is shared with the organization or assigned to a team in Stackure. Do that before testing sign-in.
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, "can_approve_invoice")(app)
# WSGI — Flask, Django
flask_app.wsgi_app = stackure.auth(app_id, "can_approve_invoice")(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 POSTs a
session_token(an app-scoped session token valid only for this app) back to your app, the middleware validates it and stores it as astackure_sessioncookie on your domain (notsession, which Flask uses for its own session). Handoff bodies over 4 KB are ignored.
Requirements
Sessions are not bound to the browser's user agent or IP. The SDK still
forwards the original User-Agent and X-Forwarded-For when validating from
your server, but they are informational only.
Every request with a session token is validated against Stackure, so revocation is immediate. Requests without a well-formed token get the sign-in URL without a Stackure call.
Every call has one 2-second deadline covering connect, headers, body and the
single retry. Calls retry once after 500 ms on a 5xx or a connection failure,
never on a timeout. A timeout anywhere, including while reading the body,
raises StackureError("timeout").
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))
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 deadline
case "network": ... # everything else
Contributing
Open a PR.
Security
Report vulnerabilities via GitHub Security Advisories. Releases publish to PyPI via OIDC trusted publishing with GitHub build-provenance attestations.
License
MIT
Metadata
Release files for stackure 1.20260926.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| stackure-1.20260926.10.tar.gz | 14.3 kB | With provenance | Details for stackure-1.20260926.10.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| stackure-1.20260926.10-py3-none-any.whl | Python 3 | none | any | Details for stackure-1.20260926.10-py3-none-any.whl |
Total release size: 31.2 kB
Release files / stackure-1.20260926.10.tar.gz
| Download URL | stackure-1.20260926.10.tar.gz |
|---|---|
| Size | 14.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8645b08429a47e46abd9b2bbd9e4040a91127d6e5e375abe926408fd62277bd4
|
|
BLAKE2b-256 checksum How to use checksums |
a0928fc9ba18e0f31bcea4d079caa9dba830261a6c9532a029056714c945246b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 26, 2026.
Transparency logRelease files / stackure-1.20260926.10-py3-none-any.whl
| Download URL | stackure-1.20260926.10-py3-none-any.whl |
|---|---|
| Size | 16.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a76eb4efd3dc4cbb95a8b0c6d3532b10dc4d674d50d7a08209acaba16e78222f
|
|
BLAKE2b-256 checksum How to use checksums |
a5267043af79bd6b76494ed56dc75117b062e97dddcf343f3d70f42650e45179
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 26, 2026.
Transparency logSecurity for stackure 1.20260926.10
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for stackure-1.20260926.10.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 26, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.