Minimal starter template for a CRUD API with FastAPI + SQLAlchemy + PostgreSQL.
- FastAPI app with CORS enabled
- SQLAlchemy ORM integration
- Postgres-ready configuration via
DATABASE_URL - CRUD endpoints for
posts - Pytest suite (DB mocked for local test runs)
- Docker + Docker Compose local setup
- Python 3.10+
pip- PostgreSQL (only needed when running app without Docker)
- Create and activate venv:
python3 -m venv .venv
source .venv/bin/activate- Install dependencies:
pip install -r requirements.txt- Add env vars:
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/fastapi_template- Run API:
uvicorn main:app --reloadWhen the server is running:
- Swagger UI: http://127.0.0.1:8000/docs
- ReDoc: http://127.0.0.1:8000/redoc
- OpenAPI JSON: http://127.0.0.1:8000/openapi.json
pytestblack .- Create
.env:
cp .env.example .env- Build and start:
docker compose up --build- Access:
- API: http://127.0.0.1:8000
- Swagger: http://127.0.0.1:8000/docs
- ReDoc: http://127.0.0.1:8000/redoc
DATABASE_URL is passed to the API container from docker-compose.yml and can be overridden via .env.