Dark/light theme toggle and readability improvements for FastAPI Swagger UI.
Project description
fastapi-swagger-ui-theme
This package enhances the default Swagger UI by adding a persistent light/dark mode toggle, and better contrast.
Features
- 🌗 Dark / Light theme toggle (persisted via
localStorage) - ⚡ Zero JavaScript configuration required
- 🔌 Plug-and-play setup with a single function call
- 📦 Packaged static assets (no CDN hacks, no manual mounting)
Installation
Using pip:
pip install fastapi-swagger-ui-theme
Using uv:
uv add fastapi-swagger-ui-theme
Usage
Add the light/dark toggle to your FastAPI application by importing and calling the provided function:
from fastapi import FastAPI
from fastapi_swagger_ui_theme import setup_swagger_ui_theme
app = FastAPI(docs_url=None) # Close the docs_url here.
setup_swagger_ui_theme(app, docs_path="/docs")
This will automatically inject the dark/light toggle and improved styles into the Swagger UI at /docs.
Configuration
The setup_swagger_ui_theme function supports optional parameters to customize the behavior:
from fastapi import FastAPI
from fastapi_swagger_ui_theme import setup_swagger_ui_theme
app = FastAPI(docs_url=None) # Close the docs_url here.
setup_swagger_ui_theme(
app,
docs_path="/docs",
title="API Docs",
static_mount_path="/swagger-ui-theme-static",
swagger_favicon_url=None,
oauth2_redirect_url=None,
init_oauth=None,
swagger_ui_parameters=None,
)
docs_path: URL path for Swagger UI (default:/docs)title: Title of the Swagger UI page (default:"Swagger UI")static_mount_path: Path to mount the static assets (default:/static/swagger-ui-theme)swagger_js_url: URL to the Swagger UI JavaScript bundle (default:https://unpkg.com/swagger-ui-dist@5/swagger-ui-bundle.js, uses bundled version)swagger_css_url: URL to the Swagger UI CSS bundle (default:https://unpkg.com/swagger-ui-dist@5/swagger-ui.css, uses bundled version)swagger_favicon_url: URL to the favicon for Swagger UI (default:None, uses bundled version)oauth2_redirect_url: OAuth2 redirect URL for Swagger UI (default:None)init_oauth: Dict of OAuth2 initialization parameters (default:None)swagger_ui_parameters: Dict of additional Swagger UI parameters (default:None)
Screenshots
Light Mode
Dark Mode
Running the Demo / Test Application
To run the demo/test application, follow these steps:
-
Clone the repository:
git clone https://github.com/akutayural/fastapi-swagger-ui-theme.git cd fastapi-swagger-ui-theme
-
Initialize the environment with
uv:uv init -
Install the required dependencies:
uv add uvicorn apiexception
-
Run the demo application:
.venv/bin/uvicorn test.app:app --reload
Credits
This project is inspired by and builds upon the official Swagger UI and FastAPI projects.
Special thanks to the following projects and their authors for their contributions to the dark theme lineage:
- NRWLDev/fastapi-swagger-dark by NRWLDev, which further developed the dark theme integration.
- georgekhananaev/darktheme-auth-fastapi-server by George Khanaev, which provided the original dark theme stylesheet.
Thanks to all contributors and maintainers of these projects.
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 fastapi_swagger_ui_theme-0.1.0.tar.gz.
File metadata
- Download URL: fastapi_swagger_ui_theme-0.1.0.tar.gz
- Upload date:
- Size: 36.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c1dfbdb83d1a189a2fca795f077e2f4789f259cf9c229e7e71d656c53d1fea5
|
|
| MD5 |
c05ed23a7bc48156e014e7577f30c9ef
|
|
| BLAKE2b-256 |
b8fef399e6738aff9f110444b8dbfea26eb378b1e1e9b12113db510d64e170b9
|
File details
Details for the file fastapi_swagger_ui_theme-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fastapi_swagger_ui_theme-0.1.0-py3-none-any.whl
- Upload date:
- Size: 37.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30252d6473a04f0a8ac360a2b382aab90828e597083010e686ba7fa84a0d73c0
|
|
| MD5 |
fe00bf70b3822ca415b501a4939c954b
|
|
| BLAKE2b-256 |
966b708d64b24a34c8b734c1cd720035270b0708af997f2d1f01cf4806427af0
|