def import_submodules(package, recursive=True):
if isinstance(package, str):<EOL><INDENT>package = importlib.import_module(package)<EOL><DEDENT>results = {}<EOL>for loader, name, is_pkg in pkgutil.walk_packages(package.__path__):<EOL><INDENT>full_name = package.__name__ + '<STR_LIT:.>' + name<EOL>results[full_name] = importlib.import_module(full_name)<EOL>if recursive and is_pkg:<EOL><INDENT>results.update(import_submodules(full_name))<EOL><DEDENT><DEDENT>return results<EOL>
Import all submodules of a module, recursively, including subpackages

    :param package: package (name or actual module)
    :type package: str | module
    :rtype: dict[str, types.ModuleType]