Skip to content

import_from_string

faststream.cli.utils.imports.import_from_string #

import_from_string(import_str, *, is_factory=False)
Source code in faststream/cli/utils/imports.py
def import_from_string(
    import_str: str,
    *,
    is_factory: bool = False,
) -> Tuple[Path, "Application"]:
    module_path, instance = _import_obj_or_factory(import_str)

    if is_factory:
        if callable(instance):
            instance = instance()
        else:
            raise typer.BadParameter(f'"{instance}" is not a factory')

    if callable(instance) and not is_factory and not isinstance(instance, Application):
        raise typer.BadParameter("Please, use --factory option for callable object")

    return module_path, instance