Skip to content

benavlabs/FastAPI-boilerplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Benav Labs FastAPI boilerplate

Batteries-included FastAPI starter with production-ready defaults, optional modules, and clear docs.

Purple Rocket with FastAPI Logo as its window.

๐Ÿ“š Docs ยท ๐Ÿง  DeepWiki ยท ๐Ÿ’ฌ Discord

FastAPI PostgreSQL Redis DeepWiki

Features

  • โšก๏ธ Fully async FastAPI + SQLAlchemy 2.0
  • ๐Ÿงฑ Pydantic v2 models & validation
  • ๐Ÿ” JWT auth (access + refresh), cookies for refresh
  • ๐Ÿ‘ฎ Rate limiter + tiers (free/pro/etc.)
  • ๐Ÿงฐ FastCRUD for efficient CRUD & pagination
  • ๐Ÿง‘โ€๐Ÿ’ผ CRUDAdmin: minimal admin panel (optional)
  • ๐Ÿšฆ ARQ background jobs (Redis)
  • ๐ŸงŠ Redis caching (server + client-side headers)
  • ๐Ÿณ One-command Docker Compose
  • ๐Ÿš€ NGINX & Gunicorn recipes for prod

Why and When to use it

Perfect if you want:

  • A pragmatic starter with auth, CRUD, jobs, caching and rate-limits
  • Sensible defaults with the freedom to opt-out of modules
  • Docs over boilerplate in README - depth lives in the site

Not a fit if you need a monorepo microservices scaffold - see the docs for pointers.

What you get:

This is what we've been using in production apps. Several applications running in production started from this boilerplate as their foundation - from SaaS platforms to internal tools. It's proven, stable technology that works together reliably. Use this as the foundation for whatever you want to build on top.

Building an AI SaaS? Skip even more setup with FastroAI - our production-ready template with AI integration, payments, and frontend included.

TL;DR - Quickstart

Use the template on GitHub, create your repo, then:

git clone https://github.com/<you>/FastAPI-boilerplate
cd FastAPI-boilerplate

Quick setup: Run the interactive setup script to choose your deployment configuration:

./setup.py

Or directly specify the deployment type: ./setup.py local, ./setup.py staging, or ./setup.py production.

The script copies the right files for your deployment scenario. Here's what each option sets up:

Option 1: Local development with Uvicorn

Best for: Development and testing

Copies:

  • scripts/local_with_uvicorn/Dockerfile โ†’ Dockerfile
  • scripts/local_with_uvicorn/docker-compose.yml โ†’ docker-compose.yml
  • scripts/local_with_uvicorn/.env.example โ†’ src/.env

Sets up Uvicorn with auto-reload enabled. The example environment values work fine for development.

Manual setup: ./setup.py local or copy the files above manually.

Option 2: Staging with Gunicorn managing Uvicorn workers

Best for: Staging environments and load testing

Copies:

  • scripts/gunicorn_managing_uvicorn_workers/Dockerfile โ†’ Dockerfile
  • scripts/gunicorn_managing_uvicorn_workers/docker-compose.yml โ†’ docker-compose.yml
  • scripts/gunicorn_managing_uvicorn_workers/.env.example โ†’ src/.env

Sets up Gunicorn managing multiple Uvicorn workers for production-like performance testing.

Warning

Change SECRET_KEY and passwords in the .env file for staging environments.

Manual setup: ./setup.py staging or copy the files above manually.

Option 3: Production with NGINX

Best for: Production deployments

Copies:

  • scripts/production_with_nginx/Dockerfile โ†’ Dockerfile
  • scripts/production_with_nginx/docker-compose.yml โ†’ docker-compose.yml
  • scripts/production_with_nginx/.env.example โ†’ src/.env

Sets up NGINX as reverse proxy with Gunicorn + Uvicorn workers for production.

Caution

You MUST change SECRET_KEY, all passwords, and sensitive values in the .env file before deploying!

Manual setup: ./setup.py production or copy the files above manually.


Start your application:

docker compose up

Access your app:

Next steps

Create your first admin user:

docker compose run --rm create_superuser

Run database migrations (if you add models):

cd src && uv run alembic revision --autogenerate && uv run alembic upgrade head

Test background jobs:

curl -X POST 'http://127.0.0.1:8000/api/v1/tasks/task?message=hello'

Or run locally without Docker:

uv sync && uv run uvicorn src.app.main:app --reload

Full setup (from-scratch, .env examples, PostgreSQL & Redis, gunicorn, nginx) lives in the docs.

Configuration (minimal)

Create src/.env and set app, database, JWT, and environment settings. See the docs for a copy-pasteable example and production guidance.

https://benavlabs.github.io/FastAPI-boilerplate/getting-started/configuration/

  • ENVIRONMENT=local|staging|production controls API docs exposure
  • Set ADMIN_* to enable the first admin user

Common tasks

# run locally with reload (without Docker)
uv sync && uv run uvicorn src.app.main:app --reload

# run Alembic migrations
cd src && uv run alembic revision --autogenerate && uv run alembic upgrade head

# enqueue a background job (example endpoint)
curl -X POST 'http://127.0.0.1:8000/api/v1/tasks/task?message=hello'

More examples (superuser creation, tiers, rate limits, admin usage) in the docs.

Contributing

Read contributing.

References

This project was inspired by a few projects, it's based on them with things changed to the way I like (and pydantic, sqlalchemy updated)

License

MIT

Contact

Benav Labs โ€“ benav.io, discord server


Powered by Benav Labs - benav.io