A modern, production-ready template for building robust APIs with FastAPI, SQLModel, and Docker. This project provides a clean, scalable structure, best practices, and batteries-included features to help you start your next Python web project quickly and efficiently.
- Modern FastAPI Stack: Async support, type hints, and modular design.
- SQLModel ORM: Simple, powerful database models and queries.
- User Authentication: Secure password hashing, user CRUD, and authentication utilities.
- Environment-based Configuration: Managed via
.envand Pydantic settings. - API Versioning: Easily extendable versioned endpoints.
- Extensible CRUD: Generic CRUD base for rapid model development.
- Health Check Endpoint: Built-in
/healthroute for monitoring. - Testing Ready: Structure supports adding tests easily.
- Docker-Ready: Multi-stage, production-optimized Dockerfile.
- MIT Licensed: Free for personal and commercial use.
simple-api/
├── app/
│ ├── api/ # API routes, versioning, dependencies
│ │ └── v1/
│ │ ├── api.py
│ │ └── endpoints/
│ │ └── users.py
│ ├── core/ # Settings, security utilities
│ ├── crud/ # Base and user CRUD logic
│ ├── db/ # Database engine, session, init
│ ├── models/ # SQLModel database models
│ ├── schemas/ # Pydantic schemas for requests/responses
│ ├── utils/ # Helper utilities
│ └── main.py # FastAPI application entrypoint
├── tests/ # (Add your tests here)
├── .env.example # Example environment variables
├── Dockerfile # Multi-stage, production-ready Dockerfile
├── pyproject.toml # Project metadata and dependencies
├── uv.lock # Dependency lock file
├── LICENSE # MIT License
└── README.md # Project documentation
git clone https://github.com/yeferson59/fastapi-template.git
cd fastapi-templatepython -m venv .venv
source .venv/bin/activateThis template uses uv for fast dependency management, but you can use pip as well.
# With uv (recommended)
uv sync --dev
# Or with pip (if you prefer)
pip install -U pip
pip install .[dev]Copy .env.example to .env and adjust settings as needed:
cp .env.example .env# With uv development (recommended)
uv run fastapi dev app/main.py
# Or with uvicorn directly
# uv run uvicorn app.main:app --reload
# With uv for production
uv run fastapi run app/main.pyThe API will be available at http://localhost:8000.
Visit http://localhost:8000/docs for the interactive Swagger UI.
- Lint:
ruff check . --fix - Format:
black . - Sort imports:
isort .
This template includes a .pre-commit-config.yaml for automatic linting and formatting before every commit.
To enable:
pre-commit installTests are located in the tests/ directory and use pytest and FastAPI's TestClient.
pytestYou can also run all pre-commit hooks manually:
pre-commit run --all-files- Health Check:
GET /health - User Endpoints:
GET /api/v1/users/— List usersPOST /api/v1/users/— Create userGET /api/v1/users/search/{search_term}— Search users by name or emailGET /api/v1/users/{user_id}— Get user by IDPUT /api/v1/users/{user_id}— Update userDELETE /api/v1/users/{user_id}— Delete user
This template includes a GitHub Actions workflow for CI/CD:
- Runs on every push and pull request to
mainormaster - Installs dependencies (including dev tools)
- Runs linting (ruff), formatting checks (black), import sorting (isort)
- Runs all tests with pytest
You can find the workflow at .github/workflows/ci.yml.
Important: The CI/CD and all development commands assume you have installed the dev dependencies group (
.[dev]).
All configuration is managed via environment variables. See .env.example for available options:
PORT=8000
ENVIRONMENT=development
DATABASE_URL=sqlite:///test.sqlite3
SECRET_KEY=your-secret-key-here
API_VERSION=v1
- Default: SQLite (file-based, easy for development)
- ORM: SQLModel (built on SQLAlchemy)
- Initialization: Tables are auto-created on startup. You can add seed logic in
app/db/init_db.py.
This template includes a multi-stage, production-ready Dockerfile.
docker build -t fastapi-template .docker run --env-file .env -p 8000:8000 fastapi-templateThe application will be available at http://localhost:8000.
You can deploy this template to any cloud provider or platform that supports Docker containers, such as:
- AWS ECS / Fargate
- Google Cloud Run
- Azure Container Apps
- DigitalOcean App Platform
- Heroku (with Docker support)
- Any VPS or server with Docker installed
Production tips:
- Set secure values in your
.env - Use a production-grade ASGI server (e.g., Uvicorn with Gunicorn)
- Configure HTTPS and a reverse proxy (e.g., Nginx, Traefik)
- Set up persistent storage for your database
- Add your own models in
app/models/and schemas inapp/schemas/ - Implement new CRUD logic in
app/crud/ - Define new API endpoints in
app/api/v1/endpoints/ - Adjust settings in
.envandapp/core/config.py
This project is licensed under the MIT License. See LICENSE for details.
Start your next FastAPI project with a solid foundation!