Fastro · The Benav Labs FastAPI Boilerplate
Batteries-included FastAPI starter - vertical-slice modules, swappable infrastructure, plugin-ready CLI.
Docs · DeepWiki · Discord
The free, open-source FastAPI foundation. Building a SaaS - AI or not? FastroAI adds payments, entitlements, email & a frontend (plus AI) on top - compare ↓
Features
- Nine removable features - accounts, rbac, tiers, tier_limits, ratelimit, api_keys, admin, cache and taskiq, each leaving with its routes, models, settings, admin views, seeders and tests (guide)
- Fully async FastAPI + SQLAlchemy 2.0
- Pydantic v2 models & validation
- Server-side sessions + CSRF via crudauth; OAuth (Google and GitHub wired); API keys
- Annotated type aliases for all FastAPI dependencies
- Rate limiter with per-tier, per-path rules
- FastCRUD for efficient CRUD & pagination
- SQLAdmin-based admin panel (optional, env-toggled)
- Taskiq workers (Redis or RabbitMQ broker)
- Redis or Memcached caching (
@cache decorator + provider API)
- Plugin-ready
bp CLI - generate compose files, audit env, mount third-party command/feature plugins
- Docker Compose for local / prod / nginx-fronted (generated by the CLI)
- Runs on any Postgres - the bundled container, or serverless via Neon (guide)
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
- A foundation that grows - vertical-slice modules + a plugin-aware CLI for code generators
- Docs over boilerplate in this README - depth lives on the docs site
Not a fit if you need a monorepo microservices scaffold - see the docs for pointers.
What you get:
Fastro vs FastroAI
This boilerplate - Fastro - is the free, open-source foundation: everything you need for a production FastAPI backend. FastroAI is the paid template built on the same foundation for shipping a complete SaaS - Stripe billing (subscriptions, credits, discounts), entitlements, transactional email, and a frontend, all wired together. Building an AI product? The PydanticAI agent layer is included too - but every paid feature fits a regular SaaS just as well.
|
Fastro (this repo · free) |
FastroAI (paid) |
| FastAPI + SQLAlchemy 2.0, Pydantic v2 |
✓ |
✓ |
| Auth - sessions, OAuth, API keys |
✓ |
✓ + JWT |
| FastCRUD · SQLAdmin · Alembic |
✓ |
✓ |
| Caching · rate limiting · Taskiq jobs |
✓ |
✓ |
| Docker (local / prod / nginx) |
✓ |
✓ |
bp CLI - scaffolding, env audit, plugins |
✓ |
|
| Payments - Stripe: subscriptions, credits, discounts, webhooks |
|
✓ |
| Entitlements - feature gating by plan/tier |
|
✓ |
| Transactional email & notifications |
|
✓ |
| Frontend - Astro landing / marketing site |
|
✓ |
| Observability - Logfire tracing & metrics |
|
✓ |
| AI agents - PydanticAI: memory, tools, usage tracking |
|
✓ |
| Support |
Community · Discord |
Priority · lifetime updates |
Stick with Fastro if you want a clean, hackable FastAPI backend to build on.
Get FastroAI → if you're shipping a SaaS - AI or not - and want billing, entitlements, email, auth, and a frontend ready out of the box.
Repo Layout
This is a uv workspace with two members. One venv at the root covers both.
fastapi-boilerplate/
├── pyproject.toml # workspace root (uv workspace metadata)
├── backend/ # the deployable application
│ ├── src/ # interfaces/, infrastructure/, modules/
│ ├── pyproject.toml
│ └── Dockerfile # multi-stage: dev / migrate / prod
└── cli/ # `bp` - developer/operator tool (never ships in prod)
└── src/cli/
Quickstart
git clone https://github.com/<you>/FastAPI-boilerplate
cd FastAPI-boilerplate
uv sync --all-packages --all-extras # one venv at the root, both members installed
Generate a compose file for the deployment shape you want:
uv run --no-sync bp deploy generate local # hot-reload dev stack
# or: uv run --no-sync bp deploy generate prod # production single-host
# or: uv run --no-sync bp deploy generate nginx # production behind nginx
Configure your env (the CLI helps with secrets and validation):
cp backend/.env.example backend/.env
uv run --no-sync bp env gen-secret # print a fresh SECRET_KEY
uv run --no-sync bp env validate # audit .env against the production validator
Bring it up:
docker compose up --build
# → http://127.0.0.1:8000 (Swagger at /docs)
Without Docker (Postgres + Redis required locally - or skip local Postgres with Neon):
cd backend
uv run --no-sync alembic upgrade head
uv run --no-sync python -m scripts.setup_initial_data # creates the first admin user + default tier
uv run --no-sync fastapi dev src/interfaces/main.py # API
uv run --no-sync taskiq worker src.infrastructure.taskiq.worker:default_broker # in a second terminal
Full setup, env-var reference, and per-environment deployment guides live in the docs.
Common tasks
# generate a fresh production-ready compose file
uv run --no-sync bp deploy generate prod --workers 8
# audit your .env against the production security validator
uv run --no-sync bp env validate
# run Alembic migrations
cd backend && uv run --no-sync alembic revision --autogenerate -m "<msg>" && uv run --no-sync alembic upgrade head
# run tests
cd backend && uv run --no-sync pytest
# install bp as a global tool (optional)
uv tool install --editable ./cli
More examples (superuser creation, tiers, rate limits, admin usage, plugin authoring) in the docs.
Sponsors
Neon supports this project with database credits for our open-source infrastructure - thank you. Neon is serverless Postgres: compute scales to zero when idle, and you can branch a database like you branch code (handy for per-PR preview environments).
It's also a drop-in option for your own build, and free to start - the free plan is permanent rather than a trial (no credit card), with enough storage and compute for dev, staging, and small production workloads. Point DATABASE_URL at a Neon project and the local Postgres container becomes optional - no code changes:
DATABASE_URL=postgresql+asyncpg://user:password@ep-xxx-pooler.region.aws.neon.tech/neondb?ssl=require
→ Full Neon guide (connection-string conversion, pooled vs. direct endpoints, scale-to-zero pool settings). Any other managed Postgres works the same way.
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