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.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:
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,
cdn_host=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
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_cdn_host-0.9.2.tar.gz.
File metadata
- Download URL: fastapi_cdn_host-0.9.2.tar.gz
- Upload date:
- Size: 16.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.25.3 CPython/3.12.7 Darwin/20.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ae4dc7296bc75412c63c48e152b2cfcaf209559075fda9d71f2bb65f5923de1
|
|
| MD5 |
1c3bc8f5f3f91b8535746be154bf7af3
|
|
| BLAKE2b-256 |
fb82461d60f2f3dba4133009b2d67ed2400d8d10671aa6b86fe506b9b13e3ba9
|
File details
Details for the file fastapi_cdn_host-0.9.2-py3-none-any.whl.
File metadata
- Download URL: fastapi_cdn_host-0.9.2-py3-none-any.whl
- Upload date:
- Size: 15.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.25.3 CPython/3.12.7 Darwin/20.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8fe2f57c1be6d3eb57c1c12d9d6d7cb085a3eb526456909edd9bd388c4434681
|
|
| MD5 |
ab7137ce6a72a5a5a2f9c841470342bd
|
|
| BLAKE2b-256 |
e0e1a268bdec3e477e041a9647e0562a58d271a259eee27a99d09bc37e77b1ea
|