Skip to main content

Official Stackure authentication SDK for Python

Project description

Stackure Python SDK

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

Authentication for your app. One decorator.

Install

pip install stackure

Requires Python 3.10+.

Protect a route

from stackure import auth

@app.get("/admin")
@auth(app_id="my-app-id", roles=["admin"])
async def admin(request):
    return {"user": request.user}

Works with FastAPI, Starlette, Django, Flask, aiohttp — cookies extracted automatically from the request object.

Verify manually

from stackure import verify

result = await verify(app_id="my-app-id", cookies=dict(request.cookies))

if not result.authenticated:
    return {"error": result.error["message"]}, result.error["code"]

return {"user": result.user}

Send a magic link

from stackure import send_magic_link

await send_magic_link(email="user@example.com", app_id="my-app-id")

Log out

from stackure import logout

await logout(dict(request.cookies))

Configuration

Set STACKURE_BASE_URL to point at a non-production environment:

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

Errors

All errors are StackureError. Switch on .code:

from stackure import StackureError

try:
    await send_magic_link(email=email)
except StackureError as err:
    # err.code is one of: "validation" | "auth" | "forbidden" | "timeout" | "network"
    ...

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

Project details


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.0.0.tar.gz (8.6 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.0.0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: stackure-1.0.0.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for stackure-1.0.0.tar.gz
Algorithm Hash digest
SHA256 fb9743e38a6489b6c7e8c9a0fa4363313c36daf364dcb2981dd7a7509d30d052
MD5 96c73ee4b69c4dec3e05f6dfc0f79234
BLAKE2b-256 9f9c057c6039cc2228bd4510828f962aa1ccf6b25af02997605307358b87dd24

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: stackure-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for stackure-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ccff7364677d1049815e2fc9b1591bd076b3c0a316ce653fee1717b65b23ecc4
MD5 6cd36b3748be5cd73cb5e34f3ba3c1a9
BLAKE2b-256 24eb9546608ca49fffbcfa16913ba1c2724ef4dc0f59caf36dafd84d0e8e9d14

See more details on using hashes here.

Provenance

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

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page