Advanced User Guide¶
This section covers capabilities beyond the basics — production patterns, advanced OpenAPI customisation, real-time transports, and testing strategies.
Pages¶
| Topic | What you learn |
|---|---|
| Custom Response Classes | Response, JSONResponse, StreamingResponse, FileResponse |
| Response Cookies & Headers | Set cookies and custom headers on responses |
| Using the Request Directly | Access raw request data, headers, client IP |
| Settings & Environment Variables | Twelve-factor config with os.environ / python-dotenv |
| OpenAPI Customisation | Conditional docs, extending the schema |
| Additional Responses | Document extra status codes and response schemas |
| Templates (Jinja2) | Server-side HTML rendering |
| Lifespan Events | Startup/shutdown hooks for connections and caches |
| Behind a Proxy | Root path, forwarded headers, Nginx/Traefik |
| Sub-applications | Mount multiple ASGI apps |
| Server-Sent Events | Push real-time updates to browsers |
| Testing with Overrides | Swap dependencies in tests |
| Async Tests | pytest-asyncio, async fixtures |
| Bigger Applications | Routers, multiple files, packages |
Prerequisites¶
Complete the Tutorial before reading this section.