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() as part of a shutdown hook:

@app.on_event("shutdown")
async def shutdown_event() -> None:
    await http_client_dependency.aclose()

Methods Summary

__call__()

Return the cached httpx.AsyncClient.

aclose()

Close the httpx.AsyncClient.

Methods Documentation

async __call__()#

Return the cached httpx.AsyncClient.

Return type:

AsyncClient

async aclose()#

Close the httpx.AsyncClient.

Return type:

None