A minimal FastAPI template using SQLAlchemy 2.0, Pydantic v2, Alembic, and GitHub Actions.
- Requirements: Python 3.12+, pipenv, PostgreSQL
- Install deps:
pipenv sync --dev- Environment:
cp .env.example .env
# Edit .env to point to your DB- Migrate DB:
pipenv run alembic upgrade head- Run API:
pipenv run uvicorn main:app --reload --host 0.0.0.0 --port 8000Server: http://localhost:8000
- API base:
http://localhost:8000/api/ - Docs:
http://localhost:8000/docs
Note: routes use trailing slashes; /api/v1/users will 307 -> /api/v1/users/.
# List users
curl http://localhost:8000/api/v1/users/
# Create a user
curl -X POST http://localhost:8000/api/v1/users/ \
-H "Content-Type: application/json" \
-d '{"name":"John"}'docker compose -f docker/docker-compose-local.yml up --build
# API: http://localhost:3000/api/pipenv run pytest -v
pipenv run black --check .
pipenv run isort --check-only .- GitHub Actions: lockfile-enforced installs (pipenv sync), Postgres service, Alembic migrations, tests, lint, Docker build.
- SQLAlchemy 2.0 patterns:
DeclarativeBase,Mapped[...],mapped_column,select()+scalars() - Pydantic v2 patterns:
field_validator,ConfigDict(from_attributes=True),pydantic-settingsfor config