Installation Guide¶
This guide covers different ways to install and set up the FastAPI Boilerplate depending on your needs and environment.
System Requirements¶
Before you begin, ensure your system meets these requirements:
- Python: 3.11 or higher
- Operating System: Linux, macOS, or Windows (with WSL2 recommended)
- Memory: Minimum 4GB RAM (8GB recommended)
- Disk Space: At least 2GB free space
Method 1: Docker Compose (Recommended)¶
Docker Compose is the easiest way to get started. It handles all dependencies and services automatically.
Prerequisites¶
Install these tools on your system:
- Docker (version 20.10+)
- Docker Compose (version 1.29+)
Installation Steps¶
- Get the template:
- Quick setup (recommended):
# Interactive setup - choose your deployment type ./setup.py # Or specify directly: ./setup.py local, ./setup.py staging, ./setup.py production This automatically copies the correct Dockerfile, docker-compose.yml, and .env files for your chosen deployment scenario.
- Start services:
Manual Setup Alternative¶
If you prefer to set up manually:
# Copy configuration files for local development cp scripts/local_with_uvicorn/Dockerfile Dockerfile cp scripts/local_with_uvicorn/docker-compose.yml docker-compose.yml cp scripts/local_with_uvicorn/.env.example src/.env # Edit src/.env with your configuration if needed - Verify installation:
What Gets Installed¶
Docker Compose sets up these services:
- Web server (FastAPI + Uvicorn) on port 8000
- PostgreSQL database on port 5432 (internal)
- Redis server on port 6379 (internal)
- ARQ Worker for background tasks
- NGINX (optional, for production)
Method 2: Manual Installation¶
For more control or development purposes, you can install everything manually.
Prerequisites¶
- Install Python 3.11+:
# On Ubuntu/Debian sudo apt update sudo apt install python3.11 python3.11-pip # On macOS (with Homebrew) brew install python@3.11 # On Windows # Download from python.org - Install uv (Python package manager):
- Install PostgreSQL:
# On Ubuntu/Debian sudo apt install postgresql postgresql-contrib # On macOS brew install postgresql # On Windows # Download from postgresql.org - Install Redis:
# On Ubuntu/Debian sudo apt install redis-server # On macOS brew install redis # On Windows # Download from redis.io Installation Steps¶
- Clone the repository:
- Install Python dependencies:
- Set up environment variables:
- Set up PostgreSQL:
# Create database and user sudo -u postgres psql CREATE DATABASE myapp; CREATE USER myuser WITH PASSWORD 'mypassword'; GRANT ALL PRIVILEGES ON DATABASE myapp TO myuser; \q - Run database migrations:
- Create admin user:
- Start the application:
- Start the worker (in another terminal):
Method 3: Development Setup¶
For contributors and advanced users who want to modify the boilerplate.
Additional Prerequisites¶
- Git for version control
Installation Steps¶
- Fork and clone:
# Fork the repository on GitHub first git clone https://github.com/yourusername/fastapi-boilerplate cd fastapi-boilerplate - Install development dependencies:
- Set up pre-commit hooks:
- Set up development environment:
- Run tests to verify setup:
Docker Services Breakdown¶
Understanding what each Docker service does:
Web Service¶
- Runs the FastAPI application
- Handles HTTP requests
- Auto-reloads on code changes (development)
Database Service¶
db: image: postgres:13 environment: POSTGRES_DB: myapp POSTGRES_USER: postgres POSTGRES_PASSWORD: changethis - PostgreSQL database server
- Persistent data storage
- Automatic initialization
Redis Service¶
- In-memory data store
- Used for caching and job queues
- Persistent storage with AOF
Worker Service¶
- Background task processor
- Handles async jobs
- Scales independently
Configuration¶
Environment Variables¶
The application uses environment variables for configuration. Key variables:
# Database POSTGRES_USER=postgres POSTGRES_PASSWORD=changethis POSTGRES_SERVER=localhost # or "db" for Docker POSTGRES_PORT=5432 POSTGRES_DB=myapp # Redis REDIS_CACHE_HOST=localhost # or "redis" for Docker REDIS_CACHE_PORT=6379 # Security SECRET_KEY=your-secret-key-here ALGORITHM=HS256 ACCESS_TOKEN_EXPIRE_MINUTES=30 Database Connection¶
For manual installation, update your database settings:
# Local PostgreSQL POSTGRES_SERVER=localhost POSTGRES_PORT=5432 # Docker PostgreSQL POSTGRES_SERVER=db POSTGRES_PORT=5432 Verification¶
After installation, verify everything works:
- API Documentation: http://localhost:8000/docs
- Health Check: http://localhost:8000/api/v1/health
- Ready Check: http://localhost:8000/api/v1/ready
- Database Connection: Check logs for successful connection
- Redis Connection: Test caching functionality
- Background Tasks: Submit a test job
Troubleshooting¶
Common Issues¶
Port Already in Use:
Database Connection Error:
# Check PostgreSQL status sudo systemctl status postgresql # Restart PostgreSQL sudo systemctl restart postgresql Redis Connection Error:
Permission Errors:
Docker Issues¶
Clean Reset:
# Stop all containers docker compose down # Remove volumes (⚠️ deletes data) docker compose down -v # Rebuild images docker compose build --no-cache # Start fresh docker compose up Next Steps¶
After successful installation:
- Configuration Guide - Set up your environment
- First Run - Test your installation
- Project Structure - Understand the codebase
Need Help?¶
If you encounter issues:
- Check the GitHub Issues for common problems
- Search existing issues
- Create a new issue with details