Skip to main content

Auto choose the fastest cdn host for fastapi project docs.

Project description

FastAPI CDN host Selector for docs ui

Python Versions LatestVersionInPypi GithubActionResult Coverage Status Ruff security: bandit

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

  1. 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`
  1. 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

  1. 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

MIT

Project details


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.2.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

fastapi_cdn_host-0.7.2-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_cdn_host-0.7.2.tar.gz.

File metadata

  • Download URL: fastapi_cdn_host-0.7.2.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.9 Darwin/20.6.0

File hashes

Hashes for fastapi_cdn_host-0.7.2.tar.gz
Algorithm Hash digest
SHA256 b6bc378398177a959d32ca8be85e6d3d7280fb17f8c51756f47292afe922bf31
MD5 7f6a5935978161da8c68ff82b1c7e274
BLAKE2b-256 93fef08cd688b1a02b752f1d76c35cbb56d4bc88c0e7b798bd0e75bc4d921e43

See more details on using hashes here.

File details

Details for the file fastapi_cdn_host-0.7.2-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_cdn_host-0.7.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bca80d6b59a22eaaaa93335b3c6cd524d3009f1109a7e951ace2364cebb68f06
MD5 3011d20c5911b44a57a9f194c39e5a5d
BLAKE2b-256 de14adf40905d2c56941af72ab983d00c84f34afeac72838998583f3a9cc35c8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page