Outcome: an aiohttp handler that returns 401 unless Authdog authenticates the caller. About five minutes.

**Unreleased:** not on PyPI. Install from the public source tree.

0. Prerequisites: Python 3.10+, aiohttp 3.9+, and an Authdog environment.

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

In the [console](https://console.authdog.com), create a tenant → project → environment and copy **Public key** from **Dashboard**. Details: [Environments](/docs/console/environments).

## 2. Install from source

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

Pin [`packages/python`](https://github.com/authdog/web-sdk/tree/main/packages/python).

## 3. Set the env var

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

## 4. Construct the client

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

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

## 5. Protect one handler

```python
from aiohttp import web

@authdog.require_auth
async def me(request):
    ctx = await authdog.session(request)
    return web.json_response(ctx.user)

app = web.Application(middlewares=[authdog.middleware])
app.router.add_get("/me", me)
```

## 6. Verify

`GET /me` without a session → 401. With a valid cookie or bearer token from hosted sign-in → user JSON.

If it fails: middleware not registered; wrong environment key; expected FastAPI `Depends` (this binding is a decorator plus `await session`).

## Next

The [aiohttp guide](/docs/backend/aiohttp) covers logout (`HTTPFound`) and async session. Other Python frameworks: [FastAPI](/docs/quickstarts?sdk=fastapi), [Django](/docs/quickstarts?sdk=django), [Flask](/docs/quickstarts?sdk=flask), [Starlette](/docs/quickstarts?sdk=starlette).
