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.5.tar.gz (108.5 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.5-py3-none-any.whl (42.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi_bootstrap-0.2.5.tar.gz
  • Upload date:
  • Size: 108.5 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.5.tar.gz
Algorithm Hash digest
SHA256 2b920e00163bea53667b1e057ffcc5cda91a9ae386425e78c78efc06a3ee693b
MD5 4bb9221966acfda064f46bf5255fb438
BLAKE2b-256 f43b90726a4ab96d0dacae5f481422ea5461e58e0a6b09d86779595108f1d6ce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastapi_bootstrap-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 eec25571c947d6b9cf24abf8b9b4f05cfb35c1281ae915ba95755fbdc33b9ff0
MD5 9b3b14284200a993ef60b14bebb8397e
BLAKE2b-256 66c1fac4730e81f2f2ae36064adbb70d7f2d76e0c8a4cffa91dd8c9220677326

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