Scalar FastAPI

1.8.2 · active · verified Sat Apr 11

Scalar FastAPI is a Python plugin that enhances the default FastAPI documentation experience by rendering a beautiful, interactive API reference based on the OpenAPI/Swagger specification. It provides a modern, responsive UI and a developer-first experience, offering extensive customization options for branding and layout. The library is actively maintained, with frequent updates to its underlying JavaScript components reflected in new Python wrapper releases.

Warnings

Install

Imports

Quickstart

This example sets up a basic FastAPI application and integrates Scalar documentation at the `/scalar` endpoint. It uses `app.openapi_url` to automatically load the API's schema. Run with `uvicorn main:app --reload` and navigate to `/scalar`.

from fastapi import FastAPI
from scalar_fastapi import get_scalar_api_reference
import uvicorn

app = FastAPI(
    title="My Awesome API",
    description="A simple FastAPI application to demonstrate Scalar docs.",
    version="1.0.0",
)

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

@app.get("/scalar", include_in_schema=False)
async def scalar_html():
    return get_scalar_api_reference(
        openapi_url=app.openapi_url,
        title=app.title,
        # Optional: Avoid CORS issues with a proxy
        # scalar_proxy_url="https://proxy.scalar.com",
        # Optional: Disable telemetry
        # telemetry=False
    )

# To run: uvicorn main:app --reload
# Then open http://127.0.0.1:8000/scalar in your browser

view raw JSON →