Skip to main content

🚀 Easy FastAPI Setup Kit - Production-ready FastAPI boilerplate with logging, error handling, metrics, security headers, and more

Project description

FastAPI Bootstrap

Production-ready FastAPI boilerplate with batteries included.

한국어 | English

Features

  • 📝 Structured Logging — Loguru-based logging with request tracking and trace IDs
  • 🛡️ Exception Handling — Centralized error handling with consistent responses
  • 📊 Prometheus Metrics — Built-in /metrics endpoint with request statistics
  • 🔒 Security Headers — HSTS, CSP, X-Frame-Options middleware
  • 🔐 OIDC Authentication — Optional JWT/JWKS validation
  • ⚡️ Type Safety — Pydantic V2 integration with enhanced BaseModel

Installation

pip install fastapi-bootstrap

Quick Start

from fastapi import APIRouter
from fastapi_bootstrap import create_app, LoggingAPIRoute

router = APIRouter(route_class=LoggingAPIRoute)

@router.get("/hello")
async def hello():
    return {"message": "Hello, World!"}

app = create_app([router], title="My API", version="1.0.0")

Run with: uvicorn app:app --reload

Core Components

Application Factory

from fastapi_bootstrap import create_app

app = create_app(
    routers=[router],
    title="My API",
    version="1.0.0"
)

Logging

from fastapi_bootstrap import get_logger, LoggingAPIRoute

logger = get_logger(__name__)
router = APIRouter(route_class=LoggingAPIRoute)

@router.get("/users/{user_id}")
async def get_user(user_id: int):
    logger.info("Fetching user", user_id=user_id)
    return {"user_id": user_id}

Exception Handling

from fastapi_bootstrap.exception import NotFoundException

@router.get("/users/{user_id}")
async def get_user(user_id: int):
    user = db.get(user_id)
    if not user:
        raise NotFoundException(detail="User not found")
    return user

Error response:

{
  "error": {
    "code": "NOT_FOUND",
    "message": "User not found"
  }
}

Metrics

from fastapi_bootstrap import MetricsMiddleware, get_metrics_router

app.add_middleware(MetricsMiddleware)
app.include_router(get_metrics_router())  # GET /metrics

Documentation

For advanced features, see ADVANCED.md:

  • Security Headers Configuration
  • Request ID & Timing Middleware
  • Max Request Size Limits
  • OIDC Authentication Setup
  • CORS Configuration
  • Health Checks
  • Complete Examples

Examples

See examples/ directory for complete working examples.

License

MIT License - see LICENSE

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

fastapi_bootstrap-0.2.4.tar.gz (108.0 kB view details)

Uploaded Source

Built Distribution

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

fastapi_bootstrap-0.2.4-py3-none-any.whl (41.9 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_bootstrap-0.2.4.tar.gz.

File metadata

  • Download URL: fastapi_bootstrap-0.2.4.tar.gz
  • Upload date:
  • Size: 108.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for fastapi_bootstrap-0.2.4.tar.gz
Algorithm Hash digest
SHA256 3d8e56748018a1598b372cc75fc959c6d5c242c29ad39e3ba3f9119520a47702
MD5 1b7aae7fbffb456b47accf80e2f9beb6
BLAKE2b-256 bfb6de7d9fdddb1a804f46ffdb00ca7d56c10197ee99938e0424ee671760c262

See more details on using hashes here.

File details

Details for the file fastapi_bootstrap-0.2.4-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_bootstrap-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 80770c3d1b181f0e7172a525aebbe1af7b69e1a7cb1a998a741f233205a7883f
MD5 8c113cd8a2ec5753528aac6c26b1cf80
BLAKE2b-256 4883c9e794c76a8edf900a377843acfb20b2ac580829e6280e87baca96b5cc1d

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