Skip to content

omnipy.data.multi

Dataset variants that allow per-item model specialization.

This module defines :class:MultiModelDataset, a Dataset variant that still enforces one general dataset item type but can additionally assign more specific models to individual data-file keys.

CLASS DESCRIPTION
MultiModelDataset

Store typed dataset items with optional per-key model overrides.

MultiModelDataset

Bases: Dataset[_GeneralModelT], Generic[_GeneralModelT]


              flowchart BT
              omnipy.data.multi.MultiModelDataset[MultiModelDataset]
              omnipy.data.dataset.Dataset[Dataset]
              omnipy.data._mixins.display.DatasetDisplayMixin[DatasetDisplayMixin]
              omnipy.data._mixins.display.BaseDisplayMixin[BaseDisplayMixin]
              omnipy.data._mixins.task.TaskDatasetMixin[TaskDatasetMixin]
              omnipy.data._data_class_creator.DataClassBase[DataClassBase]

                              omnipy.data.dataset.Dataset --> omnipy.data.multi.MultiModelDataset
                                omnipy.data._mixins.display.DatasetDisplayMixin --> omnipy.data.dataset.Dataset
                                omnipy.data._mixins.display.BaseDisplayMixin --> omnipy.data._mixins.display.DatasetDisplayMixin
                

                omnipy.data._mixins.task.TaskDatasetMixin --> omnipy.data.dataset.Dataset
                
                omnipy.data._data_class_creator.DataClassBase --> omnipy.data.dataset.Dataset
                
                omnipy.util.pydantic.GenericModel --> omnipy.data.dataset.Dataset
                



              click omnipy.data.multi.MultiModelDataset href "" "omnipy.data.multi.MultiModelDataset"
              click omnipy.data.dataset.Dataset href "" "omnipy.data.dataset.Dataset"
              click omnipy.data._mixins.display.DatasetDisplayMixin href "" "omnipy.data._mixins.display.DatasetDisplayMixin"
              click omnipy.data._mixins.display.BaseDisplayMixin href "" "omnipy.data._mixins.display.BaseDisplayMixin"
              click omnipy.data._mixins.task.TaskDatasetMixin href "" "omnipy.data._mixins.task.TaskDatasetMixin"
              click omnipy.data._data_class_creator.DataClassBase href "" "omnipy.data._data_class_creator.DataClassBase"
            

Store typed dataset items with optional per-key model overrides.

MultiModelDataset extends :class:~omnipy.data.dataset.Dataset by allowing individual data-file keys to use custom models, while still requiring every item to satisfy the dataset's general model type. This is useful when most items share one schema but selected items need a stricter or more specialized model.

CLASS DESCRIPTION
Config

Configure Pydantic behavior for dataset instances.

METHOD DESCRIPTION
__init__
absorb

Merge another dataset's contents into this dataset.

absorb_and_replace

Replace this dataset's contents with another dataset's contents.

as_multi_model_dataset

Return a multi-model view of this dataset.

browse

Opens the model or dataset in a browser, if possible.

clone_dataset_cls

Create a new dataset subclass based on this dataset class.

copy

Copy the dataset.

deepcopy_context

Delegate nested deepcopy bookkeeping to the shared data-class creator.

default_repr_to_terminal_str

Render the default display panel as terminal text.

dict

Return the dataset backing mapping as a plain dictionary.

do

Apply a callable placeholder to each item and collect the results in a new dataset.

failed_task_details

Return failure marker payloads keyed by dataset entry name.

from_data

Populate the dataset and then enforce any per-key custom models.

from_json

Populate the dataset from per-item JSON strings.

full

Display the content of the Model or Dataset in full height.

get_model

Return the model currently used for a data-file key.

get_type

Return the concrete item type stored by this dataset class.

json

Preview the data content of the Model or Dataset as JSON.

list

Displays a summary list of all models in the dataset.

load

Create a dataset and load serialized contents into it.

load_into

Load serialized contents into this dataset instance.

peek

Display a preview of the Model or Dataset content.

pending_task_details

Return pending task marker payloads keyed by dataset entry name.

save

Serialize the dataset to a .tar.gz archive and extract a directory copy.

set_model

Assign a custom model to one data-file key.

to

Convert this dataset to another model or dataset class.

to_data

Return the dataset as plain Python contents.

to_json

Serialize each dataset item to JSON.

to_json_schema

Return a JSON schema for the dataset's serialized contents.

update_forward_refs

Try to update ForwardRefs on fields based on this Model, globalns and localns.

update_reactive_views
validate

Validate arbitrary input as an instance of this dataset class.

ATTRIBUTE DESCRIPTION
available_data

Return a same-type copy containing only successfully available data entries.

TYPE: Self

config

Return the data configuration shared by the owning data-class family.

TYPE: IsDataConfig

data

TYPE: dict_t[str, _ModelOrDatasetT]

failed_data

Return a same-type copy containing only entries whose producing task failed.

TYPE: Self

pending_data

Return a same-type copy containing only entries still waiting on task results.

TYPE: Self

reactive_objects

Return the reactive-object registry attached to this data-class family.

TYPE: IsReactiveObjects | None

snapshot_holder

Return the snapshot holder coordinating copy-based change tracking.

TYPE: IsSnapshotHolder[HasContent, ContentT]

Source code in src/omnipy/data/multi.py
class MultiModelDataset(Dataset[_GeneralModelT], Generic[_GeneralModelT]):
    """Store typed dataset items with optional per-key model overrides.

    ``MultiModelDataset`` extends :class:`~omnipy.data.dataset.Dataset` by allowing individual
    data-file keys to use custom models, while still requiring every item to satisfy the dataset's
    general model type. This is useful when most items share one schema but selected items need a
    stricter or more specialized model.
    """

    # Custom field models should really be a subtype of _GeneralModelT,
    # however this is currently not checkable in the type system. Instead,
    # we rely on the _validate method to ensure that the custom field
    # models are valid.

    _custom_field_models: 'dict[str, type[Model]]' = pyd.PrivateAttr(default={})

    def set_model(self, data_file: str, model: 'type[Model]') -> None:
        """Assign a custom model to one data-file key.

        Args:
            data_file: Dataset key that should use the custom model.
            model: Model class to validate that key against.

        Raises:
            ValidationError: If the existing item for the key does not satisfy the custom model.
        """
        try:
            self._custom_field_models[data_file] = model
            if data_file in self.data:
                self._validate_data_file(data_file)
            else:
                self.data[data_file] = model()
        except ValidationError:
            del self._custom_field_models[data_file]
            raise

    def get_model(self, data_file: str) -> type[Model]:
        """Return the model currently used for a data-file key.

        Args:
            data_file: Dataset key to inspect.

        Returns:
            The custom model for the key, or the dataset's general model when no override exists.
        """
        if data_file in self._custom_field_models:
            return self._custom_field_models[data_file]
        else:
            return self.get_type()

    def from_data(self,
                  data: Mapping[str, Any] | Iterable[tuple[str, Any]],
                  update: bool = True) -> None:
        """Populate the dataset and then enforce any per-key custom models.

        Args:
            data: Mapping or iterable of ``(key, value)`` pairs to parse into validated items.
            update: Whether to merge into existing contents instead of replacing them first.
        """
        super().from_data(data, update)
        for data_file in self:
            self._validate_data_file_according_to_custom_field_model(data_file)
        self._force_full_validation()

    def _validate_data_file(self, data_file: str) -> None:
        self._validate_data_file_according_to_custom_field_model(data_file)
        self._force_full_validation()

    def _validate_data_file_according_to_custom_field_model(self, data_file: str):
        from omnipy.data.model import is_model_instance, Model

        if data_file in self._custom_field_models:
            model = self._custom_field_models[data_file]
            if not is_model_instance(model):
                model = Model[model]
            data_obj = self._to_data_if_model(self.data[data_file])
            parsed_data = self._to_data_if_model(model(data_obj))
            self.data[data_file] = parsed_data

    @staticmethod
    def _to_data_if_model(data_obj: Any):
        from omnipy.data.model import is_model_instance

        if is_model_instance(data_obj):
            data_obj = data_obj.to_data()
        return data_obj

available_data property

available_data: Self

Return a same-type copy containing only successfully available data entries.

config property

config: IsDataConfig

Return the data configuration shared by the owning data-class family.

RETURNS DESCRIPTION
IsDataConfig

Shared configuration object used by related models and datasets.

TYPE: IsDataConfig

data class-attribute instance-attribute

data: dict_t[str, _ModelOrDatasetT] = pyd.Field(default={})

failed_data property

failed_data: Self

Return a same-type copy containing only entries whose producing task failed.

pending_data property

pending_data: Self

Return a same-type copy containing only entries still waiting on task results.

reactive_objects property

reactive_objects: IsReactiveObjects | None

Return the reactive-object registry attached to this data-class family.

snapshot_holder property

Return the snapshot holder coordinating copy-based change tracking.

Config

Configure Pydantic behavior for dataset instances.

The nested config enables assignment-time validation and permits arbitrary runtime types needed by Omnipy's dataset internals.

ATTRIBUTE DESCRIPTION
validate_assignment

Re-validate fields whenever attributes are reassigned.

arbitrary_types_allowed

Permit non-Pydantic helper types in the model definition.

Source code in src/omnipy/data/dataset.py
class Config:
    """Configure Pydantic behavior for dataset instances.

    The nested config enables assignment-time validation and permits arbitrary runtime types
    needed by Omnipy's dataset internals.

    Attributes:
        validate_assignment: Re-validate fields whenever attributes are reassigned.
        arbitrary_types_allowed: Permit non-Pydantic helper types in the model definition.
    """
    validate_assignment = True
    arbitrary_types_allowed = True

arbitrary_types_allowed class-attribute instance-attribute

arbitrary_types_allowed = True

validate_assignment class-attribute instance-attribute

validate_assignment = True

__init__

__init__(
    value: Mapping[str, object] | Iterable[tuple[str, object]] | UndefinedType = Undefined,
    *,
    data: Mapping[str, object] | UndefinedType = Undefined,
    **kwargs: object,
) -> None
Source code in src/omnipy/data/dataset.py
def __init__(  # noqa: C901
    self,
    value: Mapping[str, object] | Iterable[tuple[str, object]] | UndefinedType = Undefined,
    *,
    data: Mapping[str, object] | UndefinedType = Undefined,
    **kwargs: object,
) -> None:
    from omnipy.data.model import is_model_instance, is_pure_pydantic_model

    # TODO: Error message when forgetting parenthesis when creating Dataset should be improved.
    #       Unclear where this can be done, if anywhere? E.g.:
    #           a = Dataset[Model[int]]
    #           a['adsfas'] = 2
    #           Traceback (most recent call last):
    #             ...
    #           TypeError: 'ModelMetaclass' object does not support item assignment
    #
    # TODO: Disallow e.g.:
    #       Dataset[Model[str]](Model[int](5)) ==  Dataset[Model[str]](data=Model[int](5))
    #       == Dataset[Model[str]](data={'__root__': Model[str]('5')})

    super_kwargs = {}

    assert DATA_KEY not in kwargs, \
        ('Not allowed with "data" as kwargs key. Not sure how you managed this? Are you trying '
         'to break Dataset init on purpose?')

    if value != Undefined:
        assert data == Undefined, \
            'Not allowed to combine positional and "data" keyword argument'
        assert len(kwargs) == 0, \
            'Not allowed to combine positional and keyword arguments'
        super_kwargs[DATA_KEY] = value

    if data != Undefined:
        assert len(kwargs) == 0, \
            f"Not allowed to combine '{DATA_KEY}' with other keyword arguments"
        super_kwargs[DATA_KEY] = data

    if kwargs:
        if DATA_KEY not in super_kwargs:
            super_kwargs[DATA_KEY] = kwargs
            kwargs = {}

    _type = self.get_type()
    if _type == _ModelOrDatasetT:  # type: ignore[misc]
        self._raise_type_exception()

    def _validate_any_models_or_datasets(
            iterable_data: Iterable[tuple[str, object]]) -> tuple[dict, bool]:
        """Validate model or dataset instances found in iterable input data.

        Args:
            iterable_data: Iterable of ``(key, value)`` pairs supplied to dataset
                initialization.

        Returns:
            A tuple containing the prepared mapping and a flag indicating whether any input
            values were already model or dataset instances.
        """

        prepared_data = {}
        _model_or_dataset_as_input: bool = False

        for key, val in iterable_data:
            if is_model_instance(val):
                _model_or_dataset_as_input = True
                prepared_data[key] = self._validate_value_for_data_file(key, val)
            else:
                prepared_data[key] = val
        return prepared_data, _model_or_dataset_as_input

    model_or_dataset_as_input = False
    if DATA_KEY in super_kwargs:
        input_data = super_kwargs[DATA_KEY]
        for_type_check = input_data.content if is_model_instance(input_data) else input_data
        match for_type_check:
            case Dataset():
                model_or_dataset_as_input = True
                super_kwargs[DATA_KEY] = cast(Dataset, input_data).to_data()
            case _input_data if is_pure_pydantic_model(_input_data):
                super_kwargs[DATA_KEY], model_or_dataset_as_input = (
                    _validate_any_models_or_datasets(_input_data.dict().items()))
            case Mapping():
                super_kwargs[DATA_KEY], model_or_dataset_as_input = (
                    _validate_any_models_or_datasets(cast(Mapping, input_data).items()))
            case Iterable():
                try:
                    super_kwargs[DATA_KEY], model_or_dataset_as_input = (
                        _validate_any_models_or_datasets(self._check_iterable(input_data)))
                except (TypeError, ValueError) as e:
                    raise TypeError(
                        'Data object must be a mapping or an iterable of '
                        '(key, val) pairs',
                        self.__class__) from e

            case _:
                ...

    self._init(super_kwargs, **kwargs)

    try:
        self._primary_validation(super_kwargs)
    except ValidationError:
        if model_or_dataset_as_input:
            self._secondary_validation_from_data(super_kwargs)
        else:
            raise

    if not self.__doc__:
        self._set_standard_field_description()

absorb

absorb(other: Dataset)

Merge another dataset's contents into this dataset.

PARAMETER DESCRIPTION
other

Dataset whose plain-Python contents should be added or overwrite matching keys.

TYPE: Dataset

Source code in src/omnipy/data/dataset.py
def absorb(self, other: 'Dataset'):
    """Merge another dataset's contents into this dataset.

    Args:
        other: Dataset whose plain-Python contents should be added or overwrite matching keys.
    """
    self.from_data(other.to_data(), update=True)

absorb_and_replace

absorb_and_replace(other: Dataset)

Replace this dataset's contents with another dataset's contents.

PARAMETER DESCRIPTION
other

Dataset whose contents should replace the current contents.

TYPE: Dataset

