Skip to content

Getting Started

Welcome to the FastAPI Boilerplate! This guide will have you up and running in just a few minutes.

Quick Start (5 minutes)

Pick whichever workflow fits you:

Prerequisites

  • uv (0.4+)
  • PostgreSQL and Redis running locally (or use the Docker tab)

1. Get the Template

  1. Click "Use this template" on the GitHub repository
  2. Create a new repository with your project name
  3. Clone your new repository and cd into the backend:
git clone https://github.com/yourusername/your-project-name
cd your-project-name/backend

2. Install Dependencies

uv sync --extra dev

3. Environment Setup

cp .env.example .env
# then edit .env to set your database creds, SECRET_KEY, etc.

SECRET_KEY

Generate a secure key with python -c "import secrets; print(secrets.token_urlsafe(64))" and replace the default value in .env.

4. Run the Server

uv run fastapi dev src/interfaces/main.py

Prerequisites

1. Get the Template

git clone https://github.com/yourusername/your-project-name
cd your-project-name/backend

2. Environment Setup

cp .env.example .env
# then edit .env to set your DB password, SECRET_KEY, etc.

3. Start Everything

docker compose up

This brings up:

  • FastAPI app on port 8000
  • PostgreSQL database
  • Redis for cache, rate limiting, and sessions

Verify It's Running

Visit:

You're Ready!

You now have a working FastAPI app with:

  • REST API with automatic OpenAPI docs
  • PostgreSQL database with Alembic migrations
  • Redis-backed cache and rate limiting
  • Session-based authentication with optional OAuth (Google, GitHub)
  • API keys with per-key permissions
  • SQLAdmin admin interface at /admin
  • Async background task support via Taskiq

Test Your API

1. Health Check

curl http://localhost:8000/health

2. Create a User

curl -X POST "http://localhost:8000/api/v1/users/" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "John Doe",
    "username": "johndoe",
    "email": "john@example.com",
    "password": "securepassword"
  }'
curl -X POST "http://localhost:8000/api/v1/auth/login" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "username=johndoe&password=securepassword" \
  -c cookies.txt

The response sets an HTTP-only session cookie and returns a CSRF token. Use -b cookies.txt on subsequent requests to send the session along.

4. Get the Current User

curl http://localhost:8000/api/v1/users/me -b cookies.txt

Next Steps

Essential Reading

Development & Deployment

Alternative Setup Methods

Need Help?


Ready to dive deeper? Continue with the installation guide or jump to the user guide.