A production-ready FastAPI starter template with modern Python best practices.
- FastAPI: Modern, fast web framework for building APIs
- SQLModel: SQL databases with Python objects (ORM)
- Alembic: Database migrations made easy
- uv: Ultra-fast Python package installer and resolver
- Ruff: Lightning-fast Python linter and formatter
- mypy: Static type checking
- pytest: Comprehensive testing with async support and coverage
- structlog: Structured logging for better observability
- pydantic-settings: Type-safe configuration management
- Docker: Multi-stage builds for production deployment
- just: Command runner for common tasks
- Pre-commit: Git hooks for code quality
starter-fastapi/
├── src/
│ └── starter_fastapi/
│ ├── api/ # API layer
│ │ └── v1/ # API version 1
│ │ ├── endpoints/ # API endpoints
│ │ └── router.py # Version router
│ ├── core/ # Core functionality
│ │ ├── config.py # Configuration
│ │ ├── db.py # Database configuration
│ │ ├── logging.py # Logging setup
│ │ └── exceptions.py # Custom exceptions
│ ├── migrations/ # Database migrations
│ │ └── versions/ # Migration scripts
│ ├── models/ # SQLModel models
│ ├── services/ # Business logic
│ └── main.py # Application entry point
├── tests/ # Test suite
├── .github/workflows/ # CI/CD workflows
├── Dockerfile # Docker configuration
├── docker-compose.yml # Docker Compose setup
├── pyproject.toml # Project configuration
├── alembic.ini # Alembic configuration
└── justfile # Task runner commands
- Install dependencies:
uv sync --all-extrasOr with just:
just install-dev- Copy the example environment file:
cp .env.example .env-
Update the
.envfile with your configuration. -
Apply database migrations:
uv run alembic upgrade headDevelopment mode with auto-reload:
just devOr directly with uv:
uv run uvicorn starter_fastapi.main:app --reloadThe API will be available at:
- API: http://localhost:8000
- Interactive docs (Swagger): http://localhost:8000/docs
- Alternative docs (ReDoc): http://localhost:8000/redoc
just --list # Show all available commands
just install-dev # Install all dependencies
just dev # Run development server
just test # Run tests
just test-cov # Run tests with coverage
just lint # Run linter
just format # Format code
just lint-fix # Fix linting issues and format
just type-check # Run type checking
just check # Run all checks (lint, type-check, test)
just clean # Clean up generated filesThis project uses several tools to maintain code quality:
- Ruff: For linting and formatting
- mypy: For static type checking
- pytest: For testing
Run all checks:
just checkRun tests:
just testRun tests with coverage:
just test-covCoverage reports are generated in htmlcov/index.html.
Install pre-commit hooks:
just pre-commit-installRun pre-commit manually:
just pre-commit-runSee DEPLOYMENT.md for detailed deployment instructions to Google Cloud Run.
Build the Docker image:
just docker-buildRun the container:
just docker-runStart services:
just docker-upStop services:
just docker-downOnce the application is running, visit:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
- OpenAPI JSON: http://localhost:8000/openapi.json
Configuration is managed through environment variables using pydantic-settings. See .env.example for all available options.
Key configuration areas:
- Application: Name, version, description, environment
- Server: Host, port, reload settings
- CORS: Allowed origins, credentials, methods, headers
- Logging: Level, format
- API: Versioning prefix
core/config.py: Application settings using pydantic-settingscore/logging.py: Structured logging configuration with structlogcore/exceptions.py: Custom exception handlers
api/v1/: API version 1 implementationapi/v1/endpoints/: Individual endpoint modulesapi/v1/router.py: Main router for v1
SQLModel models for database tables and Pydantic models for request/response validation.
Business logic layer, separated from API endpoints for better testability and reusability.
- Create a new branch for your feature
- Make your changes
- Run
just checkto ensure code quality - Submit a pull request
This project is licensed under the MIT License.
Future enhancements to consider:
- Database integration (SQLModel, SQLite, Alembic)
- Authentication & authorization (JWT, OAuth2)
- Caching (Redis)
- Background tasks (Celery, ARQ)
- Rate limiting
- API versioning middleware
- Prometheus metrics
- OpenTelemetry tracing
- GraphQL support
- WebSocket support