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.0.tar.gz (15.5 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.0-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for fastapi_cdn_host-0.9.0.tar.gz
Algorithm Hash digest
SHA256 7f40ab883a9e09c635ce426cad88f532adff5eb1485fa713d6118d08450353ea
MD5 7f5459d60c321b5e0cc6fb663b36355d
BLAKE2b-256 48264881773d04dd6de2e1ce6df58aeed4bc671f788cd7a1b8f33f86c3064346

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for fastapi_cdn_host-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3f7aae65ee62476caa468d224d762500f406c0c8fed5a740c69e4e8ebe496308
MD5 d9b6f87960567f7992a18037bc5ce7cb
BLAKE2b-256 65b3031ec8e3ea4a32949b3560795369312a3b89e522706c7c8d37cb8f7c5cf2

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