@app.post("/items") async def create_item(item: ItemCreate): return item
Generates interactive API documentation (Swagger UI and ReDoc) automatically from your code.
| Do | Don't | |----|-------| | Use Pydantic for settings and payloads | Put business logic in endpoints | | Write async database drivers | Block the event loop with time.sleep() | | Version your API ( /v1/ , /v2/ ) | Expose internal implementation details | | Use environment variables for config | Hardcode secrets or URLs | | Implement idempotency for POST | Forget to handle partial failures | | Set timeouts on all HTTP calls | Ignore distributed tracing |
fastapi==0.104.1 uvicorn[standard]==0.24.0 pydantic==2.4.2 sqlalchemy==2.0.22 asyncpg==0.29.0 alembic==1.12.1 httpx==0.25.1 python-jose[cryptography]==3.3.0 prometheus-fastapi-instrumentator==6.1.0 opentelemetry-api==1.20.0 opentelemetry-sdk==1.20.0 pytest==7.4.3 pytest-asyncio==0.21.1
version: "3.8" services: api: build: . ports: - "8000:8000" depends_on: - db db: image: postgres:15 environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: secret
@app.post("/items") async def create_item(item: ItemCreate): return item
Generates interactive API documentation (Swagger UI and ReDoc) automatically from your code.
| Do | Don't | |----|-------| | Use Pydantic for settings and payloads | Put business logic in endpoints | | Write async database drivers | Block the event loop with time.sleep() | | Version your API ( /v1/ , /v2/ ) | Expose internal implementation details | | Use environment variables for config | Hardcode secrets or URLs | | Implement idempotency for POST | Forget to handle partial failures | | Set timeouts on all HTTP calls | Ignore distributed tracing |
fastapi==0.104.1 uvicorn[standard]==0.24.0 pydantic==2.4.2 sqlalchemy==2.0.22 asyncpg==0.29.0 alembic==1.12.1 httpx==0.25.1 python-jose[cryptography]==3.3.0 prometheus-fastapi-instrumentator==6.1.0 opentelemetry-api==1.20.0 opentelemetry-sdk==1.20.0 pytest==7.4.3 pytest-asyncio==0.21.1
version: "3.8" services: api: build: . ports: - "8000:8000" depends_on: - db db: image: postgres:15 environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: secret