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, "FastStream"]:
    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')

    return module_path, instance