# FastAPI + Postgres + SQLAlchemy
URL: https://wwadd.dev/stacks/fastapi-postgres-sqlalchemy
Last verified: 2026-09-28

A typed Python API for when your data work, ML models, or team already live in Python.

## When to use it
- The backend sits next to data pipelines or ML models written in Python
- You want request validation and API docs generated from type hints
- The frontend is separate — a SPA, a mobile app, or another service

## How the pieces fit
FastAPI turns Python type hints into request validation and an OpenAPI schema, so interactive docs and typed client generators come for free. Pydantic models describe what the API accepts; SQLAlchemy models describe the tables; Alembic migrates them. Async database drivers let one process wait on Postgres and outbound calls at the same time. Because the contract is plain HTTP plus OpenAPI, any frontend can consume it, and ML code imports straight into request handlers without a second service.

## The tech and its role
- [FastAPI](https://wwadd.dev/tools/fastapi): HTTP framework, validation, OpenAPI docs
- [Pydantic](https://wwadd.dev/tools/pydantic): Request and response schemas
- [SQLAlchemy](https://wwadd.dev/tools/sqlalchemy): ORM and query builder
- [Alembic](https://wwadd.dev/tools/alembic): Schema migrations
- [Postgres](https://wwadd.dev/tools/postgresql): Primary datastore
- [Python](https://wwadd.dev/tools/python): Shared language with data and ML code

## Real-world examples
- Polar: Open-source billing platform whose public server code runs FastAPI with SQLAlchemy on Postgres. (source: https://github.com/polarsource/polar)
- Dispatch (Netflix): Netflix's open-source incident-management tool: a FastAPI backend with SQLAlchemy on Postgres. (source: https://github.com/Netflix/dispatch)

## Skip if
Skip if the whole team writes TypeScript and there's no Python-specific work — a TypeScript backend keeps one language and shares types with the frontend.

## Testing and shipping
- [Change database schemas in compatible stages](https://wwadd.dev/moves/testing-shipping/compatible-schema-migrations)
- [Prove a backup can restore](https://wwadd.dev/moves/testing-shipping/verify-backup-restore)

