FastAPI

Requires the fastapi extra. See FastAPI for installation and usage.

imgproxykit.integrations.fastapi.add_imgproxy(app: FastAPI, client: Client, *, name: str = 'imgproxykit_client') → Callable[[Request], Awaitable[Client]][source]

Register a client and return its FastAPI dependency.

Call while building the application, before it starts serving requests. Keep the returned callable for use with Depends and dependency overrides. Each application owns its clients; the dependency resolves its name against the application handling the current request.

Parameters:
app: FastAPI

Application that owns the client.

client: Client

Configured URL builder, including any signing credentials.

name: str = 'imgproxykit_client'

Attribute name on app.state. Defaults to 'imgproxykit_client'. Must not already exist.

Return type:

Callable[[Request], Awaitable[Client]]

Returns:

An async dependency returning the registered client. URL generation remains synchronous and makes no network requests.

Raises:
  • ValueError – If the application’s state already has this attribute.

  • TypeError – When the application’s state attribute does not contain a client, including when it has not been registered.