Source code in src/omnipy/data/dataset.py
def absorb_and_replace(self, other: 'Dataset'):
    """Replace this dataset's contents with another dataset's contents.

    Args:
        other: Dataset whose contents should replace the current contents.
    """
    self.from_data(other.to_data(), update=False)

as_multi_model_dataset

as_multi_model_dataset() -> IsMultiModelDataset[_ModelOrDatasetT]

Return a multi-model view of this dataset.

RETURNS DESCRIPTION
IsMultiModelDataset[_ModelOrDatasetT]

A MultiModelDataset initialized with the same item type and current contents.

Source code in src/omnipy/data/dataset.py
def as_multi_model_dataset(self) -> 'IsMultiModelDataset[_ModelOrDatasetT]':
    """Return a multi-model view of this dataset.

    Returns:
        A ``MultiModelDataset`` initialized with the same item type and current contents.
    """
    from omnipy.data.multi import MultiModelDataset

    multi_model_dataset = MultiModelDataset[self.get_type()]()
    for data_file in self:
        multi_model_dataset.data[data_file] = self.data[data_file]
    return multi_model_dataset

browse

browse(
    *,
    width: pyd.NonNegativeInt | None = None,
    height: pyd.NonNegativeInt | None = None,
    tab: pyd.NonNegativeInt = 4,
    indent: pyd.NonNegativeInt = 2,
    printer: PrettyPrinterLib.Literals = "auto",
    syntax: SyntaxLanguageSpec.Literals | str = "auto",
    freedom: pyd.NonNegativeFloat | None = 2.5,
    debug: bool = False,
    ui: UserInterfaceType.Literals = "auto",
    system: DisplayColorSystem.Literals = "auto",
    style: AllColorStyles.Literals | str = "auto",
    dark: typing.Literal["auto", True, False] = "auto",
    bg: bool = False,
    fonts: tuple[str, ...] = ("Menlo", "DejaVu Sans Mono", "Consolas", "Courier New", "monospace"),
    font_size: pyd.NonNegativeFloat | None = 14,
    font_weight: pyd.NonNegativeInt | None = 400,
    line_height: pyd.NonNegativeFloat | None = 1.25,
    h_overflow: HorizontalOverflowMode.Literals = "ellipsis",
    v_overflow: VerticalOverflowMode.Literals = "ellipsis_bottom",
    panel: PanelDesign.Literals = "table",
    title_at_top: bool = True,
    max_title_height: MaxTitleHeight.Literals = -1,
    min_panel_width: pyd.NonNegativeInt = 3,
    min_crop_width: pyd.NonNegativeInt = 33,
    use_min_crop_width: bool = False,
    max_panels_hor: pyd.NonNegativeInt | None = 9,
    max_nesting_depth: pyd.NonNegativeInt | None = 3,
    justify: Justify.Literals = "left",
) -> None

Opens the model or dataset in a browser, if possible.

For models, this is a detailed view of the model's content, and for datasets this is a detailed view of each model contained in the dataset, one model per browser tab.

PARAMETER DESCRIPTION
width

Width in characters of the output area (None for auto-detect based on available display dimensions).

TYPE: NonNegativeInt | None DEFAULT: None

height

Height in lines of the output area (None for auto-detect based on available display dimensions).

TYPE: NonNegativeInt | None DEFAULT: None

tab

Number of spaces to use for each tab.

TYPE: NonNegativeInt DEFAULT: 4

indent

Number of spaces to use for each indentation level.

TYPE: NonNegativeInt DEFAULT: 2

printer

Library to use for pretty printing.

TYPE: PrettyPrinterLib.Literals DEFAULT: 'auto'

syntax

Syntax language for code highlighting. Supported lexers are defined in SyntaxLanguageSpec. For non-supported styles, the user can specify a string with the Pygments lexer name. For this to work, the lexer must be registered in the Pygments library.

TYPE: SyntaxLanguageSpec.Literals | str DEFAULT: 'auto'

freedom

Parameter that controls the level of freedom for formatted text to follow the geometry of the frame size (=total available area) in a proportional manner. If the proportional freedom is 0 (the lowest), then the output area must not in any case be proportionally wider that the frame (i.e. a 16/9 frame will only produce output that is 16/9 or narrower). Larger values of proportional freedom allow the output to be proportionally wider than the total available frame, to a degree that relates to the size difference between the frame and the content (larger difference gives more freedom). The default value of 2.5 is a good compromise between readability/aesthetics and good use of the screen estate. If None, the freedom is unlimited (i.e. proportionality is not taken into account at all).

TYPE: float | None DEFAULT: 2.5

debug

When True, enables additional debugging information in the output, such as the hierarchy of the Model objects. Currently, only Python pretty printers support debug=True. Hence, enabling debug mode will automatically set the printer to the default Python pretty printer if the printer config value is not already set.

TYPE: bool DEFAULT: False

ui

Type of user interface for which the output should being prepared. The user interface describes the technical solutions available for interacting with the user, encompassing the support available for displaying output as well as how the user interacts with the library (including the type of interactive interpreter used, if any).

TYPE: UserInterfaceType.Literals DEFAULT: 'auto'

system

Color system to use for terminal output. The default is AUTO, which automatically detects the color system based on particular environment variables. If color capabilities are not detected, the output will be in black and white. If the color system of a modern consoles/terminal is not auto-detected (which is the case for e.g. the PyCharm console), the user might want to set the color system manually to ANSI_RGB to force color output.

TYPE: ColorSystem.Literals DEFAULT: 'auto'

style

Color style/theme for syntax highlighting and other display elements. Supported styles are defined in AllColorStyles. For non-supported styles, the user can specify a string with the Pygments style name. For this to work, the style must be registered in the Pygments library. If style is AUTO or any of the other RecommendedColorStyles, the style is automatically selected from the RecommendedColorStyles based on the detected user interface, the color system, and whether the background is dark or not.

TYPE: AllColorStyles.Literals | str DEFAULT: 'auto'

dark

Whether the background color of the output is dark. This is used to determine the appropriate color scheme for syntax highlighting. The default is AUTO, which automatically tries to detect whether the background is dark. Capability of auto-detection depends on the user interface.

TYPE: DarkBackground.Literals DEFAULT: 'auto'

bg

If False, uses transparent background for the output. In the case of terminal output, the background color will be the current background color of the terminal. For HTML output, the background color will be automatically set to pure black or pure white, depending on the luminosity of the foreground color.

TYPE: bool DEFAULT: False

fonts

Font families to use in HTML output, in order of preference (empty tuple for browser default).

TYPE: Tuple[str, ...] DEFAULT: ('Menlo', 'DejaVu Sans Mono', 'Consolas', 'Courier New', 'monospace')

font_size

Font size in pixels for HTML output (None for browser default).

TYPE: NonNegativeFloat | None DEFAULT: 14

font_weight

Font weight for HTML output (None for browser default).

TYPE: NonNegativeInt | None DEFAULT: 400

line_height

Line height multiplier for HTML output (None for browser default).

TYPE: NonNegativeFloat | None DEFAULT: 1.25

h_overflow

How to handle text that exceeds the width.

TYPE: HorizontalOverflowMode.Literals DEFAULT: 'ellipsis'

v_overflow

How to handle text that exceeds the height.

TYPE: VerticalOverflowMode.Literals DEFAULT: 'ellipsis_bottom'

panel

Visual design of the panel used as container for the output. Only TABLE is currently supported, which displays the output in a table-like grid.

TYPE: PanelDesign.Literals DEFAULT: 'table'

title_at_top

Whether panel titles will be displayed over the panel content (True) or below the content (False)

TYPE: bool DEFAULT: True

max_title_height

Maximum height of the panel title. If AUTO, the height is determined by the content of the title, up to a maximum of two lines. If ZERO, the title is not displayed at all. If ONE or TWO, the title is displayed with a fixed height of max one or two lines, respectively.

TYPE: MaxTitleHeight.Literals DEFAULT: -1

min_panel_width

Minimum width in characters per panel.

TYPE: NonNegativeInt DEFAULT: 3

min_crop_width

Minimum cropping width in characters for panels in cases where more than one panel are to be displayed. This is for instance used to calculate the number of models to display in a Dataset peek(). Only applied if use_min_crop_width is set to True. min_crop_width must be equal to or larger than min_panel_width.

TYPE: NonNegativeInt DEFAULT: 33

use_min_crop_width

Whether the min_crop_width value should be considered in cases where more than one panel are to be displayed, potentially reducing the number of displayed panels.

TYPE: bool DEFAULT: False

max_panels_hor

Maximum number of panels to display horizontally side-by-side at the top level. This value also acts as a ceiling for nested panels; nested panels cannot exceed this limit even if the constant MAX_PANELS_HORIZONTALLY_DEEPLY_NESTED is set to a higher value. If None, there is no limit.

TYPE: NonNegativeInt | None DEFAULT: 9

max_nesting_depth

Maximum levels of nested panels to display. If None, there is no limit.

TYPE: NonNegativeInt | None DEFAULT: 3

justify

Justification mode for the panel if inside a layout panel. This is only used for the panel content.

TYPE: Justify.Literals DEFAULT: 'left'

Source code in src/omnipy/data/_mixins/display.py
def browse(self, **kwargs) -> None:
    # %% Original docstring (managed by expand_docstr_macros.py) %%
    # {{BROWSE_SUMMARY}}
    #
    # {{BROWSE_DESCRIPTION}}
    #
    # {{DISPLAY_METHOD_ARGS}}
    #
    """Opens the model or dataset in a browser, if possible.

    For models, this is a detailed view of the model's content,
    and for datasets this is a detailed view of each model
    contained in the dataset, one model per browser tab.

    Args:
        width (NonNegativeInt | None):
            Width in characters of the output area (None for
            auto-detect based on available display dimensions).
        height (NonNegativeInt | None):
            Height in lines of the output area (None for
            auto-detect based on available display dimensions).
        tab (NonNegativeInt):
            Number of spaces to use for each tab.
        indent (NonNegativeInt):
            Number of spaces to use for each indentation level.
        printer (PrettyPrinterLib.Literals):
            Library to use for pretty printing.
        syntax (SyntaxLanguageSpec.Literals | str):
            Syntax language for code highlighting. Supported
            lexers are defined in SyntaxLanguageSpec. For
            non-supported styles, the user can specify a string
            with the Pygments lexer name. For this to work, the
            lexer must be registered in the Pygments library.
        freedom (float | None):
            Parameter that controls the level of freedom for
            formatted text to follow the geometry of the frame
            size (=total available area) in a proportional manner.
            If the proportional freedom is 0 (the lowest), then
            the output area must not in any case be proportionally
            wider that the frame (i.e. a 16/9 frame will only
            produce output that is 16/9 or narrower). Larger
            values of proportional freedom allow the output to be
            proportionally wider than the total available frame,
            to a degree that relates to the size difference
            between the frame and the content (larger difference
            gives more freedom). The default value of 2.5 is a
            good compromise between readability/aesthetics and
            good use of the screen estate. If None, the freedom is
            unlimited (i.e. proportionality is not taken into
            account at all).
        debug (bool):
            When True, enables additional debugging information in
            the output, such as the hierarchy of the Model
            objects. Currently, only Python pretty printers support
            debug=True. Hence, enabling debug mode will
            automatically set the printer to the default Python
            pretty printer if the `printer` config value is not
            already set.
        ui (UserInterfaceType.Literals):
            Type of user interface for which the output should
            being prepared. The user interface describes the
            technical solutions available for interacting with the
            user, encompassing the support available for
            displaying output as well as how the user interacts
            with the library (including the type of interactive
            interpreter used, if any).
        system (ColorSystem.Literals):
            Color system to use for terminal output. The default
            is `AUTO`, which automatically detects the color
            system based on particular environment variables. If
            color capabilities are not detected, the output will
            be in black and white. If the color system of a modern
            consoles/terminal is not auto-detected (which is the
            case for e.g. the PyCharm console), the user might
            want to set the color system manually to ANSI_RGB to
            force color output.
        style (AllColorStyles.Literals | str):
            Color style/theme for syntax highlighting and other
            display elements. Supported styles are defined in
            AllColorStyles. For non-supported styles, the user can
            specify a string with the Pygments style name. For this to
            work, the style must be registered in the Pygments
            library. If style is `AUTO` or any of the other
            RecommendedColorStyles, the style is automatically
            selected from the RecommendedColorStyles based on the
            detected user interface, the color system, and whether the
            background is dark or not.
        dark (DarkBackground.Literals):
            Whether the background color of the output is dark.
            This is used to determine the appropriate color scheme
            for syntax highlighting. The default is AUTO, which
            automatically tries to detect whether the background
            is dark. Capability of auto-detection depends on the
            user interface.
        bg (bool):
            If False, uses transparent background for the output.
            In the case of terminal output, the background color
            will be the current background color of the terminal.
            For HTML output, the background color will be
            automatically set to pure black or pure white,
            depending on the luminosity of the foreground color.
        fonts (Tuple[str, ...]):
            Font families to use in HTML output, in order of
            preference (empty tuple for browser default).
        font_size (NonNegativeFloat | None):
            Font size in pixels for HTML output (None for browser
            default).
        font_weight (NonNegativeInt | None):
            Font weight for HTML output (None for browser
            default).
        line_height (NonNegativeFloat | None):
            Line height multiplier for HTML output (None for
            browser default).
        h_overflow (HorizontalOverflowMode.Literals):
            How to handle text that exceeds the width.
        v_overflow (VerticalOverflowMode.Literals):
            How to handle text that exceeds the height.
        panel (PanelDesign.Literals):
            Visual design of the panel used as container for the
            output. Only `TABLE` is currently supported, which
            displays the output in a table-like grid.
        title_at_top (bool):
            Whether panel titles will be displayed over the panel
            content (True) or below the content (False)
        max_title_height (MaxTitleHeight.Literals):
            Maximum height of the panel title. If `AUTO`, the
            height is determined by the content of the title, up
            to a maximum of two lines. If `ZERO`, the title is not
            displayed at all. If `ONE` or `TWO`, the title is
            displayed with a fixed height of max one or two lines,
            respectively.
        min_panel_width (NonNegativeInt):
            Minimum width in characters per panel.
        min_crop_width (NonNegativeInt):
            Minimum cropping width in characters for panels in
            cases where more than one panel are to be displayed.
            This is for instance used to calculate the number of
            models to display in a Dataset peek(). Only applied if
            `use_min_crop_width` is set to `True`.
            `min_crop_width` must be equal to or larger than
            `min_panel_width`.
        use_min_crop_width (bool):
            Whether the `min_crop_width` value should be
            considered in cases where more than one panel are to
            be displayed, potentially reducing the number of
            displayed panels.
        max_panels_hor (NonNegativeInt | None):
            Maximum number of panels to display horizontally
            side-by-side at the top level. This value also acts as
            a ceiling for nested panels; nested panels cannot
            exceed this limit even if the constant
            `MAX_PANELS_HORIZONTALLY_DEEPLY_NESTED` is set to a
            higher value. If None, there is no limit.
        max_nesting_depth (NonNegativeInt | None):
            Maximum levels of nested panels to display. If None,
            there is no limit.
        justify (Justify.Literals):
            Justification mode for the panel if inside a layout
            panel. This is only used for the panel content.
    """
    self._browse(**kwargs)

