HTTPClientDependency#

class safir.dependencies.http_client.HTTPClientDependency#

Bases: object

Provides an httpx.AsyncClient as a dependency.

The resulting client will have redirects enabled and the default timeout increased to 20 seconds.

Notes

The application must call http_client_dependency.aclose() in the application lifespan hook:

from collections.abc import AsyncIterator
from contextlib import asynccontextmanager

from fastapi import FastAPI

@asynccontextmanager
async def lifespan(app: FastAPI) -> AsyncIterator[None]:
    yield
    await http_client_dependency.aclose()


app = FastAPI(lifespan=lifespan)

Methods Summary

__call__()

Return the cached httpx.AsyncClient.

aclose()

Close the httpx.AsyncClient.

Methods Documentation

async __call__()#

Return the cached httpx.AsyncClient. :rtype: AsyncClient

async aclose()#

Close the httpx.AsyncClient. :rtype: None