FastAPI is famous for its blazing speed and auto-generated documentation.
Out of the box, it gives you:
- Swagger UI at
/docs
- ReDoc UI at
/redoc
But here’s the thing:
If you want your API to feel polished, developer-friendly, and production-ready,
you need better documentation than just the basics.
Today, I’ll show you how to use scalar-fastapi
to create beautiful, customizable API docs — and why great documentation is as important as great code.
🛠 The Problem with Default Swagger Docs
Swagger is great for getting started, but:
- It's plain and developer playground-like
- It doesn't scale visually when you have 50+ endpoints
- It lacks branding — it doesn't feel like your product
- First impressions matter — messy docs = perceived messy product
🚀 Meet scalar-fastapi
scalar-fastapi
is a sweet package that upgrades your FastAPI documentation experience instantly.
It turns your OpenAPI schema into a:
- Beautifully designed API reference
- Modern, responsive UI
- Developer-first experience
And the best part?
It takes just a few lines of code to integrate.
📦 How To Set It Up
First, install Scalar:
pip install scalar-fastapi
Now update your main.py
:
from fastapi import FastAPI
from app.core.config import settings
from app.api.v1 import router as v1_router
from scalar_fastapi import get_scalar_api_reference
app = FastAPI(title=settings.PROJECT_NAME)
app.include_router(v1_router, prefix=settings.API_V1_STR)
@app.get("/")
def read_root():
return {"message": "Welcome to the FastAPI backend!"}
@app.get("/scalar", include_in_schema=False)
async def scalar_html():
return get_scalar_api_reference(
openapi_url=app.openapi_url,
title=app.title,
)
✅ That’s it — now visiting /scalar
will show you the upgraded docs!
🎨 Before and After — Visual Impact
Swagger UI (default) | Scalar API UI (better) |
---|---|
Messy when large | Clean and scalable |
Limited customization | Full branding support |
Feels like a demo project | Feels like a real product |
A small upgrade that changes the entire experience.
🛠 Full Configuration Options (Explained)
Scalar gives you serious control over how your docs look and behave:
Option | Default | What It Controls |
---|---|---|
layout |
Layout.MODERN |
Layout style (MODERN , CLASSIC , etc.) |
show_sidebar |
True |
Whether the left sidebar is visible |
hide_download_button |
False |
Hides the "Download OpenAPI Spec" button |
hide_models |
False |
Hides the models/schemas section |
dark_mode |
True |
Dark mode by default |
search_hot_key |
SearchHotKey.K |
Keyboard shortcut for search |
hidden_clients |
[] |
Hide specific SDK clients |
servers |
[] |
Define multiple server environments |
default_open_all_tags |
False |
Expand all tags by default |
authentication |
{} |
Pre-configure API authentication |
🔥 Example: Fully Customized Scalar UI
from scalar_fastapi import get_scalar_api_reference, Layout, SearchHotKey
@app.get("/scalar", include_in_schema=False)
async def scalar_html():
return get_scalar_api_reference(
openapi_url=app.openapi_url,
title="My Awesome API",
layout=Layout.CLASSIC,
show_sidebar=True,
hide_download_button=False,
hide_models=False,
dark_mode=True,
search_hot_key=SearchHotKey.K,
servers=[
{"url": "https://api.production.example.com"},
{"url": "https://api.staging.example.com"}
],
default_open_all_tags=True,
authentication={"bearerAuth": "your-static-token-if-needed"},
)
Boom — your docs now:
- Match your brand
- Show your production & staging servers
- Look polished out of the box
🌍 Bonus: Deploying Your Public Docs
After setting up Scalar, you might want to expose your API docs nicely.
Here are two easy ways:
- Docker Deploy: Serve your FastAPI app inside a Docker container behind nginx.
- Cloud Deploy: Push it to AWS, Koyeb or DigitalOcean for HTTPS and autoscaling.
FastAPI + Scalar scales to real production traffic easily.
📣 Why Beautiful API Docs Matter
Good docs aren't just about looking nice:
✅ They save onboarding time for new devs
✅ They reduce mistakes using the API
✅ They build trust in your platform
✅ They differentiate you from lazy competitors
In real startups and production teams, beautiful docs = better adoption.
That's why companies like Stripe, Twilio, and Shopify invest heavily into theirs.
🏁 Final Thoughts
✅ If you're serious about building professional APIs
✅ If you care about other developers using your platform
✅ If you want to stand out
Then upgrading your FastAPI docs with Scalar is one of the easiest, most impactful things you can do today.
It takes 5 minutes, but leaves a permanent pro impression.
🚀 What's Next?
In the next part of this series, I’ll show how to:
- Tag your endpoints for even cleaner documentation
- Add authentication flows (JWT, OAuth) to your docs
- Customize OpenAPI metadata (terms, license, support contacts)
Stay tuned — we’re building real production-ready APIs! 🎯
✍️ Final CTA
"If you enjoyed this guide, connect with me on LinkedIn for more full-stack engineering, and developer experience tips!" 🚀