clone_dataset_cls classmethod

clone_dataset_cls(
    new_dataset_cls_name: str, model_cls: type[_NewModelT] | None = None
) -> type[Self]

Create a new dataset subclass based on this dataset class.

PARAMETER DESCRIPTION
new_dataset_cls_name

Name of the generated dataset subclass.

TYPE: str

model_cls

Optional replacement item model for the generated subclass.

TYPE: type[_NewModelT] | None DEFAULT: None

RETURNS DESCRIPTION
type[Self]

A newly created dataset subclass.

Source code in src/omnipy/data/dataset.py
@classmethod
def clone_dataset_cls(cls,
                      new_dataset_cls_name: str,
                      model_cls: type[_NewModelT] | None = None) -> type[Self]:
    """Create a new dataset subclass based on this dataset class.

    Args:
        new_dataset_cls_name: Name of the generated dataset subclass.
        model_cls: Optional replacement item model for the generated subclass.

    Returns:
        A newly created dataset subclass.
    """
    if model_cls:
        generic_dataset_cls = cls.__bases__[0]
        new_base_cls = generic_dataset_cls[model_cls]  # type: ignore[index]
    else:
        new_base_cls = cls

    new_dataset_cls = type(new_dataset_cls_name, (new_base_cls,), {})
    return new_dataset_cls

copy

copy(*, deep: bool = False, **kwargs) -> Self

Copy the dataset.

PARAMETER DESCRIPTION
deep

Whether to deep-copy nested values as well as the dataset object.

TYPE: bool DEFAULT: False

**kwargs

Additional keyword arguments forwarded to Pydantic's copy().

DEFAULT: {}

RETURNS DESCRIPTION
Self

A copied dataset instance of the same specialized class.

Source code in src/omnipy/data/dataset.py
def copy(self, *, deep: bool = False, **kwargs) -> Self:
    """Copy the dataset.

    Args:
        deep: Whether to deep-copy nested values as well as the dataset object.
        **kwargs: Additional keyword arguments forwarded to Pydantic's ``copy()``.

    Returns:
        A copied dataset instance of the same specialized class.
    """
    pydantic_copy = pyd.GenericModel.copy(self, deep=deep, **kwargs)
    if not deep:
        object.__setattr__(pydantic_copy, DATA_KEY, pydantic_copy.__dict__[DATA_KEY].copy())

    return pydantic_copy  # pyright: ignore [reportReturnType]

deepcopy_context

deepcopy_context(
    top_level_entry_func: Callable[[], None], top_level_exit_func: Callable[[], None]
) -> ContextManager[int]

Delegate nested deepcopy bookkeeping to the shared data-class creator.

PARAMETER DESCRIPTION
top_level_entry_func

Callback run when entering the outermost deepcopy context.

TYPE: Callable[[], None]

top_level_exit_func

Callback run when leaving the outermost deepcopy context.

TYPE: Callable[[], None]

RETURNS DESCRIPTION
ContextManager[int]

A context manager yielding the current deepcopy nesting depth.

Source code in src/omnipy/data/_data_class_creator.py
def deepcopy_context(
    self,
    top_level_entry_func: Callable[[], None],
    top_level_exit_func: Callable[[], None],
) -> ContextManager[int]:
    """Delegate nested deepcopy bookkeeping to the shared data-class creator.

    Args:
        top_level_entry_func: Callback run when entering the outermost deepcopy context.
        top_level_exit_func: Callback run when leaving the outermost deepcopy context.

    Returns:
        A context manager yielding the current deepcopy nesting depth.
    """

    return self.__class__.data_class_creator.deepcopy_context(top_level_entry_func,
                                                              top_level_exit_func)

default_repr_to_terminal_str

default_repr_to_terminal_str(ui_type: TerminalOutputUserInterfaceType.Literals) -> str

Render the default display panel as terminal text.

PARAMETER DESCRIPTION
ui_type

Terminal-oriented user interface to render for.

TYPE: TerminalOutputUserInterfaceType.Literals

RETURNS DESCRIPTION
str

The fully rendered string representation for repr()-style terminal output.

Source code in src/omnipy/data/_mixins/display.py
def default_repr_to_terminal_str(
    self,
    ui_type: TerminalOutputUserInterfaceType.Literals,
) -> str:
    """Render the default display panel as terminal text.

    Args:
        ui_type: Terminal-oriented user interface to render for.

    Returns:
        The fully rendered string representation for ``repr()``-style
        terminal output.
    """
    return self._display_according_to_ui_type(
        ui_type=ui_type,
        return_output_if_str=True,
        output_method=self._default_panel,
    )

dict

dict(**kwargs) -> dict_t[str, Any]

Return the dataset backing mapping as a plain dictionary.

PARAMETER DESCRIPTION
**kwargs

Keyword arguments forwarded to Pydantic's dict() implementation.

DEFAULT: {}

RETURNS DESCRIPTION
dict_t[str, Any]

The serialized value of the dataset's data field.

Source code in src/omnipy/data/dataset.py
def dict(self, **kwargs) -> dict_t[str, Any]:
    """Return the dataset backing mapping as a plain dictionary.

    Args:
        **kwargs: Keyword arguments forwarded to Pydantic's ``dict()`` implementation.

    Returns:
        The serialized value of the dataset's ``data`` field.
    """
    return super().dict(**kwargs)[DATA_KEY]

do

do(placeholder: F) -> Dataset[_ModelOrDatasetT]

Apply a callable placeholder to each item and collect the results in a new dataset.

PARAMETER DESCRIPTION
placeholder

Callable wrapper used to transform each validated dataset item.

TYPE: F

RETURNS DESCRIPTION
Dataset[_ModelOrDatasetT]

A new dataset of the same class containing the transformed items.

Source code in src/omnipy/data/dataset.py
def do(self, placeholder: F) -> 'Dataset[_ModelOrDatasetT]':
    """Apply a callable placeholder to each item and collect the results in a new dataset.

    Args:
        placeholder: Callable wrapper used to transform each validated dataset item.

    Returns:
        A new dataset of the same class containing the transformed items.
    """
    new_dataset = self.__class__()
    for data_file, val in self.items():
        new_dataset[data_file] = placeholder(val)
    return new_dataset

failed_task_details

failed_task_details() -> dict[str, IsFailedData]

Return failure marker payloads keyed by dataset entry name.

Source code in src/omnipy/data/_mixins/task.py
def failed_task_details(self) -> dict[str, IsFailedData]:
    """Return failure marker payloads keyed by dataset entry name."""

    self_with_data = cast(HasData, self)
    return {  # pyright: ignore [reportReturnType]
        key: val for key, val in self_with_data.data.items() if isinstance(val, FailedData)
    }

from_data

from_data(data: Mapping[str, Any] | Iterable[tuple[str, Any]], update: bool = True) -> None

Populate the dataset and then enforce any per-key custom models.

PARAMETER DESCRIPTION
data

Mapping or iterable of (key, value) pairs to parse into validated items.

TYPE: Mapping[str, Any] | Iterable[tuple[str, Any]]

update

Whether to merge into existing contents instead of replacing them first.

TYPE: bool DEFAULT: True

Source code in src/omnipy/data/multi.py
def from_data(self,
              data: Mapping[str, Any] | Iterable[tuple[str, Any]],
              update: bool = True) -> None:
    """Populate the dataset and then enforce any per-key custom models.

    Args:
        data: Mapping or iterable of ``(key, value)`` pairs to parse into validated items.
        update: Whether to merge into existing contents instead of replacing them first.
    """
    super().from_data(data, update)
    for data_file in self:
        self._validate_data_file_according_to_custom_field_model(data_file)
    self._force_full_validation()

from_json

from_json(data: Mapping[str, str] | Iterable[tuple[str, str]], update: bool = True) -> None

Populate the dataset from per-item JSON strings.

PARAMETER DESCRIPTION
data

Mapping or iterable of (key, json_string) pairs.

TYPE: Mapping[str, str] | Iterable[tuple[str, str]]

update

Whether to merge into existing contents instead of replacing them first.

TYPE: bool DEFAULT: True

Source code in src/omnipy/data/dataset.py
def from_json(self,
              data: Mapping[str, str] | Iterable[tuple[str, str]],
              update: bool = True) -> None:
    """Populate the dataset from per-item JSON strings.

    Args:
        data: Mapping or iterable of ``(key, json_string)`` pairs.
        update: Whether to merge into existing contents instead of replacing them first.
    """
    def callback_func(type_variant: 'Model | Dataset', content: Any):
        """Populate one item instance from a JSON string.

        Args:
            type_variant: Newly created model or dataset instance to populate.
            content: JSON content to load into the instance.

        """
        type_variant.from_json(content)

    self._from_dict_with_callback(data, update, callback_func)

full

full(
    *,
    width: pyd.NonNegativeInt | None = None,
    height: pyd.NonNegativeInt | None = None,
    tab: pyd.NonNegativeInt = 4,
    indent: pyd.NonNegativeInt = 2,
    printer: PrettyPrinterLib.Literals = "auto",
    syntax: SyntaxLanguageSpec.Literals | str = "auto",
    freedom: pyd.NonNegativeFloat | None = 2.5,
    debug: bool = False,
    ui: UserInterfaceType.Literals = "auto",
    system: DisplayColorSystem.Literals = "auto",
    style: AllColorStyles.Literals | str = "auto",
    dark: typing.Literal["auto", True, False] = "auto",
    bg: bool = False,
    fonts: tuple[str, ...] = ("Menlo", "DejaVu Sans Mono", "Consolas", "Courier New", "monospace"),
    font_size: pyd.NonNegativeFloat | None = 14,
    font_weight: pyd.NonNegativeInt | None = 400,
    line_height: pyd.NonNegativeFloat | None = 1.25,
    h_overflow: HorizontalOverflowMode.Literals = "ellipsis",
    v_overflow: VerticalOverflowMode.Literals = "ellipsis_bottom",
    panel: PanelDesign.Literals = "table",
    title_at_top: bool = True,
    max_title_height: MaxTitleHeight.Literals = -1,
    min_panel_width: pyd.NonNegativeInt = 3,
    min_crop_width: pyd.NonNegativeInt = 33,
    use_min_crop_width: bool = False,
    max_panels_hor: pyd.NonNegativeInt | None = 9,
    max_nesting_depth: pyd.NonNegativeInt | None = 3,
    justify: Justify.Literals = "left",
) -> Element | None

Display the content of the Model or Dataset in full height.

full() is a shorthand for peek(height=None) for both models and datasets. Both full-height views are automatically limited in width by the available display dimensions.

PARAMETER DESCRIPTION
width

Width in characters of the output area (None for auto-detect based on available display dimensions).

TYPE: NonNegativeInt | None DEFAULT: None

height

Height in lines of the output area (None for auto-detect based on available display dimensions).

TYPE: NonNegativeInt | None DEFAULT: None

tab

Number of spaces to use for each tab.

TYPE: NonNegativeInt DEFAULT: 4

indent

Number of spaces to use for each indentation level.

TYPE: NonNegativeInt DEFAULT: 2

printer

Library to use for pretty printing.

TYPE: PrettyPrinterLib.Literals DEFAULT: 'auto'

syntax

Syntax language for code highlighting. Supported lexers are defined in SyntaxLanguageSpec. For non-supported styles, the user can specify a string with the Pygments lexer name. For this to work, the lexer must be registered in the Pygments library.

TYPE: SyntaxLanguageSpec.Literals | str DEFAULT: 'auto'

freedom

Parameter that controls the level of freedom for formatted text to follow the geometry of the frame size (=total available area) in a proportional manner. If the proportional freedom is 0 (the lowest), then the output area must not in any case be proportionally wider that the frame (i.e. a 16/9 frame will only produce output that is 16/9 or narrower). Larger values of proportional freedom allow the output to be proportionally wider than the total available frame, to a degree that relates to the size difference between the frame and the content (larger difference gives more freedom). The default value of 2.5 is a good compromise between readability/aesthetics and good use of the screen estate. If None, the freedom is unlimited (i.e. proportionality is not taken into account at all).

TYPE: float | None DEFAULT: 2.5

debug

When True, enables additional debugging information in the output, such as the hierarchy of the Model objects. Currently, only Python pretty printers support debug=True. Hence, enabling debug mode will automatically set the printer to the default Python pretty printer if the printer config value is not already set.

TYPE: bool DEFAULT: False

ui

Type of user interface for which the output should being prepared. The user interface describes the technical solutions available for interacting with the user, encompassing the support available for displaying output as well as how the user interacts with the library (including the type of interactive interpreter used, if any).

TYPE: UserInterfaceType.Literals DEFAULT: 'auto'

system

Color system to use for terminal output. The default is AUTO, which automatically detects the color system based on particular environment variables. If color capabilities are not detected, the output will be in black and white. If the color system of a modern consoles/terminal is not auto-detected (which is the case for e.g. the PyCharm console), the user might want to set the color system manually to ANSI_RGB to force color output.

TYPE: ColorSystem.Literals DEFAULT: 'auto'

style

Color style/theme for syntax highlighting and other display elements. Supported styles are defined in AllColorStyles. For non-supported styles, the user can specify a string with the Pygments style name. For this to work, the style must be registered in the Pygments library. If style is AUTO or any of the other RecommendedColorStyles, the style is automatically selected from the RecommendedColorStyles based on the detected user interface, the color system, and whether the background is dark or not.

TYPE: AllColorStyles.Literals | str DEFAULT: 'auto'

dark

Whether the background color of the output is dark. This is used to determine the appropriate color scheme for syntax highlighting. The default is AUTO, which automatically tries to detect whether the background is dark. Capability of auto-detection depends on the user interface.

TYPE: DarkBackground.Literals DEFAULT: 'auto'

bg

If False, uses transparent background for the output. In the case of terminal output, the background color will be the current background color of the terminal. For HTML output, the background color will be automatically set to pure black or pure white, depending on the luminosity of the foreground color.

TYPE: bool DEFAULT: False

fonts

Font families to use in HTML output, in order of preference (empty tuple for browser default).

TYPE: Tuple[str, ...] DEFAULT: ('Menlo', 'DejaVu Sans Mono', 'Consolas', 'Courier New', 'monospace')

font_size

Font size in pixels for HTML output (None for browser default).

TYPE: NonNegativeFloat | None DEFAULT: 14

font_weight

Font weight for HTML output (None for browser default).

TYPE: NonNegativeInt | None DEFAULT: 400

line_height

Line height multiplier for HTML output (None for browser default).

