Skip to main content

Beautiful Swagger UI for FastAPI — dark/light theme + Monaco Editor

Project description

  ██████╗ ██████╗  ██████╗ ██╗      ███████╗██╗    ██╗ █████╗  ██████╗  ██████╗ ███████╗██████╗
 ██╔════╝██╔═══██╗██╔═══██╗██║      ██╔════╝██║    ██║██╔══██╗██╔════╝ ██╔════╝ ██╔════╝██╔══██╗
 ██║     ██║   ██║██║   ██║██║      ███████╗██║ █╗ ██║███████║██║  ███╗██║  ███╗█████╗  ██████╔╝
 ██║     ██║   ██║██║   ██║██║      ╚════██║██║███╗██║██╔══██║██║   ██║██║   ██║██╔══╝  ██╔══██╗
 ╚██████╗╚██████╔╝╚██████╔╝███████╗ ███████║╚███╔███╔╝██║  ██║╚██████╔╝╚██████╔╝███████╗██║  ██║
  ╚═════╝ ╚═════╝  ╚═════╝ ╚══════╝ ╚══════╝ ╚══╝╚══╝ ╚═╝  ╚═╝ ╚═════╝  ╚═════╝ ╚══════╝╚═╝  ╚═╝

Beautiful Swagger UI for FastAPI — dark mode, Monaco Editor, zero config

PyPI version Python 3.10+ License: MIT Downloads FastAPI

Tired of FastAPI's plain white Swagger UI? One line and you get a proper dark mode, VS Code's Monaco Editor for request bodies, and theme persistence — no extra dependencies.


✨ What you get

Default FastAPI Swagger UI coolswagger
🌙 Dark / ☀️ Light theme toggle
💾 Theme saved across page reloads
🖊️ Monaco Editor for request body (syntax highlight, bracket match)
🔐 OAuth2 / initOAuth support
🎛️ swagger_ui_parameters passthrough
🎨 Custom CDN URLs partial
⚡ Zero extra runtime dependencies

📦 Installation

# pip
pip install coolswagger

# uv  (recommended)
uv add coolswagger

# poetry
poetry add coolswagger

Requires Python 3.10+ and FastAPI 0.100+.


🚀 Quick start

Replace the built-in FastAPI docs with a two-line change:

from fastapi import FastAPI
from coolswagger import coolswagger_router

# disable the default /docs
app = FastAPI(docs_url=None, title="My API")

app.include_router(
    coolswagger_router(docs_url="/docs", title=app.title)
)

Open /docs — dark mode toggle is in the top-right corner, request body fields are Monaco editors.


⚙️ Advanced usage

SwaggerConfig helper

from fastapi import FastAPI
from coolswagger import SwaggerConfig, setup_swagger

app = FastAPI(docs_url=None, title="My API")

setup_swagger(app, SwaggerConfig(
    title=app.title,
    docs_url="/docs",
    coolswagger_enable=True,   # False → falls back to default Swagger UI
))

OAuth2

app.include_router(
    coolswagger_router(
        docs_url="/docs",
        title=app.title,
        oauth2_redirect_url="/oauth2-redirect",
        init_oauth={"clientId": "my-client", "scopes": "openid profile"},
    )
)

Custom Swagger UI parameters

app.include_router(
    coolswagger_router(
        docs_url="/docs",
        title=app.title,
        swagger_ui_parameters={
            "persistAuthorization": True,
            "filter": True,
            "syntaxHighlight.theme": "monokai",
        },
    )
)

Self-hosted / offline (no CDN)

app.include_router(
    coolswagger_router(
        docs_url="/docs",
        title=app.title,
        swagger_js_url="/static/swagger-ui-bundle.js",
        swagger_css_url="/static/swagger-ui.css",
        monaco_js_url="/static/monaco/vs/loader.js",
    )
)

📋 Parameters

Parameter Type Default Description
title str required API title shown in the page
docs_url str "/docs" URL path for the docs page
openapi_url str "/openapi.json" URL to the OpenAPI schema
swagger_js_url str jsDelivr CDN Swagger UI bundle JS
swagger_css_url str jsDelivr CDN Swagger UI CSS
swagger_favicon_url str FastAPI favicon Browser tab icon
monaco_js_url str jsDelivr CDN Monaco Editor loader script
oauth2_redirect_url str | None None OAuth2 redirect URL
init_oauth dict | None None Passed to SwaggerUI.initOAuth()
swagger_ui_parameters dict | None None Extra SwaggerUIBundle options

🛠️ How it works

coolswagger registers a custom MonacoPlugin inside SwaggerUIBundle. The plugin wraps Swagger UI's internal TextArea component — every request-body textarea is replaced with a Monaco editor instance (JSON mode, auto-layout, theme-aware). Editor instances are indexed by "METHOD /path" so the patched ui.execute can pull the correct content and override req.requestBody right before the HTTP call is made.

Dark mode is a CSS class on <body> toggled by a fixed button, with the choice persisted in localStorage under swagger-theme.


🤝 Contributing

Issues and PRs are welcome at github.com/SasquatchMe/coolswagger.

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

coolswagger-0.1.1.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

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

coolswagger-0.1.1-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file coolswagger-0.1.1.tar.gz.

File metadata

  • Download URL: coolswagger-0.1.1.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for coolswagger-0.1.1.tar.gz
Algorithm Hash digest
SHA256 388534f88976003e074ef6f3c2dbd8c27956276f5d1eb1317346781fcab567da
MD5 56eab80fc2cae0e682bf30df926f4806
BLAKE2b-256 3922781bb7849ed2ac866e3bac9f3d822c0ce5f018255bbb0a0032544de6cb0c

See more details on using hashes here.

Provenance

The following attestation bundles were made for coolswagger-0.1.1.tar.gz:

Publisher: publish.yml on SasquatchMe/coolswagger

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file coolswagger-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: coolswagger-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for coolswagger-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e80afa585f50566cd814db67adb035ef58ea6e09b03837bd51b23ab42fdcfece
MD5 b9d99caf0f3ebba6ea9b104400250182
BLAKE2b-256 15ce124c8ab782ad4e4445cdf17639c8270bedd00a9aeaac27a8074c269dbe55

See more details on using hashes here.

Provenance

The following attestation bundles were made for coolswagger-0.1.1-py3-none-any.whl:

Publisher: publish.yml on SasquatchMe/coolswagger

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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