Skip to content

Context

faststream._internal.fastapi.context.Context #

Context(name, *, default=EMPTY, initial=None)

Get access to objects of the Context.

Source code in faststream/_internal/fastapi/context.py
def Context(  # noqa: N802
    name: str,
    *,
    default: Any = EMPTY,
    initial: Callable[..., Any] | None = None,
) -> Any:
    """Get access to objects of the Context."""

    def solve_context(
        context: Annotated[Any, params.Header(alias="context__")],
    ) -> Any:
        return resolve_context_by_name(
            name=name,
            default=default,
            initial=initial,
            context=context,
        )

    return params.Depends(solve_context, use_cache=True)