TYPE: NonNegativeFloat | None DEFAULT: 1.25

h_overflow

How to handle text that exceeds the width.

TYPE: HorizontalOverflowMode.Literals DEFAULT: 'ellipsis'

v_overflow

How to handle text that exceeds the height.

TYPE: VerticalOverflowMode.Literals DEFAULT: 'ellipsis_bottom'

panel

Visual design of the panel used as container for the output. Only TABLE is currently supported, which displays the output in a table-like grid.

TYPE: PanelDesign.Literals DEFAULT: 'table'

title_at_top

Whether panel titles will be displayed over the panel content (True) or below the content (False)

TYPE: bool DEFAULT: True

max_title_height

Maximum height of the panel title. If AUTO, the height is determined by the content of the title, up to a maximum of two lines. If ZERO, the title is not displayed at all. If ONE or TWO, the title is displayed with a fixed height of max one or two lines, respectively.

TYPE: MaxTitleHeight.Literals DEFAULT: -1

min_panel_width

Minimum width in characters per panel.

TYPE: NonNegativeInt DEFAULT: 3

min_crop_width

Minimum cropping width in characters for panels in cases where more than one panel are to be displayed. This is for instance used to calculate the number of models to display in a Dataset peek(). Only applied if use_min_crop_width is set to True. min_crop_width must be equal to or larger than min_panel_width.

TYPE: NonNegativeInt DEFAULT: 33

use_min_crop_width

Whether the min_crop_width value should be considered in cases where more than one panel are to be displayed, potentially reducing the number of displayed panels.

TYPE: bool DEFAULT: False

max_panels_hor

Maximum number of panels to display horizontally side-by-side at the top level. This value also acts as a ceiling for nested panels; nested panels cannot exceed this limit even if the constant MAX_PANELS_HORIZONTALLY_DEEPLY_NESTED is set to a higher value. If None, there is no limit.

TYPE: NonNegativeInt | None DEFAULT: 9

max_nesting_depth

Maximum levels of nested panels to display. If None, there is no limit.

TYPE: NonNegativeInt | None DEFAULT: 3

justify

Justification mode for the panel if inside a layout panel. This is only used for the panel content.

TYPE: Justify.Literals DEFAULT: 'left'

RETURNS DESCRIPTION
Element | None

If the UI type is Jupyter running in browser, the method returns a ReactivelyResizingHtml element which is a Jupyter widget to display HTML output in the browser. Otherwise, the method returns None.

Note

Any default argument value is overridden by the corresponding value in the relevant subsection of the UserInterfaceConfig.

Source code in src/omnipy/data/_mixins/display.py
def full(self, **kwargs) -> 'Element | None':
    # %% Original docstring (managed by expand_docstr_macros.py) %%
    # {{FULL_SUMMARY}}
    #
    # {{FULL_DESCRIPTION}}
    #
    # {{DISPLAY_METHOD_ARGS}}
    #
    # {{DISPLAY_METHOD_RETURNS}}
    #
    # {{DISPLAY_METHOD_NOTE}}
    #
    #
    """Display the content of the Model or Dataset in full height.

    `full()` is a shorthand for `peek(height=None)` for both
    models and datasets. Both full-height views are automatically
    limited in width by the available display dimensions.

    Args:
        width (NonNegativeInt | None):
            Width in characters of the output area (None for
            auto-detect based on available display dimensions).
        height (NonNegativeInt | None):
            Height in lines of the output area (None for
            auto-detect based on available display dimensions).
        tab (NonNegativeInt):
            Number of spaces to use for each tab.
        indent (NonNegativeInt):
            Number of spaces to use for each indentation level.
        printer (PrettyPrinterLib.Literals):
            Library to use for pretty printing.
        syntax (SyntaxLanguageSpec.Literals | str):
            Syntax language for code highlighting. Supported
            lexers are defined in SyntaxLanguageSpec. For
            non-supported styles, the user can specify a string
            with the Pygments lexer name. For this to work, the
            lexer must be registered in the Pygments library.
        freedom (float | None):
            Parameter that controls the level of freedom for
            formatted text to follow the geometry of the frame
            size (=total available area) in a proportional manner.
            If the proportional freedom is 0 (the lowest), then
            the output area must not in any case be proportionally
            wider that the frame (i.e. a 16/9 frame will only
            produce output that is 16/9 or narrower). Larger
            values of proportional freedom allow the output to be
            proportionally wider than the total available frame,
            to a degree that relates to the size difference
            between the frame and the content (larger difference
            gives more freedom). The default value of 2.5 is a
            good compromise between readability/aesthetics and
            good use of the screen estate. If None, the freedom is
            unlimited (i.e. proportionality is not taken into
            account at all).
        debug (bool):
            When True, enables additional debugging information in
            the output, such as the hierarchy of the Model
            objects. Currently, only Python pretty printers support
            debug=True. Hence, enabling debug mode will
            automatically set the printer to the default Python
            pretty printer if the `printer` config value is not
            already set.
        ui (UserInterfaceType.Literals):
            Type of user interface for which the output should
            being prepared. The user interface describes the
            technical solutions available for interacting with the
            user, encompassing the support available for
            displaying output as well as how the user interacts
            with the library (including the type of interactive
            interpreter used, if any).
        system (ColorSystem.Literals):
            Color system to use for terminal output. The default
            is `AUTO`, which automatically detects the color
            system based on particular environment variables. If
            color capabilities are not detected, the output will
            be in black and white. If the color system of a modern
            consoles/terminal is not auto-detected (which is the
            case for e.g. the PyCharm console), the user might
            want to set the color system manually to ANSI_RGB to
            force color output.
        style (AllColorStyles.Literals | str):
            Color style/theme for syntax highlighting and other
            display elements. Supported styles are defined in
            AllColorStyles. For non-supported styles, the user can
            specify a string with the Pygments style name. For this to
            work, the style must be registered in the Pygments
            library. If style is `AUTO` or any of the other
            RecommendedColorStyles, the style is automatically
            selected from the RecommendedColorStyles based on the
            detected user interface, the color system, and whether the
            background is dark or not.
        dark (DarkBackground.Literals):
            Whether the background color of the output is dark.
            This is used to determine the appropriate color scheme
            for syntax highlighting. The default is AUTO, which
            automatically tries to detect whether the background
            is dark. Capability of auto-detection depends on the
            user interface.
        bg (bool):
            If False, uses transparent background for the output.
            In the case of terminal output, the background color
            will be the current background color of the terminal.
            For HTML output, the background color will be
            automatically set to pure black or pure white,
            depending on the luminosity of the foreground color.
        fonts (Tuple[str, ...]):
            Font families to use in HTML output, in order of
            preference (empty tuple for browser default).
        font_size (NonNegativeFloat | None):
            Font size in pixels for HTML output (None for browser
            default).
        font_weight (NonNegativeInt | None):
            Font weight for HTML output (None for browser
            default).
        line_height (NonNegativeFloat | None):
            Line height multiplier for HTML output (None for
            browser default).
        h_overflow (HorizontalOverflowMode.Literals):
            How to handle text that exceeds the width.
        v_overflow (VerticalOverflowMode.Literals):
            How to handle text that exceeds the height.
        panel (PanelDesign.Literals):
            Visual design of the panel used as container for the
            output. Only `TABLE` is currently supported, which
            displays the output in a table-like grid.
        title_at_top (bool):
            Whether panel titles will be displayed over the panel
            content (True) or below the content (False)
        max_title_height (MaxTitleHeight.Literals):
            Maximum height of the panel title. If `AUTO`, the
            height is determined by the content of the title, up
            to a maximum of two lines. If `ZERO`, the title is not
            displayed at all. If `ONE` or `TWO`, the title is
            displayed with a fixed height of max one or two lines,
            respectively.
        min_panel_width (NonNegativeInt):
            Minimum width in characters per panel.
        min_crop_width (NonNegativeInt):
            Minimum cropping width in characters for panels in
            cases where more than one panel are to be displayed.
            This is for instance used to calculate the number of
            models to display in a Dataset peek(). Only applied if
            `use_min_crop_width` is set to `True`.
            `min_crop_width` must be equal to or larger than
            `min_panel_width`.
        use_min_crop_width (bool):
            Whether the `min_crop_width` value should be
            considered in cases where more than one panel are to
            be displayed, potentially reducing the number of
            displayed panels.
        max_panels_hor (NonNegativeInt | None):
            Maximum number of panels to display horizontally
            side-by-side at the top level. This value also acts as
            a ceiling for nested panels; nested panels cannot
            exceed this limit even if the constant
            `MAX_PANELS_HORIZONTALLY_DEEPLY_NESTED` is set to a
            higher value. If None, there is no limit.
        max_nesting_depth (NonNegativeInt | None):
            Maximum levels of nested panels to display. If None,
            there is no limit.
        justify (Justify.Literals):
            Justification mode for the panel if inside a layout
            panel. This is only used for the panel content.

    Returns:
        If the UI type is Jupyter running in browser, the
        method returns a ReactivelyResizingHtml element which
        is a Jupyter widget to display HTML output in the
        browser. Otherwise, the method returns None.

    Note:
        Any default argument value is overridden by the
        corresponding value in the relevant subsection of the
        UserInterfaceConfig.

    """
    return self._display_according_to_ui_type(
        ui_type=self._extract_ui_type(**kwargs),
        return_output_if_str=False,
        output_method=self._full,
        **kwargs)

get_model

get_model(data_file: str) -> type[Model]

Return the model currently used for a data-file key.

PARAMETER DESCRIPTION
data_file

Dataset key to inspect.

TYPE: str

RETURNS DESCRIPTION
type[Model]

The custom model for the key, or the dataset's general model when no override exists.

Source code in src/omnipy/data/multi.py
def get_model(self, data_file: str) -> type[Model]:
    """Return the model currently used for a data-file key.

    Args:
        data_file: Dataset key to inspect.

    Returns:
        The custom model for the key, or the dataset's general model when no override exists.
    """
    if data_file in self._custom_field_models:
        return self._custom_field_models[data_file]
    else:
        return self.get_type()

get_type cached classmethod

get_type() -> type[_ModelOrDatasetT]

Return the concrete item type stored by this dataset class.

RETURNS DESCRIPTION
type[_ModelOrDatasetT]

The specialized model or nested dataset class used for every item in the dataset.

Source code in src/omnipy/data/dataset.py
@classmethod
@functools.cache
def get_type(cls) -> type[_ModelOrDatasetT]:
    """Return the concrete item type stored by this dataset class.

    Returns:
        The specialized model or nested dataset class used for every item in the dataset.
    """
    # Part of pydantic v1 hack to stop coercing of e.g.
    # [{'a': 'b', 'c': 'd'}] to {'a': 'c'}
    return cls._clean_type(cls._get_data_field().sub_fields[1].type_)  # type: ignore[index]

json

json(
    *,
    width: pyd.NonNegativeInt | None = None,
    height: pyd.NonNegativeInt | None = None,
    tab: pyd.NonNegativeInt = 4,
    indent: pyd.NonNegativeInt = 2,
    printer: PrettyPrinterLib.Literals = "auto",
    syntax: SyntaxLanguageSpec.Literals | str = "auto",
    freedom: pyd.NonNegativeFloat | None = 2.5,
    debug: bool = False,
    ui: UserInterfaceType.Literals = "auto",
    system: DisplayColorSystem.Literals = "auto",
    style: AllColorStyles.Literals | str = "auto",
    dark: typing.Literal["auto", True, False] = "auto",
    bg: bool = False,
    fonts: tuple[str, ...] = ("Menlo", "DejaVu Sans Mono", "Consolas", "Courier New", "monospace"),
    font_size: pyd.NonNegativeFloat | None = 14,
    font_weight: pyd.NonNegativeInt | None = 400,
    line_height: pyd.NonNegativeFloat | None = 1.25,
    h_overflow: HorizontalOverflowMode.Literals = "ellipsis",
    v_overflow: VerticalOverflowMode.Literals = "ellipsis_bottom",
    panel: PanelDesign.Literals = "table",
    title_at_top: bool = True,
    max_title_height: MaxTitleHeight.Literals = -1,
    min_panel_width: pyd.NonNegativeInt = 3,
    min_crop_width: pyd.NonNegativeInt = 33,
    use_min_crop_width: bool = False,
    max_panels_hor: pyd.NonNegativeInt | None = 9,
    max_nesting_depth: pyd.NonNegativeInt | None = 3,
    justify: Justify.Literals = "left",
) -> Element | None

Preview the data content of the Model or Dataset as JSON.

In contrast to e.g. peek(), json() displays the "data content" of the Model or Dataset, i.e. the content as plain Python objects, potentially converted from the internal data structure. This plain data is formatted in JSON (for compactness). Hence json() represents a the basic compatibility layer of all Omnipy Model or Dataset objects. The view is automatically limited by the available display dimensions.

PARAMETER DESCRIPTION
width

Width in characters of the output area (None for auto-detect based on available display dimensions).

TYPE: NonNegativeInt | None DEFAULT: None

height

Height in lines of the output area (None for auto-detect based on available display dimensions).

TYPE: NonNegativeInt | None DEFAULT: None

tab

Number of spaces to use for each tab.

TYPE: NonNegativeInt DEFAULT: 4

indent

Number of spaces to use for each indentation level.

TYPE: NonNegativeInt DEFAULT: 2

printer

Library to use for pretty printing.

TYPE: PrettyPrinterLib.Literals DEFAULT: 'auto'

syntax

Syntax language for code highlighting. Supported lexers are defined in SyntaxLanguageSpec. For non-supported styles, the user can specify a string with the Pygments lexer name. For this to work, the lexer must be registered in the Pygments library.

TYPE: SyntaxLanguageSpec.Literals | str DEFAULT: 'auto'

freedom

Parameter that controls the level of freedom for formatted text to follow the geometry of the frame size (=total available area) in a proportional manner. If the proportional freedom is 0 (the lowest), then the output area must not in any case be proportionally wider that the frame (i.e. a 16/9 frame will only produce output that is 16/9 or narrower). Larger values of proportional freedom allow the output to be proportionally wider than the total available frame, to a degree that relates to the size difference between the frame and the content (larger difference gives more freedom). The default value of 2.5 is a good compromise between readability/aesthetics and good use of the screen estate. If None, the freedom is unlimited (i.e. proportionality is not taken into account at all).

TYPE: float | None DEFAULT: 2.5

debug

When True, enables additional debugging information in the output, such as the hierarchy of the Model objects. Currently, only Python pretty printers support debug=True. Hence, enabling debug mode will automatically set the printer to the default Python pretty printer if the printer config value is not already set.

TYPE: bool DEFAULT: False

ui

Type of user interface for which the output should being prepared. The user interface describes the technical solutions available for interacting with the user, encompassing the support available for displaying output as well as how the user interacts with the library (including the type of interactive interpreter used, if any).

