Skip to content

injector

Functions:

  • asynccontextmanager

    Inject dependencies into the given async context manager function.

  • asyncfunction

    Inject dependencies into the given coroutine.

  • asynciterator

    Inject dependencies into the given async iterator.

  • contextmanager

    Inject dependencies into the given context manager function.

  • function

    Inject dependencies into the given function.

  • iterator

    Inject dependencies into the given iterator.

Attributes:

  • required

    A sentinel object used to indicate that a dependency is required.

required module-attribute

required = make_sentinel_value(__name__, 'required')

A sentinel object used to indicate that a dependency is required.

Refer to the core concepts for more information.

asynccontextmanager

asynccontextmanager(
    func: AsyncIteratorCallable[P, R],
    *,
    requires: HintMap | HintSeq | None = None,
    scope: bool = False,
    hide_signature: bool = False
) -> Callable[P, AbstractAsyncContextManager[R]]

Inject dependencies into the given async context manager function.

Refer to the core concepts for more information.

Parameters:

  • func

    (AsyncIteratorCallable[P, R]) –

    The function to inject dependencies into.

  • requires

    (HintMap | HintSeq | None, default: None ) –

    The parameters and dependencies to inject. Otherwise infered from signature.

  • scope

    (bool, default: False ) –

    Whether injected values should be shared for the duration of the context.

  • hide_signature

    (bool, default: False ) –

    Whether to hide required parameters from the function signature.

asyncfunction

asyncfunction(
    func: Callable[P, Coroutine[Any, Any, R]],
    *,
    requires: HintMap | HintSeq | None = None,
    scope: bool = False,
    hide_signature: bool = False
) -> Callable[P, Coroutine[Any, Any, R]]

Inject dependencies into the given coroutine.

Refer to the core concepts for more information.

Parameters:

  • func

    (Callable[P, Coroutine[Any, Any, R]]) –

    The function to inject dependencies into.

  • requires

    (HintMap | HintSeq | None, default: None ) –

    The parameters and dependencies to inject. Otherwise infered from signature.

  • scope

    (bool, default: False ) –

    Whether injected values should be shared for the duration of any calls.

  • hide_signature

    (bool, default: False ) –

    Whether to hide required parameters from the function signature.

asynciterator

asynciterator(
    func: AsyncIteratorCallable[P, R],
    *,
    requires: HintMap | HintSeq | None = None,
    scope: bool = False,
    hide_signature: bool = False
) -> AsyncIteratorCallable[P, R]

Inject dependencies into the given async iterator.

Refer to the core concepts for more information.

Parameters:

  • func

    (AsyncIteratorCallable[P, R]) –

    The function to inject dependencies into.

  • requires

    (HintMap | HintSeq | None, default: None ) –

    The parameters and dependencies to inject. Otherwise infered from signature.

  • scope

    (bool, default: False ) –

    Whether injected values should be shared for the duration of any calls.

  • hide_signature

    (bool, default: False ) –

    Whether to hide required parameters from the function signature.

contextmanager

contextmanager(
    func: IteratorCallable[P, R],
    *,
    requires: HintMap | HintSeq | None = None,
    scope: bool = False,
    hide_signature: bool = False
) -> Callable[P, AbstractContextManager[R]]

Inject dependencies into the given context manager function.

Refer to the core concepts for more information.

Parameters:

  • func

    (IteratorCallable[P, R]) –

    The function to inject dependencies into.

  • requires

    (HintMap | HintSeq | None, default: None ) –

    The parameters and dependencies to inject. Otherwise infered from signature.

  • scope

    (bool, default: False ) –

    Whether injected values should be shared for the duration of the context.

  • hide_signature

    (bool, default: False ) –

    Whether to hide required parameters from the function signature.

function

function(
    func: Callable[P, R],
    *,
    requires: HintMap | HintSeq | None = None,
    scope: bool = False,
    hide_signature: bool = False
) -> Callable[P, R]

Inject dependencies into the given function.

Refer to the core concepts for more information.

Parameters:

  • func

    (Callable[P, R]) –

    The function to inject dependencies into.

  • requires

    (HintMap | HintSeq | None, default: None ) –

    The parameters and dependencies to inject. Otherwise infered from signature.

  • scope

    (bool, default: False ) –

    Whether injected values should be shared for the duration of any calls.

  • hide_signature

    (bool, default: False ) –

    Whether to hide required parameters from the function signature.

iterator

iterator(
    func: IteratorCallable[P, R],
    *,
    requires: HintMap | HintSeq | None = None,
    scope: bool = False,
    hide_signature: bool = False
) -> IteratorCallable[P, R]

Inject dependencies into the given iterator.

Refer to the core concepts for more information.

Parameters:

  • func

    (IteratorCallable[P, R]) –

    The function to inject dependencies into.

  • requires

    (HintMap | HintSeq | None, default: None ) –

    The parameters and dependencies to inject. Otherwise infered from signature.

  • scope

    (bool, default: False ) –

    Whether injected values should be shared for the duration of any calls.

  • hide_signature

    (bool, default: False ) –

    Whether to hide required parameters from the function signature.