prefect.utilities.importtools
Functions
to_qualified_name
obj
: an importable Python object
- the qualified name
from_qualified_name
name
: The fully-qualified name of the object to import.
- the imported object
load_script_as_module
prefect.exceptions.ScriptError
is created to wrap the exception and raised.
load_module
import_object
- module.object
- module:object
- /path/to/script.py:object
- module:object.method
- /path/to/script.py:object.method
lazy_import
lazy_import("docker.errors")
and import docker.errors
in the
same codebase will import docker.errors
twice and can lead to unexpected
behavior, e.g. type check failures and import-time side effects running
twice.
Adapted from the Python documentation and lazy_loader
safe_load_namespace
filepath
is provided, sys.path
is modified to support relative imports.
Changes to sys.path
are reverted after completion, but this function is not thread safe
and use of it in threaded contexts may result in undesirable behavior.
Args:
source_code
: The source code to loadfilepath
: Optional file path of the source code. If provided, enables relative imports.
- The namespace loaded from the source code.
Classes
DelayedImportErrorModule
A fake module returned by lazy_import
when the module cannot be found. When any
of the module’s attributes are accessed, we will throw a ModuleNotFoundError
.
Adapted from lazy_loader
AliasedModuleDefinition
A definition for the AliasedModuleFinder
.
Args:
alias
: The import name to createreal
: The import name of the module to reference for the aliascallback
: A function to call when the alias module is loaded