iam-abbas /
FastAPI-Production-Boilerplate
A scalable and production ready boilerplate for FastAPI
83/100 healthLoading repository data…
mantle-bearer / repository
A production-ready FastAPI boilerplate with modern Python development practices, async SQLAlchemy 2.0, Alembic migrations, JWT authentication, and comprehensive tooling.
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
A production-ready FastAPI boilerplate with modern Python development practices, async SQLAlchemy 2.0, Alembic migrations, JWT authentication, and comprehensive tooling.
git clone <your-repo-url>
cd fastapi-template
Copy and configure your environment variables:
copy .env.sample .env
Edit .env with your actual configuration values.
# Install UV if you haven't
pip install uv
# Install dependencies
uv sync
# Run development server
uv run fastapi dev main.py
# Create virtual environment
python -m venv venv
venv\Scripts\activate # Windows
# source venv/bin/activate # Linux/Mac
# Install dependencies
pip install -r requirements.txt
# Run development server
fastapi dev main.py
# Development with hot reload
docker-compose up
# Or build and run manually
docker build -t fastapi-template .
docker run -p 8000:8000 fastapi-template
# Run migrations
alembic upgrade head
# Create new migration (after model changes)
alembic revision --autogenerate -m "description"
fastapi-template/
├── api/ # Main API package
│ ├── core/ # Core functionality
│ │ ├── dependencies/ # Dependency injection
│ │ └── responses.py # Response constants
│ ├── db/ # Database configuration
│ │ ├── database.py # SQLAlchemy setup
│ │ └── enum.py # Database enums
│ ├── templates/ # Email templates
│ ├── utils/ # Utilities
│ │ ├── cookies.py # OAuth2 with cookies
│ │ ├── response.py # Response helpers
│ │ ├── security.py # JWT utilities
│ │ └── settings.py # Configuration
│ └── v1/ # API version 1
│ ├── models/ # SQLAlchemy models
│ ├── routes/ # API endpoints
│ ├── schemas/ # Pydantic schemas
│ └── services/ # Business logic
├── alembic/ # Database migrations
├── tests/ # Test suite
├── main.py # FastAPI application
├── requirements.txt # Python dependencies
├── pyproject.toml # Project configuration
├── docker-compose.yml # Docker development setup
├── Dockerfile # Container configuration
└── .env.sample # Environment template
# Development server with hot reload
fastapi dev main.py
# Production server
fastapi run main.py
# Custom host/port
fastapi dev main.py --host 0.0.0.0 --port 8080
# Format code
black .
isort .
# Lint code
flake8 .
mypy .
# Run tests
pytest
pytest -v --cov=api # With coverage
# Create migration
alembic revision --autogenerate -m "add user table"
# Apply migrations
alembic upgrade head
# Rollback migration
alembic downgrade -1
# Check current version
alembic current
Once running, visit:
The template includes JWT authentication with cookie support:
# Token in Authorization header
Authorization: Bearer <token>
# Or in cookie
Cookie: access_token=Bearer <token>
Built-in email system with Jinja2 templates:
await send_mail(
recipient="user@example.com",
template_name="welcome.html",
subject="Welcome!",
context={"name": "John"}
)
docker-compose up
# Build production image
docker build --target production -t fastapi-template:prod .
# Run with environment variables
docker run -d \
-p 8000:8000 \
-e DB_HOST=your-db-host \
-e JWT_SECRET_KEY=your-secret \
fastapi-template:prod
Key environment variables:
| Variable | Description | Default |
|---|---|---|
APP_NAME | Application name | "FastAPI Template" |
ENVIRONMENT | Environment (development/production) | "development" |
DB_HOST | Database host | "localhost" |
DB_TYPE | Database type (postgresql/sqlite) | "postgresql" |
JWT_SECRET_KEY | JWT secret key | Required |
FRONTEND_URL | Frontend URL for CORS | "" |
See .env.sample for complete configuration options.
# Run all tests
pytest
# Run with coverage
pytest --cov=api --cov-report=html
# Run specific test file
pytest tests/test_users.py
# Run with verbose output
pytest -v
# api/v1/models/your_model.py
from api.v1.models.base_mdel import BaseTableModel
from sqlalchemy import Column, String
class YourModel(BaseTableModel):
__tablename__ = "your_table"
name = Column(String, nullable=False)
# Import in api/v1/models/__init__.py
from .your_model import YourModel
# Generate migration
alembic revision --autogenerate -m "add your_model"
alembic upgrade head
# api/v1/routes/your_routes.py
from fastapi import APIRouter
from api.utils.response import success_response
router = APIRouter()
@router.get("/")
async def list_items():
return success_response(
status_code=200,
message="Items retrieved successfully",
data={"items": []}
)
# api/v1/routes/__init__.py
from .your_routes import router as your_router
api_router.include_router(your_router, prefix="/items", tags=["Items"])
git checkout -b feature/amazing-featuregit commit -m 'Add amazing feature'git push origin feature/amazing-featureThis project is licensed under the MIT License - see the LICENSE file for details.
Happy coding! 🎉
Selected from shared topics, language and repository description—not editorial ratings.
iam-abbas /
A scalable and production ready boilerplate for FastAPI
83/100 healthJiayuXu0 /
A production-ready FastAPI backend template with clean architecture. 一个功能完整、架构清晰的企业级FastAPI后端模板,专为团队开发设计,开箱即用。
88/100 healthTobi-De /
Cookiecutter fastapi is a framework for jumpstarting production-ready fastapi projects quickly.
72/100 healthlbedner /
A production-ready FastAPI platform with modular components and a built-in control plane.
72/100 healthFastAPI-MEA /
A production-ready FastAPI template with Redis, Docker and PostgreSQL
62/100 healthakhil2308 /
🚀 Production-grade FastAPI template • JWT auth • Rate limiting • Async PostgreSQL & Redis • OpenTelemetry observability (Prometheus, Grafana, Tempo) • Alembic • Docker • Gunicorn + Uvicorn • Async Ready • RFC-Compliant API Responses • Enterprise Security Patterns
74/100 health