Simple plugin to support enabling a dark theme for swagger docs in a FastAPI application.
Usage
The simplest usage with default /docs endpoint can be achieved with something like:
import fastapi
import fastapi_swagger_dark as fsd
app = fastapi.FastAPI(docs_url=None)
router = fastapi.APIRouter()
fsd.install(router)
app.include_router(router)
To install using a custom path:
import fastapi
import fastapi_swagger_dark as fsd
app = fastapi.FastAPI(docs_url=None)
router = fastapi.APIRouter()
fsd.install(router, path="/swagger-docs")
app.include_router(router)
To install using a custom prefix:
import fastapi
import fastapi_swagger_dark as fsd
app = fastapi.FastAPI(docs_url=None)
router = fastapi.APIRouter(prefix="/api/v1")
fsd.install(router, path="/docs")
app.include_router(router)
To install using custom swagger_ui_parameters:
import fastapi
import fastapi_swagger_dark as fsd
app = fastapi.FastAPI(docs_url=None)
router = fastapi.APIRouter()
fsd.install(router, swagger_ui_parameters={...})
app.include_router(router)
If you are customising the documentation endpoints, for example with authorization, you can replace fastapi's default get_swagger_ui_html with the custom one using the dark theme. Ensure the dark_theme route is also included.
import typing
import fastapi
import fastapi_swagger_dark as fsd
app = fastapi.FastAPI(docs_url=None)
def auth_validation(...) -> None:
...
async def swagger_ui_html(
request: fastapi.Request,
_docs_auth: typing.Annotated[None, fastapi.Depends(auth_validation)],
) -> fastapi.responses.HTMLResponse:
return fsd.get_swagger_ui_html(request)
app.get("/docs")(swwagger_ui_html)
app.get("/dark_theme.css", include_in_schema=False, name="dark_theme")(fsd.dark_swagger_theme)
Credit
Thanks go to @georgekhananaev and their repository darktheme-auth-fastapi-server for the basis of the stylesheet used here.
Metadata
Release files for fastapi-swagger-dark 0.0.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fastapi_swagger_dark-0.0.9.tar.gz | 179.8 kB | Without provenance | Details for fastapi_swagger_dark-0.0.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fastapi_swagger_dark-0.0.9-py3-none-any.whl | Python 3 | none | any | Details for fastapi_swagger_dark-0.0.9-py3-none-any.whl |
Total release size: 238.1 kB
Release files / fastapi_swagger_dark-0.0.9.tar.gz
| Download URL | fastapi_swagger_dark-0.0.9.tar.gz |
|---|---|
| Size | 179.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3f981af17ced385e53bd813c4ba08c99c8ca551c1a2957295abbf12c511d97d5
|
|
BLAKE2b-256 checksum How to use checksums |
f790f68af675cf21bd4f091c6e686b9d01839a956f3188fbd68c3527399a8fdb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Release files / fastapi_swagger_dark-0.0.9-py3-none-any.whl
| Download URL | fastapi_swagger_dark-0.0.9-py3-none-any.whl |
|---|---|
| Size | 58.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
189ae4b8c4b58fc2faa19929517fc81495add85611b3117f650f15135d53f748
|
|
BLAKE2b-256 checksum How to use checksums |
6306f880792625d4ebb75786e47867ade0c9a7163a52293847babb9adf9540c1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Security for fastapi-swagger-dark 0.0.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.