[](https://github.com/astral-sh/uv)
[](https://github.com/astral-sh/ruff)
[](https://pypi.org/project/fastapi-swagger-dark/)
[](https://pypi.org/project/fastapi-swagger-dark/)
[](https://pypi.org/project/fastapi-swagger-dark/)


[](https://codecov.io/gh/NRWLDev/fastapi-swagger-dark)
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:
```python
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:
```python
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:
```python
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)
```
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.
```python
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](https://github.com/georgekhananaev) and their repository
[darktheme-auth-fastapi-server](https://github.com/georgekhananaev/darktheme-auth-fastapi-server)
for the basis of the stylesheet used here.
Raw data
{
"_id": null,
"home_page": null,
"name": "fastapi-swagger-dark",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "exception, handler, starlette, webdev",
"author": null,
"author_email": "Daniel Edgecombe <daniel@nrwl.co>",
"download_url": "https://files.pythonhosted.org/packages/06/2a/73a7244e936f0b1598185634e0350e8705448131fd65bc69464edfcc2404/fastapi_swagger_dark-0.0.7.tar.gz",
"platform": null,
"description": "[](https://github.com/astral-sh/uv)\n[](https://github.com/astral-sh/ruff)\n[](https://pypi.org/project/fastapi-swagger-dark/)\n[](https://pypi.org/project/fastapi-swagger-dark/)\n[](https://pypi.org/project/fastapi-swagger-dark/)\n\n\n[](https://codecov.io/gh/NRWLDev/fastapi-swagger-dark)\n\nSimple plugin to support enabling a dark theme for swagger docs in a FastAPI application.\n\n\n\n# Usage\n\nThe simplest usage with default `/docs` endpoint can be achieved with something like:\n\n```python\nimport fastapi\nimport fastapi_swagger_dark as fsd\n\napp = fastapi.FastAPI(docs_url=None)\nrouter = fastapi.APIRouter()\n\nfsd.install(router)\napp.include_router(router)\n```\n\nTo install using a custom path:\n\n```python\nimport fastapi\nimport fastapi_swagger_dark as fsd\n\napp = fastapi.FastAPI(docs_url=None)\nrouter = fastapi.APIRouter()\n\nfsd.install(router, path=\"/swagger-docs\")\napp.include_router(router)\n```\n\nTo install using a custom prefix:\n\n```python\nimport fastapi\nimport fastapi_swagger_dark as fsd\n\napp = fastapi.FastAPI(docs_url=None)\nrouter = fastapi.APIRouter(prefix=\"/api/v1\")\n\nfsd.install(router, path=\"/docs\")\napp.include_router(router)\n```\n\nIf you are customising the documentation endpoints, for example with\nauthorization, you can replace fastapi's default get_swagger_ui_html with the\ncustom one using the dark theme. Ensure the dark_theme route is also included.\n\n```python\nimport typing\n\nimport fastapi\nimport fastapi_swagger_dark as fsd\n\napp = fastapi.FastAPI(docs_url=None)\n\n\ndef auth_validation(...) -> None:\n ...\n\n\nasync def swagger_ui_html(\n request: fastapi.Request,\n _docs_auth: typing.Annotated[None, fastapi.Depends(auth_validation)],\n) -> fastapi.responses.HTMLResponse:\n return fsd.get_swagger_ui_html(request)\n\n\napp.get(\"/docs\")(swwagger_ui_html)\napp.get(\"/dark_theme.css\", include_in_schema=False, name=\"dark_theme\")(fsd.dark_swagger_theme)\n```\n\n# Credit\n\nThanks go to [@georgekhananaev](https://github.com/georgekhananaev) and their repository\n[darktheme-auth-fastapi-server](https://github.com/georgekhananaev/darktheme-auth-fastapi-server)\nfor the basis of the stylesheet used here.\n",
"bugtrack_url": null,
"license": null,
"summary": "FastAPI plugin to add dark theme swagger docs.",
"version": "0.0.7",
"project_urls": {
"homepage": "https://github.com/NRWLDev/fastapi-swagger-dark/"
},
"split_keywords": [
"exception",
" handler",
" starlette",
" webdev"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "30ad56b538db4322462e21945ac83b410fb3b4f7cd7da909be85e313ed993fab",
"md5": "a277037c1676b79b1e2360efd9beb831",
"sha256": "4bdade47403713d013d24345336d312b5af4ca1486f85ffa3d73e80742a9c3df"
},
"downloads": -1,
"filename": "fastapi_swagger_dark-0.0.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a277037c1676b79b1e2360efd9beb831",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 58086,
"upload_time": "2025-07-09T19:15:26",
"upload_time_iso_8601": "2025-07-09T19:15:26.670951Z",
"url": "https://files.pythonhosted.org/packages/30/ad/56b538db4322462e21945ac83b410fb3b4f7cd7da909be85e313ed993fab/fastapi_swagger_dark-0.0.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "062a73a7244e936f0b1598185634e0350e8705448131fd65bc69464edfcc2404",
"md5": "05de375996e084498b5f70aa75eb2fb1",
"sha256": "83acc439bc039c8cae2a452bba2492742b09a4644f76a2d4be30207277156f1c"
},
"downloads": -1,
"filename": "fastapi_swagger_dark-0.0.7.tar.gz",
"has_sig": false,
"md5_digest": "05de375996e084498b5f70aa75eb2fb1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 179289,
"upload_time": "2025-07-09T19:15:28",
"upload_time_iso_8601": "2025-07-09T19:15:28.521160Z",
"url": "https://files.pythonhosted.org/packages/06/2a/73a7244e936f0b1598185634e0350e8705448131fd65bc69464edfcc2404/fastapi_swagger_dark-0.0.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-09 19:15:28",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "NRWLDev",
"github_project": "fastapi-swagger-dark",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "fastapi-swagger-dark"
}