TYPE: UserInterfaceType.Literals DEFAULT: 'auto'

system

Color system to use for terminal output. The default is AUTO, which automatically detects the color system based on particular environment variables. If color capabilities are not detected, the output will be in black and white. If the color system of a modern consoles/terminal is not auto-detected (which is the case for e.g. the PyCharm console), the user might want to set the color system manually to ANSI_RGB to force color output.

TYPE: ColorSystem.Literals DEFAULT: 'auto'

style

Color style/theme for syntax highlighting and other display elements. Supported styles are defined in AllColorStyles. For non-supported styles, the user can specify a string with the Pygments style name. For this to work, the style must be registered in the Pygments library. If style is AUTO or any of the other RecommendedColorStyles, the style is automatically selected from the RecommendedColorStyles based on the detected user interface, the color system, and whether the background is dark or not.

TYPE: AllColorStyles.Literals | str DEFAULT: 'auto'

dark

Whether the background color of the output is dark. This is used to determine the appropriate color scheme for syntax highlighting. The default is AUTO, which automatically tries to detect whether the background is dark. Capability of auto-detection depends on the user interface.

TYPE: DarkBackground.Literals DEFAULT: 'auto'

bg

If False, uses transparent background for the output. In the case of terminal output, the background color will be the current background color of the terminal. For HTML output, the background color will be automatically set to pure black or pure white, depending on the luminosity of the foreground color.

TYPE: bool DEFAULT: False

fonts

Font families to use in HTML output, in order of preference (empty tuple for browser default).

TYPE: Tuple[str, ...] DEFAULT: ('Menlo', 'DejaVu Sans Mono', 'Consolas', 'Courier New', 'monospace')

font_size

Font size in pixels for HTML output (None for browser default).

TYPE: NonNegativeFloat | None DEFAULT: 14

font_weight

Font weight for HTML output (None for browser default).

TYPE: NonNegativeInt | None DEFAULT: 400

line_height

Line height multiplier for HTML output (None for browser default).

TYPE: NonNegativeFloat | None DEFAULT: 1.25

h_overflow

How to handle text that exceeds the width.

TYPE: HorizontalOverflowMode.Literals DEFAULT: 'ellipsis'

v_overflow

How to handle text that exceeds the height.

TYPE: VerticalOverflowMode.Literals DEFAULT: 'ellipsis_bottom'

panel

Visual design of the panel used as container for the output. Only TABLE is currently supported, which displays the output in a table-like grid.

TYPE: PanelDesign.Literals DEFAULT: 'table'

title_at_top

Whether panel titles will be displayed over the panel content (True) or below the content (False)

TYPE: bool DEFAULT: True

max_title_height

Maximum height of the panel title. If AUTO, the height is determined by the content of the title, up to a maximum of two lines. If ZERO, the title is not displayed at all. If ONE or TWO, the title is displayed with a fixed height of max one or two lines, respectively.

TYPE: MaxTitleHeight.Literals DEFAULT: -1

min_panel_width

Minimum width in characters per panel.

TYPE: NonNegativeInt DEFAULT: 3

min_crop_width

Minimum cropping width in characters for panels in cases where more than one panel are to be displayed. This is for instance used to calculate the number of models to display in a Dataset peek(). Only applied if use_min_crop_width is set to True. min_crop_width must be equal to or larger than min_panel_width.

TYPE: NonNegativeInt DEFAULT: 33

use_min_crop_width

Whether the min_crop_width value should be considered in cases where more than one panel are to be displayed, potentially reducing the number of displayed panels.

TYPE: bool DEFAULT: False

max_panels_hor

Maximum number of panels to display horizontally side-by-side at the top level. This value also acts as a ceiling for nested panels; nested panels cannot exceed this limit even if the constant MAX_PANELS_HORIZONTALLY_DEEPLY_NESTED is set to a higher value. If None, there is no limit.

TYPE: NonNegativeInt | None DEFAULT: 9

max_nesting_depth

Maximum levels of nested panels to display. If None, there is no limit.

TYPE: NonNegativeInt | None DEFAULT: 3

justify

Justification mode for the panel if inside a layout panel. This is only used for the panel content.

TYPE: Justify.Literals DEFAULT: 'left'

RETURNS DESCRIPTION
Element | None

If the UI type is Jupyter running in browser, the method returns a ReactivelyResizingHtml element which is a Jupyter widget to display HTML output in the browser. Otherwise, the method returns None.

Note

Any default argument value is overridden by the corresponding value in the relevant subsection of the UserInterfaceConfig.

Source code in src/omnipy/data/_mixins/display.py
def json(self, **kwargs) -> None:
    # %% Original docstring (managed by expand_docstr_macros.py) %%
    # {{JSON_SUMMARY}}
    #
    # {{JSON_DESCRIPTION}}
    #
    # {{DISPLAY_METHOD_ARGS}}
    #
    # {{DISPLAY_METHOD_RETURNS}}
    #
    # {{DISPLAY_METHOD_NOTE}}
    #
    """Preview the data content of the Model or Dataset as JSON.

    In contrast to e.g. `peek()`, `json()` displays the "data
    content" of the Model or Dataset, i.e. the content as plain
    Python objects, potentially converted from the internal data
    structure. This plain data is formatted in JSON (for
    compactness). Hence `json()` represents a the basic
    compatibility layer of all Omnipy Model or Dataset objects.
    The view is automatically limited by the available display
    dimensions.

    Args:
        width (NonNegativeInt | None):
            Width in characters of the output area (None for
            auto-detect based on available display dimensions).
        height (NonNegativeInt | None):
            Height in lines of the output area (None for
            auto-detect based on available display dimensions).
        tab (NonNegativeInt):
            Number of spaces to use for each tab.
        indent (NonNegativeInt):
            Number of spaces to use for each indentation level.
        printer (PrettyPrinterLib.Literals):
            Library to use for pretty printing.
        syntax (SyntaxLanguageSpec.Literals | str):
            Syntax language for code highlighting. Supported
            lexers are defined in SyntaxLanguageSpec. For
            non-supported styles, the user can specify a string
            with the Pygments lexer name. For this to work, the
            lexer must be registered in the Pygments library.
        freedom (float | None):
            Parameter that controls the level of freedom for
            formatted text to follow the geometry of the frame
            size (=total available area) in a proportional manner.
            If the proportional freedom is 0 (the lowest), then
            the output area must not in any case be proportionally
            wider that the frame (i.e. a 16/9 frame will only
            produce output that is 16/9 or narrower). Larger
            values of proportional freedom allow the output to be
            proportionally wider than the total available frame,
            to a degree that relates to the size difference
            between the frame and the content (larger difference
            gives more freedom). The default value of 2.5 is a
            good compromise between readability/aesthetics and
            good use of the screen estate. If None, the freedom is
            unlimited (i.e. proportionality is not taken into
            account at all).
        debug (bool):
            When True, enables additional debugging information in
            the output, such as the hierarchy of the Model
            objects. Currently, only Python pretty printers support
            debug=True. Hence, enabling debug mode will
            automatically set the printer to the default Python
            pretty printer if the `printer` config value is not
            already set.
        ui (UserInterfaceType.Literals):
            Type of user interface for which the output should
            being prepared. The user interface describes the
            technical solutions available for interacting with the
            user, encompassing the support available for
            displaying output as well as how the user interacts
            with the library (including the type of interactive
            interpreter used, if any).
        system (ColorSystem.Literals):
            Color system to use for terminal output. The default
            is `AUTO`, which automatically detects the color
            system based on particular environment variables. If
            color capabilities are not detected, the output will
            be in black and white. If the color system of a modern
            consoles/terminal is not auto-detected (which is the
            case for e.g. the PyCharm console), the user might
            want to set the color system manually to ANSI_RGB to
            force color output.
        style (AllColorStyles.Literals | str):
            Color style/theme for syntax highlighting and other
            display elements. Supported styles are defined in
            AllColorStyles. For non-supported styles, the user can
            specify a string with the Pygments style name. For this to
            work, the style must be registered in the Pygments
            library. If style is `AUTO` or any of the other
            RecommendedColorStyles, the style is automatically
            selected from the RecommendedColorStyles based on the
            detected user interface, the color system, and whether the
            background is dark or not.
        dark (DarkBackground.Literals):
            Whether the background color of the output is dark.
            This is used to determine the appropriate color scheme
            for syntax highlighting. The default is AUTO, which
            automatically tries to detect whether the background
            is dark. Capability of auto-detection depends on the
            user interface.
        bg (bool):
            If False, uses transparent background for the output.
            In the case of terminal output, the background color
            will be the current background color of the terminal.
            For HTML output, the background color will be
            automatically set to pure black or pure white,
            depending on the luminosity of the foreground color.
        fonts (Tuple[str, ...]):
            Font families to use in HTML output, in order of
            preference (empty tuple for browser default).
        font_size (NonNegativeFloat | None):
            Font size in pixels for HTML output (None for browser
            default).
        font_weight (NonNegativeInt | None):
            Font weight for HTML output (None for browser
            default).
        line_height (NonNegativeFloat | None):
            Line height multiplier for HTML output (None for
            browser default).
        h_overflow (HorizontalOverflowMode.Literals):
            How to handle text that exceeds the width.
        v_overflow (VerticalOverflowMode.Literals):
            How to handle text that exceeds the height.
        panel (PanelDesign.Literals):
            Visual design of the panel used as container for the
            output. Only `TABLE` is currently supported, which
            displays the output in a table-like grid.
        title_at_top (bool):
            Whether panel titles will be displayed over the panel
            content (True) or below the content (False)
        max_title_height (MaxTitleHeight.Literals):
            Maximum height of the panel title. If `AUTO`, the
            height is determined by the content of the title, up
            to a maximum of two lines. If `ZERO`, the title is not
            displayed at all. If `ONE` or `TWO`, the title is
            displayed with a fixed height of max one or two lines,
            respectively.
        min_panel_width (NonNegativeInt):
            Minimum width in characters per panel.
        min_crop_width (NonNegativeInt):
            Minimum cropping width in characters for panels in
            cases where more than one panel are to be displayed.
            This is for instance used to calculate the number of
            models to display in a Dataset peek(). Only applied if
            `use_min_crop_width` is set to `True`.
            `min_crop_width` must be equal to or larger than
            `min_panel_width`.
        use_min_crop_width (bool):
            Whether the `min_crop_width` value should be
            considered in cases where more than one panel are to
            be displayed, potentially reducing the number of
            displayed panels.
        max_panels_hor (NonNegativeInt | None):
            Maximum number of panels to display horizontally
            side-by-side at the top level. This value also acts as
            a ceiling for nested panels; nested panels cannot
            exceed this limit even if the constant
            `MAX_PANELS_HORIZONTALLY_DEEPLY_NESTED` is set to a
            higher value. If None, there is no limit.
        max_nesting_depth (NonNegativeInt | None):
            Maximum levels of nested panels to display. If None,
            there is no limit.
        justify (Justify.Literals):
            Justification mode for the panel if inside a layout
            panel. This is only used for the panel content.

    Returns:
        If the UI type is Jupyter running in browser, the
        method returns a ReactivelyResizingHtml element which
        is a Jupyter widget to display HTML output in the
        browser. Otherwise, the method returns None.

    Note:
        Any default argument value is overridden by the
        corresponding value in the relevant subsection of the
        UserInterfaceConfig.
    """
    return self._display_according_to_ui_type(
        ui_type=self._extract_ui_type(**kwargs),
        return_output_if_str=False,
        output_method=self._json,
        **kwargs)

list

list(
    *,
    width: pyd.NonNegativeInt | None = None,
    height: pyd.NonNegativeInt | None = None,
    tab: pyd.NonNegativeInt = 4,
    indent: pyd.NonNegativeInt = 2,
    printer: PrettyPrinterLib.Literals = "auto",
    syntax: SyntaxLanguageSpec.Literals | str = "auto",
    freedom: pyd.NonNegativeFloat | None = 2.5,
    debug: bool = False,
    ui: UserInterfaceType.Literals = "auto",
    system: DisplayColorSystem.Literals = "auto",
    style: AllColorStyles.Literals | str = "auto",
    dark: typing.Literal["auto", True, False] = "auto",
    bg: bool = False,
    fonts: tuple[str, ...] = ("Menlo", "DejaVu Sans Mono", "Consolas", "Courier New", "monospace"),
    font_size: pyd.NonNegativeFloat | None = 14,
    font_weight: pyd.NonNegativeInt | None = 400,
    line_height: pyd.NonNegativeFloat | None = 1.25,
    h_overflow: HorizontalOverflowMode.Literals = "ellipsis",
    v_overflow: VerticalOverflowMode.Literals = "ellipsis_bottom",
    panel: PanelDesign.Literals = "table",
    title_at_top: bool = True,
    max_title_height: MaxTitleHeight.Literals = -1,
    min_panel_width: pyd.NonNegativeInt = 3,
    min_crop_width: pyd.NonNegativeInt = 33,
    use_min_crop_width: bool = False,
    max_panels_hor: pyd.NonNegativeInt | None = 9,
    max_nesting_depth: pyd.NonNegativeInt | None = 3,
    justify: Justify.Literals = "left",
) -> Element | None

Displays a summary list of all models in the dataset.

The summary list includes a number of key properties for each model, including data file names, types, lengths, and sizes in memory. The output is automatically limited by the available display dimensions.

PARAMETER DESCRIPTION
width

Width in characters of the output area (None for auto-detect based on available display dimensions).

TYPE: NonNegativeInt | None DEFAULT: None

height

Height in lines of the output area (None for auto-detect based on available display dimensions).

TYPE: NonNegativeInt | None DEFAULT: None

tab

Number of spaces to use for each tab.

TYPE: NonNegativeInt DEFAULT: 4

indent

Number of spaces to use for each indentation level.

TYPE: NonNegativeInt DEFAULT: 2

printer

Library to use for pretty printing.

TYPE: PrettyPrinterLib.Literals DEFAULT: 'auto'

syntax

Syntax language for code highlighting. Supported lexers are defined in SyntaxLanguageSpec. For non-supported styles, the user can specify a string with the Pygments lexer name. For this to work, the lexer must be registered in the Pygments library.

TYPE: SyntaxLanguageSpec.Literals | str DEFAULT: 'auto'

freedom

Parameter that controls the level of freedom for formatted text to follow the geometry of the frame size (=total available area) in a proportional manner. If the proportional freedom is 0 (the lowest), then the output area must not in any case be proportionally wider that the frame (i.e. a 16/9 frame will only produce output that is 16/9 or narrower). Larger values of proportional freedom allow the output to be proportionally wider than the total available frame, to a degree that relates to the size difference between the frame and the content (larger difference gives more freedom). The default value of 2.5 is a good compromise between readability/aesthetics and good use of the screen estate. If None, the freedom is unlimited (i.e. proportionality is not taken into account at all).

TYPE: float | None DEFAULT: 2.5

