importutils¶
Import related utilities and helper functions.
- oslo_utils.importutils.import_any(module: str, *modules: str) Any ¶
Try to import a module from a list of modules.
- Parameters:
modules – A list of modules to try and import
- Returns:
The first module found that can be imported
- Raises:
ImportError – If no modules can be imported from list
Added in version 3.8.
- oslo_utils.importutils.import_class(import_str: str) Any ¶
Returns a class from a string including module and class.
Added in version 0.3.
- oslo_utils.importutils.import_module(import_str: str) Any ¶
Import a module.
Added in version 0.3.
- oslo_utils.importutils.import_object(import_str: str, *args: Any, **kwargs: Any) Any ¶
Import a class and return an instance of it.
Added in version 0.3.
- oslo_utils.importutils.import_object_ns(name_space: str, import_str: str, *args: Any, **kwargs: Any) Any ¶
Tries to import object from default namespace.
Imports a class and return an instance of it, first by trying to find the class in a default namespace, then failing back to a full path if not found in the default namespace.
Added in version 0.3.
Changed in version 2.6: Don’t capture
ImportError
when instanciating the object, only when importing the object class.
- oslo_utils.importutils.import_versioned_module(module: str, version: str | int, submodule: str | None = None) Any ¶
Import a versioned module in format {module}.v{version][.{submodule}].
- Parameters:
module – the module name.
version – the version number.
submodule – the submodule name.
- Raises:
ValueError – For any invalid input.
Added in version 0.3.
Changed in version 3.17: Added module parameter.
- oslo_utils.importutils.try_import(import_str: str, default: Any = None) Any ¶
Try to import a module and if it fails return default.