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.

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

## 1. Create an environment and copy the public key

In the [console](https://console.authdog.com):

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](/docs/console/environments).

## 2. Install from source

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

Clone or pin [`packages/python`](https://github.com/authdog/web-sdk/tree/main/packages/python). FastAPI 0.110+.

## 3. Set the env var

```bash
export PK_AUTHDOG="pk_..."
```

## 4. Construct the client

```python
import os
from authdog.fastapi import Authdog

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

## 5. Protect one route

```python
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](/docs/backend/fastapi) covers logout, caching, and `fetch_user=False`. Other Python frameworks: [Django](/docs/quickstarts?sdk=django), [Flask](/docs/quickstarts?sdk=flask), [Starlette](/docs/quickstarts?sdk=starlette), [aiohttp](/docs/quickstarts?sdk=aiohttp).
