Authdog

Python · FastAPI · Flask · Django · Starlette · aiohttp

Authentication for FastAPI and every Python framework

A session resolver, a require_auth gate, and a logout handler for Python backends, with idiomatic bindings for FastAPI, Flask, Django, Starlette, and aiohttp over one shared core. Validate Authdog sessions on every request, on the same wire as the Node SDKs.

One dependency
Add authdog.session as a dependency and any path operation gets a typed AuthdogContext. No middleware boilerplate.
One enforcement point
Depend on authdog.require_auth and unauthenticated requests are rejected with 401 before your handler runs.
Five frameworks, one core
FastAPI, Flask, Django, Starlette, and aiohttp bindings share the same public-key, cookie, and userinfo logic.
At most one userinfo call
The resolved context is cached on the request, so combining session and require_auth costs a single lookup.

Add the dependency

# main.py
from authdog.fastapi import Authdog

authdog = Authdog(public_key=os.environ["PK_AUTHDOG"])

@app.get("/")
async def index(ctx=Depends(authdog.session)):
    return {"authenticated": ctx.is_authenticated}

Gate routes with require_auth

# routes.py
@app.get("/me")
async def me(user=Depends(authdog.require_auth)):
    return user

Your framework, one core

Everything Python apps need

A drop-in session resolver, a require_auth gate, and a typed context, delivered as a FastAPI dependency, a Flask decorator, Django/Starlette middleware, or an aiohttp middleware, all wire-compatible with the rest of your Authdog stack.

01

A FastAPI dependency

Depends(authdog.session) resolves the request's session and returns a typed AuthdogContext with token, user, and is_authenticated for any path operation.

  • Typed AuthdogContext
  • Any path operation
02

require_auth gate

Depend on authdog.require_auth and FastAPI raises HTTPException(401) for unauthenticated requests, returning the user object otherwise. This is the security boundary.

  • 401 before your handler
  • Returns the verified user
03

At most one userinfo call

The resolved context is cached on request.state, so combining session and require_auth on one request makes a single outbound userinfo call.

  • Cached on request.state
  • One outbound call
04

Pick your framework

Import authdog.fastapi, authdog.flask, authdog.django, authdog.starlette, or authdog.aiohttp. Each is idiomatic for its framework and shares the same core, cookie parsing, and userinfo flow.

  • Five idiomatic bindings
  • One shared core
05

Safe logout handler

authdog.logout(request) returns a RedirectResponse that expires the session cookie and redirects to a redirect_uri sanitized against open redirects.

  • Expires the cookie
  • Open-redirect safe
06

Same wire as Node

It mirrors @authdog/express and @authdog/fastify on the wire, so one Authdog environment serves your Node and Python services interchangeably.

  • One environment
  • Node and Python together
01

Install

pip install the extra for your framework, e.g. authdog[fastapi].

02

Resolve

Add the session dependency or middleware for your stack.

03

Gate routes

Depend on require_auth where a user is required.

Add auth to your Python app.

pip install the SDK, import the binding for your framework, and gate your routes with require_auth today. Free to start, with secure defaults built in.