kiara.kiara¶
Main module.
Kiara
¶
The core context of a kiara session.
The Kiara
object holds all information related to the current environment the user does works in. This includes:
- available modules, operations & pipelines
- available value types
- available metadata schemas
- available data items
- available controller and processor types
- misc. configuration options
It's possible to use kiara without ever manually touching the 'Kiara' class, by default all relevant classes and functions
will use a default instance of this class (available via the Kiara.instance()
method.
The Kiara class is highly dependent on the Python environment it lives in, because it auto-discovers available sub-classes of its building blocks (modules, value types, etc.). So, you can't assume that, for example, a pipeline you create will work the same way (or at all) in a different environment. kiara will always be able to tell you all the details of this environment, though, and it will attach those details to things like data, so there is always a record of how something was created, and in which environment.
available_module_types: List[str]
property
readonly
¶
Return the names of all available modules
available_non_pipeline_module_types: List[str]
property
readonly
¶
Return the names of all available pipeline-type modules.
available_pipeline_module_types: List[str]
property
readonly
¶
Return the names of all available pipeline-type modules.
config: KiaraConfig
property
readonly
¶
The configuration of this kiara environment.
default_processor: ModuleProcessor
property
readonly
¶
The default module processor that will be used in this environment, unless otherwise specified.
create_module(self, module_type, module_config=None, id=None, parent_id=None)
¶
Create a module instance.
The 'module_type' argument can be a module type id, or an operation id. In case of the latter, the 'real' module_type and module_config will be resolved via the operation management.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_type |
str |
the module type- or operation-id |
required |
module_config |
Optional[Mapping[str, Any]] |
the module instance configuration (must be empty in case of the module_type being an operation id |
None |
id |
Optional[str] |
the id of this module, only relevant if the module is part of a pipeline, in which case it must be unique within the pipeline |
None |
parent_id |
Optional[str] |
a reference to the pipeline that contains this module (if applicable) |
None |
Returns:
Type | Description |
---|---|
KiaraModule |
The instantiated module object. |
Source code in kiara/kiara.py
def create_module(
self,
module_type: str,
module_config: typing.Optional[typing.Mapping[str, typing.Any]] = None,
id: typing.Optional[str] = None,
parent_id: typing.Optional[str] = None,
) -> "KiaraModule":
"""Create a module instance.
The 'module_type' argument can be a module type id, or an operation id. In case of the latter, the 'real' module_type
and module_config will be resolved via the operation management.
Arguments:
module_type: the module type- or operation-id
module_config: the module instance configuration (must be empty in case of the module_type being an operation id
id: the id of this module, only relevant if the module is part of a pipeline, in which case it must be unique within the pipeline
parent_id: a reference to the pipeline that contains this module (if applicable)
Returns:
The instantiated module object.
"""
if module_type == "pipeline":
from kiara import PipelineModule
module = PipelineModule(
id=id, parent_id=parent_id, module_config=module_config, kiara=self
)
return module
elif (
module_type not in self.available_module_types
and module_type in self.operation_mgmt.operation_ids
):
op = self.operation_mgmt.get_operation(module_type)
assert op is not None
module_type = op.module_type
op_config = op.module_config
if not module_config:
_module_config: typing.Optional[
typing.Mapping[str, typing.Any]
] = op_config
else:
_module_config = dict(op_config)
_module_config.update(module_config)
elif (
module_type not in self.available_module_types
and isinstance(module_type, str)
and os.path.isfile(os.path.realpath(os.path.expanduser(module_type)))
):
if module_config:
raise Exception(
"Creating pipeline module from file with extra module_config not supported (yet)."
)
path = os.path.expanduser(module_type)
pipeline_config_data = get_data_from_file(path)
pipeline_config = PipelineConfig(**pipeline_config_data)
from kiara import PipelineModule
module = PipelineModule(
id=id, parent_id=parent_id, module_config=pipeline_config, kiara=self
)
return module
else:
_module_config = module_config
return self._module_mgr.create_module(
kiara=self,
id=id,
module_type=module_type,
module_config=_module_config,
parent_id=parent_id,
)
instance()
classmethod
¶
The default kiara context. In most cases, it's recommended you create and manage your own, though.
Source code in kiara/kiara.py
@classmethod
def instance(cls):
"""The default *kiara* context. In most cases, it's recommended you create and manage your own, though."""
if cls._instance is None:
cls._instance = Kiara()
return cls._instance
explain(item)
¶
Pretty print information about an item on the terminal.
Source code in kiara/kiara.py
def explain(item: typing.Any):
"""Pretty print information about an item on the terminal."""
if isinstance(item, type):
from kiara.module import KiaraModule
if issubclass(item, KiaraModule):
item = KiaraModuleTypeMetadata.from_module_class(module_cls=item)
elif isinstance(item, Value):
item.get_metadata()
console = get_console()
console.print(item)