debug

When True, enables additional debugging information in the output, such as the hierarchy of the Model objects. Currently, only Python pretty printers support debug=True. Hence, enabling debug mode will automatically set the printer to the default Python pretty printer if the printer config value is not already set.

TYPE: bool DEFAULT: False

ui

Type of user interface for which the output should being prepared. The user interface describes the technical solutions available for interacting with the user, encompassing the support available for displaying output as well as how the user interacts with the library (including the type of interactive interpreter used, if any).

TYPE: UserInterfaceType.Literals DEFAULT: 'auto'

system

Color system to use for terminal output. The default is AUTO, which automatically detects the color system based on particular environment variables. If color capabilities are not detected, the output will be in black and white. If the color system of a modern consoles/terminal is not auto-detected (which is the case for e.g. the PyCharm console), the user might want to set the color system manually to ANSI_RGB to force color output.

TYPE: ColorSystem.Literals DEFAULT: 'auto'

style

Color style/theme for syntax highlighting and other display elements. Supported styles are defined in AllColorStyles. For non-supported styles, the user can specify a string with the Pygments style name. For this to work, the style must be registered in the Pygments library. If style is AUTO or any of the other RecommendedColorStyles, the style is automatically selected from the RecommendedColorStyles based on the detected user interface, the color system, and whether the background is dark or not.

TYPE: AllColorStyles.Literals | str DEFAULT: 'auto'

dark

Whether the background color of the output is dark. This is used to determine the appropriate color scheme for syntax highlighting. The default is AUTO, which automatically tries to detect whether the background is dark. Capability of auto-detection depends on the user interface.

TYPE: DarkBackground.Literals DEFAULT: 'auto'

bg

If False, uses transparent background for the output. In the case of terminal output, the background color will be the current background color of the terminal. For HTML output, the background color will be automatically set to pure black or pure white, depending on the luminosity of the foreground color.

TYPE: bool DEFAULT: False

fonts

Font families to use in HTML output, in order of preference (empty tuple for browser default).

TYPE: Tuple[str, ...] DEFAULT: ('Menlo', 'DejaVu Sans Mono', 'Consolas', 'Courier New', 'monospace')

font_size

Font size in pixels for HTML output (None for browser default).

TYPE: NonNegativeFloat | None DEFAULT: 14

font_weight

Font weight for HTML output (None for browser default).

TYPE: NonNegativeInt | None DEFAULT: 400

line_height

Line height multiplier for HTML output (None for browser default).

TYPE: NonNegativeFloat | None DEFAULT: 1.25

h_overflow

How to handle text that exceeds the width.

TYPE: HorizontalOverflowMode.Literals DEFAULT: 'ellipsis'

v_overflow

How to handle text that exceeds the height.

TYPE: VerticalOverflowMode.Literals DEFAULT: 'ellipsis_bottom'

panel

Visual design of the panel used as container for the output. Only TABLE is currently supported, which displays the output in a table-like grid.

TYPE: PanelDesign.Literals DEFAULT: 'table'

title_at_top

Whether panel titles will be displayed over the panel content (True) or below the content (False)

TYPE: bool DEFAULT: True

max_title_height

Maximum height of the panel title. If AUTO, the height is determined by the content of the title, up to a maximum of two lines. If ZERO, the title is not displayed at all. If ONE or TWO, the title is displayed with a fixed height of max one or two lines, respectively.

TYPE: MaxTitleHeight.Literals DEFAULT: -1

min_panel_width

Minimum width in characters per panel.

TYPE: NonNegativeInt DEFAULT: 3

min_crop_width

Minimum cropping width in characters for panels in cases where more than one panel are to be displayed. This is for instance used to calculate the number of models to display in a Dataset peek(). Only applied if use_min_crop_width is set to True. min_crop_width must be equal to or larger than min_panel_width.

TYPE: NonNegativeInt DEFAULT: 33

use_min_crop_width

Whether the min_crop_width value should be considered in cases where more than one panel are to be displayed, potentially reducing the number of displayed panels.

TYPE: bool DEFAULT: False

max_panels_hor

Maximum number of panels to display horizontally side-by-side at the top level. This value also acts as a ceiling for nested panels; nested panels cannot exceed this limit even if the constant MAX_PANELS_HORIZONTALLY_DEEPLY_NESTED is set to a higher value. If None, there is no limit.

TYPE: NonNegativeInt | None DEFAULT: 9

max_nesting_depth

Maximum levels of nested panels to display. If None, there is no limit.

TYPE: NonNegativeInt | None DEFAULT: 3

justify

Justification mode for the panel if inside a layout panel. This is only used for the panel content.

TYPE: Justify.Literals DEFAULT: 'left'

RETURNS DESCRIPTION
Element | None

If the UI type is Jupyter running in browser, the method returns a ReactivelyResizingHtml element which is a Jupyter widget to display HTML output in the browser. Otherwise, the method returns None.

Note

Any default argument value is overridden by the corresponding value in the relevant subsection of the UserInterfaceConfig.

Source code in src/omnipy/data/_mixins/display.py
def list(self, **kwargs) -> 'Element | None':
    # %% Original docstring (managed by expand_docstr_macros.py) %%
    # {{LIST_SUMMARY}}
    #
    # {{LIST_DESCRIPTION}}
    #
    # {{DISPLAY_METHOD_ARGS}}
    #
    # {{DISPLAY_METHOD_RETURNS}}
    #
    # {{DISPLAY_METHOD_NOTE}}
    #
    """Displays a summary list of all models in the dataset.

    The summary list includes a number of key properties for each
    model, including data file names, types, lengths, and sizes in
    memory. The output is automatically limited by the available
    display dimensions.

    Args:
        width (NonNegativeInt | None):
            Width in characters of the output area (None for
            auto-detect based on available display dimensions).
        height (NonNegativeInt | None):
            Height in lines of the output area (None for
            auto-detect based on available display dimensions).
        tab (NonNegativeInt):
            Number of spaces to use for each tab.
        indent (NonNegativeInt):
            Number of spaces to use for each indentation level.
        printer (PrettyPrinterLib.Literals):
            Library to use for pretty printing.
        syntax (SyntaxLanguageSpec.Literals | str):
            Syntax language for code highlighting. Supported
            lexers are defined in SyntaxLanguageSpec. For
            non-supported styles, the user can specify a string
            with the Pygments lexer name. For this to work, the
            lexer must be registered in the Pygments library.
        freedom (float | None):
            Parameter that controls the level of freedom for
            formatted text to follow the geometry of the frame
            size (=total available area) in a proportional manner.
            If the proportional freedom is 0 (the lowest), then
            the output area must not in any case be proportionally
            wider that the frame (i.e. a 16/9 frame will only
            produce output that is 16/9 or narrower). Larger
            values of proportional freedom allow the output to be
            proportionally wider than the total available frame,
            to a degree that relates to the size difference
            between the frame and the content (larger difference
            gives more freedom). The default value of 2.5 is a
            good compromise between readability/aesthetics and
            good use of the screen estate. If None, the freedom is
            unlimited (i.e. proportionality is not taken into
            account at all).
        debug (bool):
            When True, enables additional debugging information in
            the output, such as the hierarchy of the Model
            objects. Currently, only Python pretty printers support
            debug=True. Hence, enabling debug mode will
            automatically set the printer to the default Python
            pretty printer if the `printer` config value is not
            already set.
        ui (UserInterfaceType.Literals):
            Type of user interface for which the output should
            being prepared. The user interface describes the
            technical solutions available for interacting with the
            user, encompassing the support available for
            displaying output as well as how the user interacts
            with the library (including the type of interactive
            interpreter used, if any).
        system (ColorSystem.Literals):
            Color system to use for terminal output. The default
            is `AUTO`, which automatically detects the color
            system based on particular environment variables. If
            color capabilities are not detected, the output will
            be in black and white. If the color system of a modern
            consoles/terminal is not auto-detected (which is the
            case for e.g. the PyCharm console), the user might
            want to set the color system manually to ANSI_RGB to
            force color output.
        style (AllColorStyles.Literals | str):
            Color style/theme for syntax highlighting and other
            display elements. Supported styles are defined in
            AllColorStyles. For non-supported styles, the user can
            specify a string with the Pygments style name. For this to
            work, the style must be registered in the Pygments
            library. If style is `AUTO` or any of the other
            RecommendedColorStyles, the style is automatically
            selected from the RecommendedColorStyles based on the
            detected user interface, the color system, and whether the
            background is dark or not.
        dark (DarkBackground.Literals):
            Whether the background color of the output is dark.
            This is used to determine the appropriate color scheme
            for syntax highlighting. The default is AUTO, which
            automatically tries to detect whether the background
            is dark. Capability of auto-detection depends on the
            user interface.
        bg (bool):
            If False, uses transparent background for the output.
            In the case of terminal output, the background color
            will be the current background color of the terminal.
            For HTML output, the background color will be
            automatically set to pure black or pure white,
            depending on the luminosity of the foreground color.
        fonts (Tuple[str, ...]):
            Font families to use in HTML output, in order of
            preference (empty tuple for browser default).
        font_size (NonNegativeFloat | None):
            Font size in pixels for HTML output (None for browser
            default).
        font_weight (NonNegativeInt | None):
            Font weight for HTML output (None for browser
            default).
        line_height (NonNegativeFloat | None):
            Line height multiplier for HTML output (None for
            browser default).
        h_overflow (HorizontalOverflowMode.Literals):
            How to handle text that exceeds the width.
        v_overflow (VerticalOverflowMode.Literals):
            How to handle text that exceeds the height.
        panel (PanelDesign.Literals):
            Visual design of the panel used as container for the
            output. Only `TABLE` is currently supported, which
            displays the output in a table-like grid.
        title_at_top (bool):
            Whether panel titles will be displayed over the panel
            content (True) or below the content (False)
        max_title_height (MaxTitleHeight.Literals):
            Maximum height of the panel title. If `AUTO`, the
            height is determined by the content of the title, up
            to a maximum of two lines. If `ZERO`, the title is not
            displayed at all. If `ONE` or `TWO`, the title is
            displayed with a fixed height of max one or two lines,
            respectively.
        min_panel_width (NonNegativeInt):
            Minimum width in characters per panel.
        min_crop_width (NonNegativeInt):
            Minimum cropping width in characters for panels in
            cases where more than one panel are to be displayed.
            This is for instance used to calculate the number of
            models to display in a Dataset peek(). Only applied if
            `use_min_crop_width` is set to `True`.
            `min_crop_width` must be equal to or larger than
            `min_panel_width`.
        use_min_crop_width (bool):
            Whether the `min_crop_width` value should be
            considered in cases where more than one panel are to
            be displayed, potentially reducing the number of
            displayed panels.
        max_panels_hor (NonNegativeInt | None):
            Maximum number of panels to display horizontally
            side-by-side at the top level. This value also acts as
            a ceiling for nested panels; nested panels cannot
            exceed this limit even if the constant
            `MAX_PANELS_HORIZONTALLY_DEEPLY_NESTED` is set to a
            higher value. If None, there is no limit.
        max_nesting_depth (NonNegativeInt | None):
            Maximum levels of nested panels to display. If None,
            there is no limit.
        justify (Justify.Literals):
            Justification mode for the panel if inside a layout
            panel. This is only used for the panel content.

    Returns:
        If the UI type is Jupyter running in browser, the
        method returns a ReactivelyResizingHtml element which
        is a Jupyter widget to display HTML output in the
        browser. Otherwise, the method returns None.

    Note:
        Any default argument value is overridden by the
        corresponding value in the relevant subsection of the
        UserInterfaceConfig.
    """

    return self._display_according_to_ui_type(
        ui_type=self._extract_ui_type(**kwargs),
        return_output_if_str=False,
        output_method=self._list,
        **kwargs,
    )

load classmethod

load(
    paths_or_urls: IsPathsOrUrlsOneOrMoreOrNone = None,
    by_file_suffix: bool = False,
    as_mime_type: None | str = None,
    **kwargs: IsPathOrUrl,
) -> Self | asyncio.Task[Self]

Create a dataset and load serialized contents into it.

PARAMETER DESCRIPTION
paths_or_urls

Path, URL, iterable of paths or URLs, or dataset/model of HTTP URLs to load from.

TYPE: IsPathsOrUrlsOneOrMoreOrNone DEFAULT: None

by_file_suffix

Whether serializer lookup should prefer file-suffix detection.

TYPE: bool DEFAULT: False

as_mime_type

Optional MIME type hint for HTTP loading.

TYPE: None | str DEFAULT: None

**kwargs

Alternate keyed path or URL arguments when paths_or_urls is omitted.

TYPE: IsPathOrUrl DEFAULT: {}

RETURNS DESCRIPTION
Self | asyncio.Task[Self]

A loaded dataset, or an asyncio.Task when called inside a running event loop.

Source code in src/omnipy/data/dataset.py
@classmethod
def load(
    cls,
    paths_or_urls: IsPathsOrUrlsOneOrMoreOrNone = None,
    by_file_suffix: bool = False,
    as_mime_type: None | str = None,
    **kwargs: IsPathOrUrl,
) -> Self | asyncio.Task[Self]:
    """Create a dataset and load serialized contents into it.

    Args:
        paths_or_urls: Path, URL, iterable of paths or URLs, or dataset/model of HTTP URLs to
            load from.
        by_file_suffix: Whether serializer lookup should prefer file-suffix detection.
        as_mime_type: Optional MIME type hint for HTTP loading.
        **kwargs: Alternate keyed path or URL arguments when ``paths_or_urls`` is omitted.

    Returns:
        A loaded dataset, or an ``asyncio.Task`` when called inside a running event loop.
    """
    dataset = cls()
    return dataset.load_into(
        paths_or_urls, by_file_suffix=by_file_suffix, as_mime_type=as_mime_type, **kwargs)

load_into

load_into(
    paths_or_urls: IsPathsOrUrlsOneOrMoreOrNone = None,
    by_file_suffix: bool = False,
    as_mime_type: None | str = None,
    **kwargs: IsPathOrUrl,
) -> Self | asyncio.Task[Self]

Load serialized contents into this dataset instance.

PARAMETER DESCRIPTION
paths_or_urls

Path, URL, iterable of paths or URLs, or dataset/model of HTTP URLs to load from.

TYPE: IsPathsOrUrlsOneOrMoreOrNone DEFAULT: None

by_file_suffix

Whether serializer lookup should prefer file-suffix detection.

TYPE: bool DEFAULT: False

as_mime_type

Optional MIME type hint for HTTP loading.

TYPE: None | str DEFAULT: None

**kwargs

Alternate keyed path or URL arguments when paths_or_urls is omitted.

TYPE: IsPathOrUrl DEFAULT: {}

RETURNS DESCRIPTION
Self | asyncio.Task[Self]

This dataset instance after loading, or an asyncio.Task when called inside a running event loop.

RAISES DESCRIPTION
AssertionError

If the input forms are combined incorrectly.

TypeError

If paths_or_urls has an unsupported type.

NotImplementedError

If keyed local-path loading is requested.

Source code in src/omnipy/data/dataset.py
def load_into(
    self,
    paths_or_urls: IsPathsOrUrlsOneOrMoreOrNone = None,
    by_file_suffix: bool = False,
    as_mime_type: None | str = None,
    **kwargs: IsPathOrUrl,
) -> Self | asyncio.Task[Self]:
    """Load serialized contents into this dataset instance.

    Args:
        paths_or_urls: Path, URL, iterable of paths or URLs, or dataset/model of HTTP URLs to
            load from.
        by_file_suffix: Whether serializer lookup should prefer file-suffix detection.
        as_mime_type: Optional MIME type hint for HTTP loading.
        **kwargs: Alternate keyed path or URL arguments when ``paths_or_urls`` is omitted.

    Returns:
        This dataset instance after loading, or an ``asyncio.Task`` when called inside a
        running event loop.

    Raises:
        AssertionError: If the input forms are combined incorrectly.
        TypeError: If ``paths_or_urls`` has an unsupported type.
        NotImplementedError: If keyed local-path loading is requested.
    """
    from omnipy.components.remote.datasets import HttpUrlDataset
    from omnipy.components.remote.models import HttpUrlModel

    if paths_or_urls is None:
        assert len(kwargs) > 0, 'No paths or urls specified'
        paths_or_urls = kwargs
    else:
        assert len(kwargs) == 0, 'No keyword arguments allowed when paths_or_urls is specified'

    match paths_or_urls:
        case HttpUrlDataset():
            return self._load_http_urls(paths_or_urls, as_mime_type=as_mime_type)

        case HttpUrlModel():
            return self._load_http_urls(
                HttpUrlDataset({str(paths_or_urls): paths_or_urls}),
                as_mime_type=as_mime_type,
            )

        case str():
            try:
                http_url_dataset = HttpUrlDataset({paths_or_urls: paths_or_urls})
            except ValidationError:
                return self._load_paths([paths_or_urls], by_file_suffix)
            return self._load_http_urls(http_url_dataset, as_mime_type=as_mime_type)

        case Mapping():
            try:
                http_url_dataset = HttpUrlDataset(paths_or_urls)
            except ValidationError as exp:
                raise NotImplementedError(
                    'Loading files with specified keys is not yet '
                    'implemented, as only tar.gz file import is '
                    'supported until serializers have been refactored.') from exp
            return self._load_http_urls(http_url_dataset, as_mime_type=as_mime_type)

        case Iterable():
            path_or_url_iterable = paths_or_urls
            try:
                http_url_dataset = HttpUrlDataset(
                    zip(path_or_url_iterable, path_or_url_iterable))
            except ValidationError:
                return self._load_paths(path_or_url_iterable, by_file_suffix)
            return self._load_http_urls(http_url_dataset, as_mime_type=as_mime_type)
        case _:
            raise TypeError(f'"paths_or_urls" argument is of incorrect type. Type '
                            f'{type(paths_or_urls)} is not supported.')

peek

peek(
    *,
    width: pyd.NonNegativeInt | None = None,
    height: pyd.NonNegativeInt | None = None,
    tab: pyd.NonNegativeInt = 4,
    indent: pyd.NonNegativeInt = 2,
    printer: PrettyPrinterLib.Literals = "auto",
    syntax: SyntaxLanguageSpec.Literals | str = "auto",
    freedom: pyd.NonNegativeFloat | None = 2.5,
    debug: bool = False,
    ui: UserInterfaceType.Literals = "auto",
    system: DisplayColorSystem.Literals = "auto",
    style: AllColorStyles.Literals | str = "auto",
    dark: typing.Literal["auto", True, False] = "auto",
    bg: bool = False,
    fonts: tuple[str, ...] = ("Menlo", "DejaVu Sans Mono", "Consolas", "Courier New", "monospace"),
    font_size: pyd.NonNegativeFloat | None = 14,
    font_weight: pyd.NonNegativeInt | None = 400,
    line_height: pyd.NonNegativeFloat | None = 1.25,
    h_overflow: HorizontalOverflowMode.Literals = "ellipsis",
    v_overflow: VerticalOverflowMode.Literals = "ellipsis_bottom",
    panel: PanelDesign.Literals = "table",
    title_at_top: bool = True,
    max_title_height: MaxTitleHeight.Literals = -1,
    min_panel_width: pyd.NonNegativeInt = 3,
    min_crop_width: pyd.NonNegativeInt = 33,
    use_min_crop_width: bool = False,
    max_panels_hor: pyd.NonNegativeInt | None = 9,
    max_nesting_depth: pyd.NonNegativeInt | None = 3,
    justify: Justify.Literals = "left",
) -> Element | None

Display a preview of the Model or Dataset content.

For Model instances, peek() displays a preview of the model's content. For Dataset instances, peek() displays a side-by-side view of each model contained in the dataset. Both views are automatically limited by the available display dimensions.

PARAMETER DESCRIPTION
width

Width in characters of the output area (None for auto-detect based on available display dimensions).

TYPE: NonNegativeInt | None DEFAULT: None

height

Height in lines of the output area (None for auto-detect based on available display dimensions).

TYPE: NonNegativeInt | None DEFAULT: None

tab

Number of spaces to use for each tab.

TYPE: NonNegativeInt DEFAULT: 4

indent

Number of spaces to use for each indentation level.

TYPE: NonNegativeInt DEFAULT: 2

printer

Library to use for pretty printing.

TYPE: PrettyPrinterLib.Literals DEFAULT: 'auto'

syntax

Syntax language for code highlighting. Supported lexers are defined in SyntaxLanguageSpec. For non-supported styles, the user can specify a string with the Pygments lexer name. For this to work, the lexer must be registered in the Pygments library.

TYPE: SyntaxLanguageSpec.Literals | str DEFAULT: 'auto'

freedom

Parameter that controls the level of freedom for formatted text to follow the geometry of the frame size (=total available area) in a proportional manner. If the proportional freedom is 0 (the lowest), then the output area must not in any case be proportionally wider that the frame (i.e. a 16/9 frame will only produce output that is 16/9 or narrower). Larger values of proportional freedom allow the output to be proportionally wider than the total available frame, to a degree that relates to the size difference between the frame and the content (larger difference gives more freedom). The default value of 2.5 is a good compromise between readability/aesthetics and good use of the screen estate. If None, the freedom is unlimited (i.e. proportionality is not taken into account at all).

TYPE: float | None DEFAULT: 2.5

debug

When True, enables additional debugging information in the output, such as the hierarchy of the Model objects. Currently, only Python pretty printers support debug=True. Hence, enabling debug mode will automatically set the printer to the default Python pretty printer if the printer config value is not already set.

TYPE: bool DEFAULT: False

ui

Type of user interface for which the output should being prepared. The user interface describes the technical solutions available for interacting with the user, encompassing the support available for displaying output as well as how the user interacts with the library (including the type of interactive interpreter used, if any).

TYPE: UserInterfaceType.Literals DEFAULT: 'auto'

system

Color system to use for terminal output. The default is AUTO, which automatically detects the color system based on particular environment variables. If color capabilities are not detected, the output will be in black and white. If the color system of a modern consoles/terminal is not auto-detected (which is the case for e.g. the PyCharm console), the user might want to set the color system manually to ANSI_RGB to force color output.

TYPE: ColorSystem.Literals DEFAULT: 'auto'

style

Color style/theme for syntax highlighting and other display elements. Supported styles are defined in AllColorStyles. For non-supported styles, the user can specify a string with the Pygments style name. For this to work, the style must be registered in the Pygments library. If style is AUTO or any of the other RecommendedColorStyles, the style is automatically selected from the RecommendedColorStyles based on the detected user interface, the color system, and whether the background is dark or not.

TYPE: AllColorStyles.Literals | str DEFAULT: 'auto'

dark

Whether the background color of the output is dark. This is used to determine the appropriate color scheme for syntax highlighting. The default is AUTO, which automatically tries to detect whether the background is dark. Capability of auto-detection depends on the user interface.

TYPE: DarkBackground.Literals DEFAULT: 'auto'

bg

If False, uses transparent background for the output. In the case of terminal output, the background color will be the current background color of the terminal. For HTML output, the background color will be automatically set to pure black or pure white, depending on the luminosity of the foreground color.

TYPE: bool DEFAULT: False

fonts

Font families to use in HTML output, in order of preference (empty tuple for browser default).

TYPE: Tuple[str, ...] DEFAULT: ('Menlo', 'DejaVu Sans Mono', 'Consolas', 'Courier New', 'monospace')

font_size

Font size in pixels for HTML output (None for browser default).

TYPE: NonNegativeFloat | None DEFAULT: 14

font_weight

Font weight for HTML output (None for browser default).

TYPE: NonNegativeInt | None DEFAULT: 400

line_height

Line height multiplier for HTML output (None for browser default).

TYPE: NonNegativeFloat | None DEFAULT: 1.25

h_overflow

How to handle text that exceeds the width.

TYPE: HorizontalOverflowMode.Literals DEFAULT: 'ellipsis'

v_overflow

How to handle text that exceeds the height.

TYPE: VerticalOverflowMode.Literals DEFAULT: 'ellipsis_bottom'

panel

Visual design of the panel used as container for the output. Only TABLE is currently supported, which displays the output in a table-like grid.

TYPE: PanelDesign.Literals DEFAULT: 'table'

title_at_top

Whether panel titles will be displayed over the panel content (True) or below the content (False)

TYPE: bool DEFAULT: True

max_title_height

Maximum height of the panel title. If AUTO, the height is determined by the content of the title, up to a maximum of two lines. If ZERO, the title is not displayed at all. If ONE or TWO, the title is displayed with a fixed height of max one or two lines, respectively.

TYPE: MaxTitleHeight.Literals DEFAULT: -1

min_panel_width

Minimum width in characters per panel.

TYPE: NonNegativeInt DEFAULT: 3

min_crop_width

Minimum cropping width in characters for panels in cases where more than one panel are to be displayed. This is for instance used to calculate the number of models to display in a Dataset peek(). Only applied if use_min_crop_width is set to True. min_crop_width must be equal to or larger than min_panel_width.

TYPE: NonNegativeInt DEFAULT: 33

use_min_crop_width

Whether the min_crop_width value should be considered in cases where more than one panel are to be displayed, potentially reducing the number of displayed panels.

TYPE: bool DEFAULT: False

max_panels_hor

Maximum number of panels to display horizontally side-by-side at the top level. This value also acts as a ceiling for nested panels; nested panels cannot exceed this limit even if the constant MAX_PANELS_HORIZONTALLY_DEEPLY_NESTED is set to a higher value. If None, there is no limit.

TYPE: NonNegativeInt | None DEFAULT: 9

max_nesting_depth

Maximum levels of nested panels to display. If None, there is no limit.

TYPE: NonNegativeInt | None DEFAULT: 3

justify

Justification mode for the panel if inside a layout panel. This is only used for the panel content.

TYPE: Justify.Literals DEFAULT: 'left'

RETURNS DESCRIPTION
Element | None

If the UI type is Jupyter running in browser, the method returns a ReactivelyResizingHtml element which is a Jupyter widget to display HTML output in the browser. Otherwise, the method returns None.

Note

Any default argument value is overridden by the corresponding value in the relevant subsection of the UserInterfaceConfig.

