utils.depends_on_optional()

Check if an optional dependency is installed.

Usage

Source

utils.depends_on_optional(
    module_name,
    install_hint=None,
)

Parameters

module_name: str

The name of the optional module to check for.

install_hint: str or None = None
Custom install instruction appended to the error message. If None, a generic message is used.

Returns

Callable[[Callable[P, T]], Callable[P, T]]
A decorator that wraps a function and raises ImportError if the specified module is not installed.

Raises

ImportError
If the optional dependency is not found when the decorated function is called.