Beautiful Swagger UI for FastAPI — dark/light theme + Monaco Editor
Project description
██████╗ ██████╗ ██████╗ ██╗ ███████╗██╗ ██╗ █████╗ ██████╗ ██████╗ ███████╗██████╗
██╔════╝██╔═══██╗██╔═══██╗██║ ██╔════╝██║ ██║██╔══██╗██╔════╝ ██╔════╝ ██╔════╝██╔══██╗
██║ ██║ ██║██║ ██║██║ ███████╗██║ █╗ ██║███████║██║ ███╗██║ ███╗█████╗ ██████╔╝
██║ ██║ ██║██║ ██║██║ ╚════██║██║███╗██║██╔══██║██║ ██║██║ ██║██╔══╝ ██╔══██╗
╚██████╗╚██████╔╝╚██████╔╝███████╗ ███████║╚███╔███╔╝██║ ██║╚██████╔╝╚██████╔╝███████╗██║ ██║
╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝ ╚══════╝ ╚══╝╚══╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝
Beautiful Swagger UI for FastAPI — dark mode, Monaco Editor, zero config
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
388534f88976003e074ef6f3c2dbd8c27956276f5d1eb1317346781fcab567da
|
|
| MD5 |
56eab80fc2cae0e682bf30df926f4806
|
|
| BLAKE2b-256 |
3922781bb7849ed2ac866e3bac9f3d822c0ce5f018255bbb0a0032544de6cb0c
|
Provenance
The following attestation bundles were made for coolswagger-0.1.1.tar.gz:
Publisher:
publish.yml on SasquatchMe/coolswagger
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
coolswagger-0.1.1.tar.gz -
Subject digest:
388534f88976003e074ef6f3c2dbd8c27956276f5d1eb1317346781fcab567da - Sigstore transparency entry: 1413077333
- Sigstore integration time:
-
Permalink:
SasquatchMe/coolswagger@547710a27424c48b008df91ba0f269a4656f6796 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/SasquatchMe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@547710a27424c48b008df91ba0f269a4656f6796 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e80afa585f50566cd814db67adb035ef58ea6e09b03837bd51b23ab42fdcfece
|
|
| MD5 |
b9d99caf0f3ebba6ea9b104400250182
|
|
| BLAKE2b-256 |
15ce124c8ab782ad4e4445cdf17639c8270bedd00a9aeaac27a8074c269dbe55
|
Provenance
The following attestation bundles were made for coolswagger-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on SasquatchMe/coolswagger
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
coolswagger-0.1.1-py3-none-any.whl -
Subject digest:
e80afa585f50566cd814db67adb035ef58ea6e09b03837bd51b23ab42fdcfece - Sigstore transparency entry: 1413077439
- Sigstore integration time:
-
Permalink:
SasquatchMe/coolswagger@547710a27424c48b008df91ba0f269a4656f6796 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/SasquatchMe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@547710a27424c48b008df91ba0f269a4656f6796 -
Trigger Event:
push
-
Statement type: