FastAPI Offline Docs

1.7.6 · active · verified Thu Apr 16

fastapi-offline is a Python library that enables FastAPI applications to serve their interactive documentation (Swagger UI and Redoc) without relying on external Content Delivery Networks (CDNs). It bundles the necessary static assets locally, making it suitable for environments with restricted internet access or for improved reliability. The library is actively maintained, with frequent releases (currently v1.7.6) to vendor new dependencies and ensure compatibility with the latest Python and FastAPI versions.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a basic FastAPI application using `FastAPIOffline`. Simply import `FastAPIOffline` and instantiate it instead of `FastAPI`. The interactive documentation (Swagger UI and ReDoc) will then be served from local assets, making them available offline. Any parameters passed to `FastAPIOffline()` (except `docs_url`, `redoc_url`, `favicon_url`, and `static_url`) are forwarded to the underlying `FastAPI` instance.

from fastapi_offline import FastAPIOffline
import uvicorn

app = FastAPIOffline(
    title="My Offline API",
    description="A simple API with offline docs"
)

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

@app.get("/items/{item_id}")
async def read_item(item_id: int):
    return {"item_id": item_id}

# To run this app, save it as main.py and execute: uvicorn main:app --reload
# Then open http://127.0.0.1:8000/docs or http://127.0.0.1:8000/redoc in your browser.

view raw JSON →