Skip to main content

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

Metadata

Release files for fastapi-cdn-host 0.10.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastapi-cdn-host 0.10.0
File Size Uploaded Provenance Actions
fastapi_cdn_host-0.10.0.tar.gz 16.9 kB Without provenance Details for fastapi_cdn_host-0.10.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-cdn-host 0.10.0
File Interpreter ABI Platform Actions
fastapi_cdn_host-0.10.0-py3-none-any.whl Python 3 none any Details for fastapi_cdn_host-0.10.0-py3-none-any.whl

Total release size: 32.8 kB

Release files / fastapi_cdn_host-0.10.0.tar.gz

Download URL fastapi_cdn_host-0.10.0.tar.gz
Size 16.9 kB
Tags Source
SHA-256 checksum
How to use checksums
0b5e949a5712bd829aabd15f0733072479d64c48560150b76707059ee87efc23
BLAKE2b-256 checksum
How to use checksums
737ce5ae214a2c4665ea411b713213a67e0ecff4f47d84d4a298322ced20bc43
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / fastapi_cdn_host-0.10.0-py3-none-any.whl

Download URL fastapi_cdn_host-0.10.0-py3-none-any.whl
Size 16.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f4563c154e7f789231597320f4ef6866a0cd3af5425322875540d9f1648e1886
BLAKE2b-256 checksum
How to use checksums
35ee49705ec7451b1c52bdedc8f4b15977fb44173e2d9ec95c351794ae5fb6bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Security for fastapi-cdn-host 0.10.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.10.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page