Auto choose the fastest cdn host for fastapi project docs.
Project description
FastAPI CDN host Selector for docs ui
Auto find swagger-ui in local files, if exist use them. Otherwise make concurrent http requests by httpx to find out which third part cdn host(cdn.jsdelivr.net/unpkg.com/cdnjs.cloudflare.com/cdn.bootcdn.net/cdn.staticfile.org) is the fastest one.
English | 中文
Install
pip install fastapi-cdn-host
Usage
import fastapi_cdn_host
from fastapi import FastAPI
app = FastAPI()
# include_routes ...
fastapi_cdn_host.patch_docs(app)
See more at:
- examples/
- tests/
Detail
- Let's say that the default docs CDN host https://cdn.jsdelivr.net is too slow in your network, while unpkg.com is much faster.
import fastapi_cdn_host
from fastapi import FastAPI
app = FastAPI()
fastapi_cdn_host.patch_docs(app) # Will use `unpkg.com`(or other faster host) to replace the `cdn.jsdelivr.net/npm`
- To support offline docs/, put swagger-ui asset files into local directory named
static
from pathlib import Path
fastapi_cdn_host.patch_docs(app, Path(__file__).parent.joinpath('static'))
This get the same result of the example in official document: https://fastapi.tiangolo.com/how-to/custom-docs-ui-assets/?h=static#self-hosting-javascript-and-css-for-docs
- If asset files are ready in private cdn
from fastapi_cdn_host import AssetUrl
fastapi_cdn_host.patch_docs(app, AssetUrl(
js='http://my-cdn.com/swagger-ui.js',
css='http://my-cdn.com/swagger-ui.css',
redoc='http://my-cdn.com/redoc.standalone.js',
favicon='http://my-cdn.com/favicon.ico')
)
License
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
fastapi_cdn_host-0.7.6.tar.gz
(12.6 kB
view details)
Built Distribution
File details
Details for the file fastapi_cdn_host-0.7.6.tar.gz
.
File metadata
- Download URL: fastapi_cdn_host-0.7.6.tar.gz
- Upload date:
- Size: 12.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.9 Darwin/20.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ba9e01efada4c70960c5de5ec1ea6d92b55cbfaf718b33069e76e1f3c02b66e |
|
MD5 | add2e987a160f07a8bba46d3bab6c6bf |
|
BLAKE2b-256 | 0ca5eda0eaac5fa46f4cf810c189ffe38b9616b5492eec63e0d40609fa060158 |
File details
Details for the file fastapi_cdn_host-0.7.6-py3-none-any.whl
.
File metadata
- Download URL: fastapi_cdn_host-0.7.6-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.9 Darwin/20.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76c3341989fa6e36c16ab10649693d28ee84aebcac483b42f12035e026863ac0 |
|
MD5 | 1c8feede1254e871651082f95c92f497 |
|
BLAKE2b-256 | 6f115276df47bbe2ff6ed8d4e866590680c1d79e286d38841e843673cf30ec8b |