Skip to main content

Production FastAPI starter toolkit with Redis, SQLAlchemy, JWT Auth, and CLI scaffolding

Project description

🛠️ BoostAPI

Production-ready FastAPI starter toolkit with Redis caching, JWT Auth & CLI scaffolding

PyPI version Python versions CI Coverage MIT License GitHub Stars


✨ Features

Feature Details
Redis Caching Built-in caching templates for instant responses
🔐 JWT Auth Secure authentication with refresh tokens built-in
🗃️ Async SQLAlchemy asyncpg driver, connection pooling, Alembic migrations
🛠️ CLI Scaffolding boostapi quickstart myapp → full project in seconds
📦 Zero-Config Works out of the box with sane defaults
🚀 Production-Grade Loguru logging, CORS, rate limiting, OpenAPI docs

⚡ 2-Minute Quickstart

Option A: Scaffold a New Project

# Install BoostAPI
pip install boostapi

# Scaffold a complete web application
boostapi quickstart my-app
cd my-app

# Start dependencies (PostgreSQL + Redis)
docker compose up -d

# Run migrations & start server
alembic upgrade head
uvicorn app.main:app --reload

Open http://localhost:8000/docs — your API is live! 🎉

Option B: Embed in Your App

# myapp.py
from boostapi import create_app

app = create_app()
# uvicorn myapp:app --reload

Option C: Custom Settings

from boostapi import create_app
from boostapi.app.core.config import Settings

app = create_app(settings=Settings(
    POSTGRES_DB="mydb",
    REDIS_URL="redis://myredis:6379",
    SECRET_KEY="super-secret-change-me",
))

👨‍💻 Developer Guide

Once you've scaffolded your project, you can easily extend it to build your application.

1. Adding a Database Model

Models are built using SQLAlchemy 2.0. Define your models in app/db/models.py:

from sqlalchemy import String
from sqlalchemy.orm import Mapped, mapped_column
from boostapi.app.db.database import Base

class Item(Base):
    __tablename__ = "items"
    
    id: Mapped[int] = mapped_column(primary_key=True)
    name: Mapped[str] = mapped_column(String(255), nullable=False)

2. Database Migrations (Alembic)

After adding or modifying a model, generate and apply an Alembic migration:

# Generate a new migration script based on models
alembic revision --autogenerate -m "Add items table"

# Apply migrations to the database
alembic upgrade head

3. Creating a New API Route

Add your business logic and routes in app/api/endpoints/:

# app/api/endpoints/items.py
from fastapi import APIRouter, Depends
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy import select
from boostapi.app.api.deps import get_db
from app.db.models import Item

router = APIRouter()

@router.get("/")
async def get_items(db: AsyncSession = Depends(get_db)):
    result = await db.execute(select(Item))
    return result.scalars().all()

Then register the router in app/main.py!

4. Protecting Routes (JWT)

To require authentication, inject the get_current_user dependency:

from fastapi import Depends
from boostapi.app.api.deps import get_current_user
from boostapi.app.db.models import User

@router.get("/protected")
async def protected_route(current_user: User = Depends(get_current_user)):
    return {"message": f"Hello {current_user.username}!"}

5. Using Redis Caching

Inject the Redis client using get_redis to cache expensive computations or DB queries:

from fastapi import Depends
from redis.asyncio import Redis
from boostapi.app.api.deps import get_redis

@router.get("/stats")
async def get_stats(redis: Redis = Depends(get_redis)):
    cached = await redis.get("app_stats")
    if cached:
        return {"stats": cached, "cached": True}
    
    # Store with TTL (e.g., 60 seconds)
    stats = "expensive_computation_result"
    await redis.setex("app_stats", 60, stats)
    return {"stats": stats, "cached": False}

🔌 API Reference

Authentication

# Login
curl -X POST http://localhost:8000/api/v1/auth/login \
  -H "Content-Type: application/json" \
  -d '{"username": "admin", "password": "secret"}'

# Returns:
# {"access_token": "eyJ...", "token_type": "bearer"}

Health Check

curl http://localhost:8000/api/v1/health/
# {"status": "healthy", "version": "0.1.1", "db": "ok", "redis": "ok"}

🐳 Docker Compose

BoostAPI ships with a production-ready docker-compose.yml:

# Included automatically via `boostapi quickstart`
services:
  db:    # postgres:16-alpine
  redis: # redis:7-alpine
  app:   # your FastAPI app

⚙️ Configuration

All settings are configurable via environment variables or .env file:

Variable Default Description
POSTGRES_SERVER localhost PostgreSQL host
POSTGRES_PORT 5432 PostgreSQL port
POSTGRES_USER postgres DB username
POSTGRES_PASSWORD password DB password
POSTGRES_DB boostapi Database name
REDIS_URL redis://localhost:6379 Redis connection URL
SECRET_KEY (change me) JWT signing key
ACCESS_TOKEN_EXPIRE_MINUTES 30 Token TTL (minutes)

🧪 Testing

pip install boostapi[dev]
pytest --cov=boostapi

🚀 Deployment

Render / Fly.io

# Set environment variables in your hosting dashboard
# then:
uvicorn boostapi.app.main:app --host 0.0.0.0 --port $PORT

Docker

docker build -t my-app .
docker compose up

Publish to PyPI

pip install build twine
python -m build
twine upload dist/*

🏗️ Project Structure

my-app/                        # generated by `boostapi quickstart`
├── app/
│   ├── main.py                # create_app() entry point
│   ├── api/endpoints/         # auth, health, etc.
│   ├── core/                  # config, security
│   ├── db/                    # models, migrations
│   └── services/              # business logic
├── tests/                     # pytest suite (90%+ coverage)
├── docker-compose.yml
├── alembic.ini
└── .env

📄 License

MIT © Dhinakaran

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

boostapi-0.1.1.tar.gz (24.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

boostapi-0.1.1-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

File details

Details for the file boostapi-0.1.1.tar.gz.

File metadata

  • Download URL: boostapi-0.1.1.tar.gz
  • Upload date:
  • Size: 24.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for boostapi-0.1.1.tar.gz
Algorithm Hash digest
SHA256 dfb3f5a9899c338ce62273ffafd2deecced7f930eba2a841b024329d65d4e8ff
MD5 a007aa171913815ce46de1acb69c5cbd
BLAKE2b-256 ac904a180ed6983f07feba7549c0cb102ed23bb383c5ba832e04e3aa8bc68d4d

See more details on using hashes here.

File details

Details for the file boostapi-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: boostapi-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 22.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for boostapi-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 510d821a501bacbd3a43b5895f33f3c76ce7ed828d1b4984b29e4e714c986af9
MD5 dc9d7a0c78f24be8102bdb9a7428535b
BLAKE2b-256 dbe76757d2c107f49f8b9631851d8e1110fabc6db53eec0d8e64d72f29bb66b5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page