Skip to content

FastAPI Helper

Note

FastAPI Helper Module need FastAPI installed.

There are two helper modules to get FastAPI app/router for proxy conveniently.

app

use fastapi_proxy_lib.fastapi.app is very convenient and out of the box, there are three helper functions:

Example:

from fastapi_proxy_lib.fastapi.app import reverse_http_app
from httpx import AsyncClient

client = AsyncClient()  # (1)!
base_url = "http://www.example.com/"  # (2)!

app = reverse_http_app(client=client, base_url=base_url)
  1. You can pass httpx.AsyncClient instance:
    • if you want to customize the arguments, e.g. httpx.AsyncClient(proxies={})
    • if you want to reuse the connection pool of httpx.AsyncClient

    Or you can pass None(The default value), then fastapi-proxy-lib will create a new httpx.AsyncClient instance for you.

  2. Note

    The base_url must end with /!

For other app helpers, please refer to their API references.

router

For the following scenarios, you might prefer fastapi_proxy_lib.fastapi.router:

Please refer to the documentation of RouterHelper for more information .