Source code in src/omnipy/data/_mixins/display.py
def peek(self, **kwargs) -> 'Element | None':
    # %% Original docstring (managed by expand_docstr_macros.py) %%
    # {{PEEK_SUMMARY}}
    #
    # {{PEEK_DESCRIPTION}}
    #
    # {{DISPLAY_METHOD_ARGS}}
    #
    # {{DISPLAY_METHOD_RETURNS}}
    #
    # {{DISPLAY_METHOD_NOTE}}
    #
    """Display a preview of the Model or Dataset content.

    For Model instances, `peek()` displays a preview of the
    model's content. For Dataset instances, `peek()` displays a
    side-by-side view of each model contained in the dataset. Both
    views are automatically limited by the available display
    dimensions.

    Args:
        width (NonNegativeInt | None):
            Width in characters of the output area (None for
            auto-detect based on available display dimensions).
        height (NonNegativeInt | None):
            Height in lines of the output area (None for
            auto-detect based on available display dimensions).
        tab (NonNegativeInt):
            Number of spaces to use for each tab.
        indent (NonNegativeInt):
            Number of spaces to use for each indentation level.
        printer (PrettyPrinterLib.Literals):
            Library to use for pretty printing.
        syntax (SyntaxLanguageSpec.Literals | str):
            Syntax language for code highlighting. Supported
            lexers are defined in SyntaxLanguageSpec. For
            non-supported styles, the user can specify a string
            with the Pygments lexer name. For this to work, the
            lexer must be registered in the Pygments library.
        freedom (float | None):
            Parameter that controls the level of freedom for
            formatted text to follow the geometry of the frame
            size (=total available area) in a proportional manner.
            If the proportional freedom is 0 (the lowest), then
            the output area must not in any case be proportionally
            wider that the frame (i.e. a 16/9 frame will only
            produce output that is 16/9 or narrower). Larger
            values of proportional freedom allow the output to be
            proportionally wider than the total available frame,
            to a degree that relates to the size difference
            between the frame and the content (larger difference
            gives more freedom). The default value of 2.5 is a
            good compromise between readability/aesthetics and
            good use of the screen estate. If None, the freedom is
            unlimited (i.e. proportionality is not taken into
            account at all).
        debug (bool):
            When True, enables additional debugging information in
            the output, such as the hierarchy of the Model
            objects. Currently, only Python pretty printers support
            debug=True. Hence, enabling debug mode will
            automatically set the printer to the default Python
            pretty printer if the `printer` config value is not
            already set.
        ui (UserInterfaceType.Literals):
            Type of user interface for which the output should
            being prepared. The user interface describes the
            technical solutions available for interacting with the
            user, encompassing the support available for
            displaying output as well as how the user interacts
            with the library (including the type of interactive
            interpreter used, if any).
        system (ColorSystem.Literals):
            Color system to use for terminal output. The default
            is `AUTO`, which automatically detects the color
            system based on particular environment variables. If
            color capabilities are not detected, the output will
            be in black and white. If the color system of a modern
            consoles/terminal is not auto-detected (which is the
            case for e.g. the PyCharm console), the user might
            want to set the color system manually to ANSI_RGB to
            force color output.
        style (AllColorStyles.Literals | str):
            Color style/theme for syntax highlighting and other
            display elements. Supported styles are defined in
            AllColorStyles. For non-supported styles, the user can
            specify a string with the Pygments style name. For this to
            work, the style must be registered in the Pygments
            library. If style is `AUTO` or any of the other
            RecommendedColorStyles, the style is automatically
            selected from the RecommendedColorStyles based on the
            detected user interface, the color system, and whether the
            background is dark or not.
        dark (DarkBackground.Literals):
            Whether the background color of the output is dark.
            This is used to determine the appropriate color scheme
            for syntax highlighting. The default is AUTO, which
            automatically tries to detect whether the background
            is dark. Capability of auto-detection depends on the
            user interface.
        bg (bool):
            If False, uses transparent background for the output.
            In the case of terminal output, the background color
            will be the current background color of the terminal.
            For HTML output, the background color will be
            automatically set to pure black or pure white,
            depending on the luminosity of the foreground color.
        fonts (Tuple[str, ...]):
            Font families to use in HTML output, in order of
            preference (empty tuple for browser default).
        font_size (NonNegativeFloat | None):
            Font size in pixels for HTML output (None for browser
            default).
        font_weight (NonNegativeInt | None):
            Font weight for HTML output (None for browser
            default).
        line_height (NonNegativeFloat | None):
            Line height multiplier for HTML output (None for
            browser default).
        h_overflow (HorizontalOverflowMode.Literals):
            How to handle text that exceeds the width.
        v_overflow (VerticalOverflowMode.Literals):
            How to handle text that exceeds the height.
        panel (PanelDesign.Literals):
            Visual design of the panel used as container for the
            output. Only `TABLE` is currently supported, which
            displays the output in a table-like grid.
        title_at_top (bool):
            Whether panel titles will be displayed over the panel
            content (True) or below the content (False)
        max_title_height (MaxTitleHeight.Literals):
            Maximum height of the panel title. If `AUTO`, the
            height is determined by the content of the title, up
            to a maximum of two lines. If `ZERO`, the title is not
            displayed at all. If `ONE` or `TWO`, the title is
            displayed with a fixed height of max one or two lines,
            respectively.
        min_panel_width (NonNegativeInt):
            Minimum width in characters per panel.
        min_crop_width (NonNegativeInt):
            Minimum cropping width in characters for panels in
            cases where more than one panel are to be displayed.
            This is for instance used to calculate the number of
            models to display in a Dataset peek(). Only applied if
            `use_min_crop_width` is set to `True`.
            `min_crop_width` must be equal to or larger than
            `min_panel_width`.
        use_min_crop_width (bool):
            Whether the `min_crop_width` value should be
            considered in cases where more than one panel are to
            be displayed, potentially reducing the number of
            displayed panels.
        max_panels_hor (NonNegativeInt | None):
            Maximum number of panels to display horizontally
            side-by-side at the top level. This value also acts as
            a ceiling for nested panels; nested panels cannot
            exceed this limit even if the constant
            `MAX_PANELS_HORIZONTALLY_DEEPLY_NESTED` is set to a
            higher value. If None, there is no limit.
        max_nesting_depth (NonNegativeInt | None):
            Maximum levels of nested panels to display. If None,
            there is no limit.
        justify (Justify.Literals):
            Justification mode for the panel if inside a layout
            panel. This is only used for the panel content.

    Returns:
        If the UI type is Jupyter running in browser, the
        method returns a ReactivelyResizingHtml element which
        is a Jupyter widget to display HTML output in the
        browser. Otherwise, the method returns None.

    Note:
        Any default argument value is overridden by the
        corresponding value in the relevant subsection of the
        UserInterfaceConfig.
    """
    return self._display_according_to_ui_type(
        ui_type=self._extract_ui_type(**kwargs),
        return_output_if_str=False,
        output_method=self._peek,
        **kwargs,
    )

pending_task_details

pending_task_details() -> dict[str, IsPendingData]

Return pending task marker payloads keyed by dataset entry name.

Source code in src/omnipy/data/_mixins/task.py
def pending_task_details(self) -> dict[str, IsPendingData]:
    """Return pending task marker payloads keyed by dataset entry name."""

    self_with_data = cast(HasData, self)
    return {  # pyright: ignore [reportReturnType]
        key: val for key, val in self_with_data.data.items() if isinstance(val, PendingData)
    }

save

save(path: str)

Serialize the dataset to a .tar.gz archive and extract a directory copy.

PARAMETER DESCRIPTION
path

Destination path with or without the .tar.gz suffix.

TYPE: str

Source code in src/omnipy/data/dataset.py
def save(self, path: str):
    """Serialize the dataset to a ``.tar.gz`` archive and extract a directory copy.

    Args:
        path: Destination path with or without the ``.tar.gz`` suffix.
    """
    serializer_registry = self._get_serializer_registry()

    parsed_dataset, serializer = serializer_registry.auto_detect_tar_file_serializer(self)

    if serializer is None:
        print(f'Unable to find a serializer for dataset with data type "{type(self)}". '
              f'Will abort saving...')
    else:
        if not path.endswith('.tar.gz'):
            out_tar_gz_path = f'{path}.tar.gz'

        print(f'Writing dataset as a gzipped tarpack to "{os.path.abspath(out_tar_gz_path)}"')

        with open(out_tar_gz_path, 'wb') as out_tar_gz_file:
            out_tar_gz_file.write(serializer.serialize(parsed_dataset))

        directory = os.path.abspath(out_tar_gz_path[:-7])
        if not os.path.exists(directory):
            os.makedirs(directory)

        tar = tarfile.open(out_tar_gz_path)
        print(f'Extracting content to directory "{os.path.abspath(out_tar_gz_path[:-7])}"')
        tar.extractall(path=directory)
        tar.close()

set_model

set_model(data_file: str, model: type[Model]) -> None

Assign a custom model to one data-file key.

PARAMETER DESCRIPTION
data_file

Dataset key that should use the custom model.

TYPE: str

model

Model class to validate that key against.

TYPE: type[Model]

RAISES DESCRIPTION
ValidationError

If the existing item for the key does not satisfy the custom model.

Source code in src/omnipy/data/multi.py
def set_model(self, data_file: str, model: 'type[Model]') -> None:
    """Assign a custom model to one data-file key.

    Args:
        data_file: Dataset key that should use the custom model.
        model: Model class to validate that key against.

    Raises:
        ValidationError: If the existing item for the key does not satisfy the custom model.
    """
    try:
        self._custom_field_models[data_file] = model
        if data_file in self.data:
            self._validate_data_file(data_file)
        else:
            self.data[data_file] = model()
    except ValidationError:
        del self._custom_field_models[data_file]
        raise

to

to(model_or_dataset_cls: type[_OtherModelOrDatasetT]) -> _OtherModelOrDatasetT

Convert this dataset to another model or dataset class.

PARAMETER DESCRIPTION
model_or_dataset_cls

Target model or dataset class that can be constructed from this dataset.

TYPE: type[_OtherModelOrDatasetT]

RETURNS DESCRIPTION
_OtherModelOrDatasetT

An instance of the requested target class.

Source code in src/omnipy/data/dataset.py
def to(self, model_or_dataset_cls: type[_OtherModelOrDatasetT]) -> '_OtherModelOrDatasetT':
    """Convert this dataset to another model or dataset class.

    Args:
        model_or_dataset_cls: Target model or dataset class that can be constructed from this
            dataset.

    Returns:
        An instance of the requested target class.
    """
    return model_or_dataset_cls(self)

to_data

to_data() -> dict_t[str, Any]

Return the dataset as plain Python contents.

RETURNS DESCRIPTION
dict_t[str, Any]

A mapping from data-file name to plain Python data extracted from each validated item.

Source code in src/omnipy/data/dataset.py
def to_data(self) -> dict_t[str, Any]:
    """Return the dataset as plain Python contents.

    Returns:
        A mapping from data-file name to plain Python data extracted from each validated item.
    """
    return {key: self._check_value(val) for key, val in self.dict(by_alias=True).items()}

to_json

to_json(pretty=True) -> dict_t[str, str]

Serialize each dataset item to JSON.

PARAMETER DESCRIPTION
pretty

Whether to pretty-print the JSON for each item.

DEFAULT: True

RETURNS DESCRIPTION
dict_t[str, str]

A mapping from data-file name to JSON string.

Source code in src/omnipy/data/dataset.py
def to_json(self, pretty=True) -> dict_t[str, str]:
    """Serialize each dataset item to JSON.

    Args:
        pretty: Whether to pretty-print the JSON for each item.

    Returns:
        A mapping from data-file name to JSON string.
    """
    result = {}

    for key, val in self.data.items():
        result[key] = val.to_json(pretty=pretty)

    return result

to_json_schema classmethod

to_json_schema(pretty: bool = True) -> str | dict_t[str, str]

Return a JSON schema for the dataset's serialized contents.

PARAMETER DESCRIPTION
pretty

Whether to return pretty-printed JSON text instead of compact JSON text.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
str | dict_t[str, str]

A JSON schema string describing the dataset contents.

Source code in src/omnipy/data/dataset.py
@classmethod
def to_json_schema(cls, pretty: bool = True) -> str | dict_t[str, str]:
    """Return a JSON schema for the dataset's serialized contents.

    Args:
        pretty: Whether to return pretty-printed JSON text instead of compact JSON text.

    Returns:
        A JSON schema string describing the dataset contents.
    """
    result = {}
    clean_dataset = super(Dataset, Dataset).__class_getitem__(cls.get_type())
    schema = clean_dataset.schema()
    for key, val in schema['properties'][DATA_KEY].items():
        # Remove the first part of the type definition of 'data', added
        # as a hack to stop coercing of e.g. [{'a': 'b', 'c': 'd'}]
        # to {'a': 'c'}
        if key == 'anyOf':
            result['type'] = 'object'
            result['additionalProperties'] = {
                '$ref': '#/definitions/' + pyd.normalize_name(clean_dataset.get_type().__name__)
            }
        else:
            result[key] = val

    result['title'] = clean_dataset.__name__
    result['definitions'] = schema['definitions']

    for model_desc in result['definitions'].values():
        if 'orig_model' in model_desc:
            del model_desc['orig_model']

    if pretty:
        return cls._pretty_print_json(result)
    else:
        return json.dumps(result)

update_forward_refs classmethod

update_forward_refs(
    calling_module: str | None = None, prev_visited_classes: set[type] | None = None, **localns: Any
) -> None

Try to update ForwardRefs on fields based on this Model, globalns and localns.

Source code in src/omnipy/data/dataset.py
@classmethod
def update_forward_refs(
    cls,
    calling_module: str | None = None,
    prev_visited_classes: set[type] | None = None,
    **localns: Any,
) -> None:
    """
    Try to update ForwardRefs on fields based on this Model, globalns and localns.
    """

    from omnipy.data.model import is_model_subclass

    if prev_visited_classes is None:
        prev_visited_classes = set()
    elif cls in prev_visited_classes:
        return

    # Merge the namespaces of the Datasets's own module and the
    # calling module to the local namespace for evaluation of forward
    # references, which is necessary for cases where the Dataset is
    # defined in a different module than where it is used, e.g. when
    # the Dataset is defined in a library and used by a user in their
    # own code.
    if calling_module is None:
        calling_module = get_calling_module_name()
    own_module_ns, globalns = \
        build_own_module_and_global_namespace_for_forward_refs(cls, calling_module, **localns)

    prev_type = cls._get_data_field().type_

    super().update_forward_refs(**globalns)

    cls._get_data_field().type_ = evaluate_any_forward_refs_if_possible(prev_type, **globalns)
    if DATA_KEY in cls.__annotations__:
        cls.__annotations__[DATA_KEY] = evaluate_any_forward_refs_if_possible(
            cls.__annotations__[DATA_KEY], **globalns)

    cls._clean_type_caches()

    prev_visited_classes.add(cls)

    # Merge the Dataset's own module namespace into
    # localns before propagating. This is to allow Model classes and
    # pydantic-generated parametrized base classes (which have
    # __module__='omnipy.data.dataset' rather than the defining
    # module) to still resolve forward refs that only exist
    # in the defining module's namespace.

    extra_ns: dict[str, Any] = {}
    extra_ns.update(own_module_ns)
    extra_ns.update(localns)

    # Propagate update_forward_refs to parent Dataset classes but
    # retaining the same calling module. This is needed to ensure the
    # correct context is used to resolve forward references in complex
    # inheritance hierarchies.
    #
    # We explicitly call `update_forward_refs` on immediate parent
    # classes (`__bases__`) instead of relying solely on
    # `super().update_forward_refs()`. This is because `super()`
    # inside this classmethod resolves relative to `Dataset` in the MRO,
    # silently bypassing custom logic on any intermediate `Dataset`
    # subclasses. Explicitly propagating through `__bases__` ensures
    # that class-level setups are correctly applied to all parents
    # exactly once, efficiently preventing redundant updates.
    for base in cls.__bases__:
        if is_dataset_subclass(base) and base is not Dataset:
            base.update_forward_refs(
                calling_module=calling_module,
                prev_visited_classes=prev_visited_classes,
                **extra_ns,
            )

    # As above, but now propagate update_forward_refs to the types of
    # the Dataset (e.g. the Model).
    for type_variant in split_to_union_variants(cls.get_type()):
        if is_dataset_subclass(type_variant) or is_model_subclass(type_variant):
            type_variant.update_forward_refs(
                calling_module=calling_module,
                prev_visited_classes=prev_visited_classes,
                **extra_ns,
            )

    cls.__name__ = remove_forward_ref_notation(cls.__name__)
    cls.__qualname__ = remove_forward_ref_notation(cls.__qualname__)

update_reactive_views

update_reactive_views()
Source code in src/omnipy/data/_mixins/display.py
def update_reactive_views(self):
    from omnipy import runtime
    assert runtime.objects.reactive is not None
    obj_id_update_flags = runtime.objects.reactive.obj_id_update_flags.value.copy()
    flag = obj_id_update_flags.get(id(self), False)
    obj_id_update_flags[id(self)] = not flag
    runtime.objects.reactive.obj_id_update_flags.set(obj_id_update_flags)

validate classmethod

validate(value: Any) -> Self

Validate arbitrary input as an instance of this dataset class.

This method is primarily part of the Pydantic integration layer and preserves dataset validation behavior when iterables are accepted as input.

PARAMETER DESCRIPTION
value

The value to validate.

TYPE: Any

RETURNS DESCRIPTION
Self

A validated dataset instance.

Source code in src/omnipy/data/dataset.py
@classmethod
def validate(cls, value: Any) -> Self:
    """Validate arbitrary input as an instance of this dataset class.

    This method is primarily part of the Pydantic integration layer and preserves dataset
    validation behavior when iterables are accepted as input.

    Args:
        value: The value to validate.

    Returns:
        A validated dataset instance.
    """
    # TODO: Doublecheck if validate() method is still needed for pydantic v2

    # validate_cls_counts[cls.__name__] += 1
    if is_iterable(value) and not isinstance(value, Mapping):
        value = cls._check_iterable(value)

    return super().validate({'data': value})