A modern, production-ready FastAPI project template using Copier for scaffolding and UV for dependency management.
- β‘ FastAPI: Modern, fast web framework with automatic API documentation
- π Modern Python: Support for Python 3.10, 3.11, and 3.12
- π¦ UV Package Manager: Lightning-fast dependency resolution and management
- π§ Flexible Configuration: Choose only the features you need
- π Template Updates: Update existing projects when template evolves
- π³ Docker Ready: Optional Docker and Docker Compose configuration
- ποΈ Database Support: SQLite, PostgreSQL, or MySQL with async support
- π Authentication: Optional JWT-based authentication system
- β‘ Redis & Celery: Optional caching and background task processing
- π§ͺ Testing: Comprehensive test suite with pytest
- π Code Quality: Pre-configured Black, isort, Ruff, and MyPy
- π Database Migrations: Optional Alembic integration
- π Auto Documentation: Swagger UI and ReDoc included
# Install copier if you haven't already
pip install copier
# Or with UV
uv tool install copier# From GitHub (recommended)
copier copy https://github.com/yourusername/fastapi-copier-template my-awesome-api
# From local template
copier copy /path/to/fastapi-copier-template my-awesome-apicd my-awesome-api
# Install dependencies
uv sync
# Copy environment template
cp .env.example .env
# Edit .env with your settings
vim .env
# Run database migrations (if database is enabled)
uv run alembic upgrade head
# Start the development server
uv run fastapi devYour API will be available at:
- API: http://localhost:8000
- Interactive Docs: http://localhost:8000/docs
- Alternative Docs: http://localhost:8000/redoc
The template will prompt you for the following options:
| Option | Description | Default |
|---|---|---|
project_name |
Human-readable project name | "My FastAPI Project" |
project_slug |
Python package name (auto-generated) | - |
description |
Brief project description | - |
author_name |
Your full name | "Your Name" |
author_email |
Your email address | "your.email@example.com" |
python_version |
Python version (3.10, 3.11, 3.12) | "3.12" |
include_database |
Database type (none, sqlite, postgresql, mysql) | "none" |
include_auth |
JWT authentication | false |
include_async_database |
Async database operations | auto |
include_alembic |
Database migrations | auto |
include_tests |
Test suite with pytest | true |
include_docker |
Docker configuration | true |
include_redis |
Redis for caching/sessions | false |
include_celery |
Background tasks with Celery | false |
api_prefix |
API route prefix | "/api/v1" |
cors_origins |
CORS allowed origins | "http://localhost:3000,http://localhost:8080" |
my-awesome-api/
βββ π pyproject.toml # Project configuration & dependencies
βββ π README.md # Project-specific documentation
βββ π .env.example # Environment variables template
βββ π .gitignore # Git ignore rules
βββ π³ Dockerfile # Docker configuration (optional)
βββ π³ docker-compose.yml # Docker Compose (optional)
βββ π app/
β βββ π __init__.py
β βββ π main.py # FastAPI application entry point
β βββ π api/
β β βββ π __init__.py
β β βββ π routes.py # API route definitions
β βββ π core/
β β βββ π __init__.py
β β βββ π config.py # App configuration
β β βββ π database.py # Database setup (optional)
β β βββ π security.py # Authentication (optional)
β βββ π models/ # SQLAlchemy models (optional)
β βββ π schemas/ # Pydantic schemas
β βββ π crud/ # Database operations (optional)
βββ π tests/ # Test suite (optional)
βββ π __init__.py
βββ π conftest.py
βββ π test_main.pyOne of Copier's best features is the ability to update existing projects when the template evolves:
# Update project with latest template changes
cd my-existing-project
copier update
# Reconfigure project with different options
copier reconfigureIf you enabled Docker support:
# Development with Docker Compose
docker-compose up --build
# Production build
docker build -t my-awesome-api .
docker run -p 8000:8000 my-awesome-api# Format code
uv run black .
uv run isort .
# Lint code
uv run ruff check .
uv run mypy .
# Fix linting issues
uv run ruff check --fix .# Run all tests
uv run pytest
# Run with coverage
uv run pytest --cov=app --cov-report=html
# Run specific test file
uv run pytest tests/test_main.py -v# Create new migration
uv run alembic revision --autogenerate -m "Add new table"
# Apply migrations
uv run alembic upgrade head
# Rollback migration
uv run alembic downgrade -1- Fork this template repository
- Modify the template files in
{{ project_slug }}/ - Update
copier.ymlwith new configuration options - Test your changes with
copier copy . /tmp/test-project - Submit a pull request
# Test template locally
copier copy . /tmp/test-project --data project_name="Test Project"
# Answer prompts programmatically
copier copy . /tmp/test-project --data-file test-data.ymlContributions are welcome! Here's how you can help:
- π Report Issues: Found a bug? Open an issue with details
- π‘ Feature Requests: Have an idea? Let's discuss it
- π§ Pull Requests:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Test thoroughly
- Submit a pull request
# Clone the template repository
git clone https://github.com/yourusername/fastapi-copier-template
cd fastapi-copier-template
# Test the template
copier copy . /tmp/test-project --data project_name="Test Project"
cd /tmp/test-project
uv sync
uv run uvicorn app.main:app --reload- Support for more databases (MongoDB, etc.)
- WebSocket support
- GraphQL integration
- Kubernetes deployment templates
- CI/CD pipeline templates
- More authentication providers (OAuth, SAML)
- API versioning strategies
- Monitoring and observability setup
- FastAPI - The amazing web framework
- Copier - Template engine that makes this possible
- UV - Fast Python package management
- Pydantic - Data validation using Python type hints
This project is licensed under the MIT License - see the LICENSE file for details.
If this template helped you build something awesome, please give it a β on GitHub!
Happy coding! π
Built with β€οΈ for the Python community