Authdog

FastAPI quickstart

Last updated Sep 10, 2026CI passing
View as Markdown

Outcome: a FastAPI route that returns the Authdog user only when require_auth succeeds. About five minutes.

Unreleased: not on PyPI. Install from the public source tree. Do not run pip install authdog-fastapi in production.

  1. Prerequisites: Python 3.10+ and an Authdog environment.

1. Create an environment and copy the public key

In the console:

  1. Create a tenant, a project, and an environment.
  2. Open Dashboard (/dashboard/home) and copy Public key (pk_...).

The public key is publishable. Details: Environments.

2. Install from source

python -m pip install "./packages/python[fastapi]"

Clone or pin `packages/python`. FastAPI 0.110+.

3. Set the env var

export PK_AUTHDOG="pk_..."

4. Construct the client

import os
from authdog.fastapi import Authdog

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

5. Protect one route

from fastapi import Depends, FastAPI

app = FastAPI()

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

6. Verify

GET /me without a session should be 401. With a valid authdog-session cookie or Authorization: Bearer <token> from hosted sign-in, you should get the user.

If it fails: wrong environment key; used session instead of require_auth; or pip looked on PyPI (use the source extra).

Next

The FastAPI guide covers logout, caching, and fetch_user=False. Other Python frameworks: Django, Flask, Starlette, aiohttp.