Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ahmetoner/fastapi-offline-swagger-ui
By default FastAPI uses CDN for swagger ui assets, with this repository you can use it offline.
https://github.com/ahmetoner/fastapi-offline-swagger-ui
docs fastapi offline python swagger-ui
Last synced: about 1 month ago
JSON representation
By default FastAPI uses CDN for swagger ui assets, with this repository you can use it offline.
- Host: GitHub
- URL: https://github.com/ahmetoner/fastapi-offline-swagger-ui
- Owner: ahmetoner
- License: mit
- Created: 2022-12-03T22:13:40.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-07-22T22:12:27.000Z (over 1 year ago)
- Last Synced: 2024-05-02T04:14:17.068Z (8 months ago)
- Topics: docs, fastapi, offline, python, swagger-ui
- Language: Python
- Homepage: https://github.com/ahmetoner/fastapi-offline-swagger-ui
- Size: 4.88 KB
- Stars: 11
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Fastapi Offline Swagger UI
By default FastAPI uses CDN for swagger ui assets (js and css files), with this repository you can use it offline. This repository aims to download CDN urls and store inside of a python module. You can easily use this downloaded assets with following examples.## Install
You can install this software via pip or poetry.```sh
pip3 install git+https://github.com/ahmetoner/fastapi-offline-swagger-ui
```or pyproject.toml
```sh
[tool.poetry.dependencies]
...
fastapi-offline-swagger-ui = {git = "https://github.com/ahmetoner/fastapi-offline-swagger-ui"}```
## Usage Examples
After installing the module, create a python file. Copy and run following.
```py
from fastapi import FastAPI, File, UploadFile, Query, applications
from fastapi.responses import StreamingResponse, RedirectResponse
from fastapi.staticfiles import StaticFiles
from fastapi.openapi.docs import get_swagger_ui_html
import fastapi_offline_swagger_uiapp = FastAPI()
''' This following code block necessary to switch offline cdn files via fastapi_offline_swagger_ui module
'''
assets_path = fastapi_offline_swagger_ui.__path__[0]
if path.exists(assets_path + "/swagger-ui.css") and path.exists(assets_path + "/swagger-ui-bundle.js"):
app.mount("/assets", StaticFiles(directory=assets_path), name="static")
def swagger_monkey_patch(*args, **kwargs):
return get_swagger_ui_html(
*args,
**kwargs,
swagger_favicon_url="",
swagger_css_url="/assets/swagger-ui.css",
swagger_js_url="/assets/swagger-ui-bundle.js",
)
applications.get_swagger_ui_html = swagger_monkey_patch```
## Live Example
Alternatively you can browse [ahmetoner/whisper-asr-webservice](https://github.com/ahmetoner/whisper-asr-webservice/) repository to see how it is implemented.