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

  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,
    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

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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_cdn_host-0.9.1-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi_cdn_host-0.9.1.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.23.1 CPython/3.11.9 Darwin/20.6.0

File hashes

Hashes for fastapi_cdn_host-0.9.1.tar.gz
Algorithm Hash digest
SHA256 39e6f2dc951d75992a1d12d453ab4ec96f3cdae4be6870ee9d4b1ca3f92ea4f0
MD5 c5c6dfe8fa1fcc98912d150e98465f26
BLAKE2b-256 1b8154893fd8a734402010925d6a97e6d9adba603586df718928c21bab7e712c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fastapi_cdn_host-0.9.1-py3-none-any.whl
  • Upload date:
  • Size: 15.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.23.1 CPython/3.11.9 Darwin/20.6.0

File hashes

Hashes for fastapi_cdn_host-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5f032b350e03d0ef51398351299d5a9c5258df90a3051fcb6559b045c5a02ce5
MD5 90312f1ca1dd8dd20d77c517e46b56f3
BLAKE2b-256 9b5080149e939e023ca59087b13ae2fad818586364aa36d6b9cec517ca6aca3c

See more details on using hashes here.

Supported by

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