dlt.common.runtime.run_context
RunContext Objects
class RunContext(RunContextBase)
A default run context used by dlt
run_dir
@property
def run_dir() -> str
The default run dir is the current working directory but may be overridden by DLT_PROJECT_DIR env variable.
settings_dir
@property
def settings_dir() -> str
Returns a path to dlt settings directory. If not overridden it resides in current working directory
The name of the setting folder is '.dlt'. The path is current working directory '.' but may be overridden by DLT_PROJECT_DIR env variable.
get_run_entity
def get_run_entity(entity: str) -> str
Default run context assumes that entities are defined in root dir
switch_context
def switch_context(run_dir: Optional[str],
profile: str = None,
required: str = None,
validate: bool = False) -> RunContextBase
Switch the run context to a project at run_dir with an optional profile.
Calls reload on PluggableRunContext to re-trigger the plugin hook
(plug_run_context spec), which will query all active context plugins.
The required argument is passed to each context plugin via the
_required key of runtime_kwargs and should cause an exception if a
given plugin cannot instantiate its context at run_dir.
The validate argument is passed to each context plugin via the
_validate key of runtime_kwargs and should cause a strict validation
of any config files and manifests associated with the run context.
Arguments:
run_dirstr - Filesystem path of the project directory to activate. If None, plugins may resolve the directory themselves.profilestr - Profile name to activate for the run context.requiredstr, optional - A class name of the context be instantiated atrun_dirie. setting it toWorkspaceRunContextwill cause the workspace context plugin to raise if workspace is not found atrun_dir.validatestr, optional - If True, plugins should perform strict validation of config files and manifests associated with the run context.
Returns:
SupportsProfilesRunContext- The new run context.
switched_run_context
@contextmanager
def switched_run_context(new_context: RunContext) -> Iterator[RunContext]
Context manager that switches run context to new_context into pluggable run context.
global_dir
def global_dir() -> str
Gets default directory where pipelines' data (working directories) will be stored
- if XDG_DATA_HOME is set in env then it is used
- in user home directory: ~/.dlt/
- if current user is root: in /var/dlt/
- if current user does not have a home directory: in /tmp/dlt/
get_plugin_modules
def get_plugin_modules() -> List[str]
Return top level module names of all discovered plugins, including dlt.
If current run context is a top level module it is also included, otherwise empty string.
ensure_plugin_version_match
def ensure_plugin_version_match(
pkg_name: str,
dlt_version: str,
plugin_version: str,
plugin_module_name: str,
dlt_extra: str,
dlt_version_specifier: Optional[SpecifierSet] = None) -> None
Ensures that installed plugin version matches dlt requirements. Plugins are tightly bound
to dlt and released together.
If dlt_version_specifier is provided, it is used to check if the plugin version satisfies
the specifier. Otherwise, the specifier is read from dlt's package metadata (Requires-Dist).
If specifier cannot be determined, the function returns without checking.
Arguments:
pkg_name- Name of the plugin package (e.g., "dlthub")dlt_version- The installed dlt version stringplugin_version- The installed plugin version stringplugin_module_name- The module name for MissingDependencyException (e.g., "dlthub")dlt_extra- The dlt extra to install the plugin (e.g., "hub")dlt_version_specifier- Optional version specifier for the plugin. If not provided, reads from dlt's package metadata.
Raises:
MissingDependencyException- If version mismatch is detected
active
def active() -> RunContextBase
Returns currently active run context