Skip to content

omnipy.config.data

CLASS DESCRIPTION
BrowserUserInterfaceConfig

Configuration for browser user interface type.

ColorConfig

Configuration for color output.

DataConfig

Configuration for data module.

DimsModeConfig
DimsModeMixin
FontConfig
HtmlUserInterfaceConfig
HttpConfig
HttpRequestsConfig

Configuration for HTTP requests.

JupyterUserInterfaceConfig
LayoutConfig
ModelConfig

Configuration for behavior of the Model class.

OverflowConfig

Configuration for overflow handling.

TerminalUserInterfaceConfig
TextConfig
UserInterfaceConfig

Configuration for the user interface, including inputs and output

UserInterfaceTypeConfig

BrowserUserInterfaceConfig

Bases: HtmlUserInterfaceConfig

Configuration for browser user interface type.

METHOD DESCRIPTION
__init__
ATTRIBUTE DESCRIPTION
height

width

Source code in src/omnipy/config/data.py
class BrowserUserInterfaceConfig(HtmlUserInterfaceConfig):
    """
    Configuration for browser user interface type.
    """
    def __init__(self, **data: Any) -> None:
        super().__init__(**data)
        self.width = BROWSER_DEFAULT_WIDTH
        self.height = BROWSER_DEFAULT_HEIGHT
        self.color.system = detect_display_color_system(UserInterfaceType.BROWSER_PAGE)
        self.color.dark_background = False

height instance-attribute

width instance-attribute

__init__

__init__(**data: Any) -> None
Source code in src/omnipy/config/data.py
def __init__(self, **data: Any) -> None:
    super().__init__(**data)
    self.width = BROWSER_DEFAULT_WIDTH
    self.height = BROWSER_DEFAULT_HEIGHT
    self.color.system = detect_display_color_system(UserInterfaceType.BROWSER_PAGE)
    self.color.dark_background = False

ColorConfig

Bases: ConfigBase

Configuration for color output.

METHOD DESCRIPTION
default_style
ATTRIBUTE DESCRIPTION
dark_background

TYPE: bool

solid_background

TYPE: bool

style

TYPE: AllColorStyles.Literals | str

system

TYPE: DisplayColorSystem.Literals

Source code in src/omnipy/config/data.py
class ColorConfig(ConfigBase):
    """
    Configuration for color output.
    """
    system: DisplayColorSystem.Literals = DisplayColorSystem.AUTO
    style: AllColorStyles.Literals | str = RecommendedColorStyles.AUTO
    dark_background: bool = DEFAULT_DARK_BACKGROUND
    solid_background: bool = False

    @pyd.root_validator()
    def default_style(cls, values: _ColorConfigTypedDict) -> _ColorConfigTypedDict:
        if values['style'] in RecommendedColorStyles:
            values['style'] = RecommendedColorStyles.get_default_style(
                values['system'],
                values['dark_background'],
                values['solid_background'],
            )
        return values

dark_background class-attribute instance-attribute

dark_background: bool = DEFAULT_DARK_BACKGROUND

solid_background class-attribute instance-attribute

solid_background: bool = False

style class-attribute instance-attribute

system class-attribute instance-attribute

default_style

default_style(values: _ColorConfigTypedDict) -> _ColorConfigTypedDict
Source code in src/omnipy/config/data.py
@pyd.root_validator()
def default_style(cls, values: _ColorConfigTypedDict) -> _ColorConfigTypedDict:
    if values['style'] in RecommendedColorStyles:
        values['style'] = RecommendedColorStyles.get_default_style(
            values['system'],
            values['dark_background'],
            values['solid_background'],
        )
    return values

DataConfig

Bases: ConfigBase

Configuration for data module.

ATTRIBUTE DESCRIPTION
http

TYPE: IsHttpConfig

model

TYPE: IsModelConfig

ui

TYPE: IsUserInterfaceConfig

Source code in src/omnipy/config/data.py
class DataConfig(ConfigBase):
    """
    Configuration for data module.
    """
    ui: IsUserInterfaceConfig = pyd.Field(default_factory=lambda: UserInterfaceConfig())
    model: IsModelConfig = pyd.Field(default_factory=lambda: ModelConfig())
    http: IsHttpConfig = pyd.Field(default_factory=HttpConfig)

http class-attribute instance-attribute

http: IsHttpConfig = pyd.Field(default_factory=HttpConfig)

model class-attribute instance-attribute

model: IsModelConfig = pyd.Field(default_factory=lambda: ModelConfig())

ui class-attribute instance-attribute

ui: IsUserInterfaceConfig = pyd.Field(default_factory=lambda: UserInterfaceConfig())

DimsModeConfig

Bases: UserInterfaceTypeConfig, DimsModeMixin, ABC

CLASS DESCRIPTION
Config
METHOD DESCRIPTION
check_and_set_auto_height
check_and_set_auto_width
Source code in src/omnipy/config/data.py
class DimsModeConfig(UserInterfaceTypeConfig, DimsModeMixin, ABC):
    class Config:  # pyright: ignore [reportIncompatibleVariableOverride]
        validate_all = True
        validate_assignment = True

    @classmethod
    @abstractmethod
    def _get_available_display_dims(
            cls) -> tuple[pyd.NonNegativeInt | None, pyd.NonNegativeInt | None]:
        ...

    @pyd.validator('width', always=True)
    def check_and_set_auto_width(
        cls,
        value: pyd.NonNegativeInt,
        values: dict[str, Any],
    ) -> pyd.NonNegativeInt:
        return cls._get_available_display_dim_if_auto_dims_mode(value, values, index=0)

    @pyd.validator('height', always=True)
    def check_and_set_auto_height(
        cls,
        value: pyd.NonNegativeInt,
        values: dict[str, Any],
    ) -> pyd.NonNegativeInt:
        return cls._get_available_display_dim_if_auto_dims_mode(value, values, index=1)

    @classmethod
    def _get_available_display_dim_if_auto_dims_mode(
        cls,
        value: pyd.NonNegativeInt,
        values: dict[str, Any],
        index: int,
    ):
        if values.get('dims_mode') is DisplayDimensionsUpdateMode.AUTO:
            fetched_val = cls._get_available_display_dims()[index]
            if fetched_val:
                return fetched_val
        return value

    # Override __getattribute__ to dynamically update width and height
    # if dims_mode is AUTO and the display size is available.
    def __getattribute__(self, attr):
        if (attr in ['width', 'height']
                and object.__getattribute__(self, 'dims_mode') is DisplayDimensionsUpdateMode.AUTO):
            width, height = object.__getattribute__(self, '_get_available_display_dims')()
            if width is not None:
                setattr(self, 'width', width)
            if height is not None:
                setattr(self, 'height', height)
        return object.__getattribute__(self, attr)

Config

ATTRIBUTE DESCRIPTION
validate_all

validate_assignment

Source code in src/omnipy/config/data.py
class Config:  # pyright: ignore [reportIncompatibleVariableOverride]
    validate_all = True
    validate_assignment = True

validate_all class-attribute instance-attribute

validate_all = True

validate_assignment class-attribute instance-attribute

validate_assignment = True

check_and_set_auto_height

check_and_set_auto_height(value: pyd.NonNegativeInt, values: dict[str, Any]) -> pyd.NonNegativeInt
Source code in src/omnipy/config/data.py
@pyd.validator('height', always=True)
def check_and_set_auto_height(
    cls,
    value: pyd.NonNegativeInt,
    values: dict[str, Any],
) -> pyd.NonNegativeInt:
    return cls._get_available_display_dim_if_auto_dims_mode(value, values, index=1)

check_and_set_auto_width

check_and_set_auto_width(value: pyd.NonNegativeInt, values: dict[str, Any]) -> pyd.NonNegativeInt
Source code in src/omnipy/config/data.py
@pyd.validator('width', always=True)
def check_and_set_auto_width(
    cls,
    value: pyd.NonNegativeInt,
    values: dict[str, Any],
) -> pyd.NonNegativeInt:
    return cls._get_available_display_dim_if_auto_dims_mode(value, values, index=0)

DimsModeMixin

Bases: pyd.BaseModel

ATTRIBUTE DESCRIPTION
dims_mode

TYPE: DisplayDimensionsUpdateMode.Literals

Source code in src/omnipy/config/data.py
class DimsModeMixin(pyd.BaseModel):
    dims_mode: DisplayDimensionsUpdateMode.Literals = DisplayDimensionsUpdateMode.AUTO

dims_mode class-attribute instance-attribute

FontConfig

Bases: ConfigBase

ATTRIBUTE DESCRIPTION
families

TYPE: tuple[str, ...]

line_height

TYPE: pyd.NonNegativeFloat

size

TYPE: pyd.NonNegativeInt

weight

TYPE: pyd.NonNegativeInt

Source code in src/omnipy/config/data.py
class FontConfig(ConfigBase):
    families: tuple[str, ...] = (
        'Menlo',
        'DejaVu Sans Mono',
        'Consolas',
        'Courier New',
        'monospace',
    )
    size: pyd.NonNegativeInt = 14
    weight: pyd.NonNegativeInt = 400
    line_height: pyd.NonNegativeFloat = 1.25

families class-attribute instance-attribute

families: tuple[str, ...] = ('Menlo', 'DejaVu Sans Mono', 'Consolas', 'Courier New', 'monospace')

line_height class-attribute instance-attribute

line_height: pyd.NonNegativeFloat = 1.25

size class-attribute instance-attribute

size: pyd.NonNegativeInt = 14

weight class-attribute instance-attribute

weight: pyd.NonNegativeInt = 400

HtmlUserInterfaceConfig

Bases: UserInterfaceTypeConfig

ATTRIBUTE DESCRIPTION
font

TYPE: IsFontConfig

Source code in src/omnipy/config/data.py
class HtmlUserInterfaceConfig(UserInterfaceTypeConfig):
    font: IsFontConfig = pyd.Field(default_factory=FontConfig)

font class-attribute instance-attribute

font: IsFontConfig = pyd.Field(default_factory=FontConfig)

HttpConfig

Bases: ConfigBase

METHOD DESCRIPTION
update_http_defaults
ATTRIBUTE DESCRIPTION
defaults

TYPE: IsHttpRequestsConfig

for_host

TYPE: defaultdict[str, IsHttpRequestsConfig]

Source code in src/omnipy/config/data.py
class HttpConfig(ConfigBase):
    defaults: IsHttpRequestsConfig = pyd.Field(default_factory=HttpRequestsConfig)
    for_host: defaultdict[str, IsHttpRequestsConfig] = pyd.Field(
        default_factory=lambda: defaultdict(HttpRequestsConfig))

    @pyd.validator('for_host', always=True)
    def update_http_defaults(cls,
                             _for_host: defaultdict[str, HttpRequestsConfig],
                             values: dict[str, Any]) -> defaultdict[str, HttpRequestsConfig]:
        return defaultdict(lambda: values['defaults'].copy())

defaults class-attribute instance-attribute

defaults: IsHttpRequestsConfig = pyd.Field(default_factory=HttpRequestsConfig)

for_host class-attribute instance-attribute

for_host: defaultdict[str, IsHttpRequestsConfig] = pyd.Field(
    default_factory=lambda: defaultdict(HttpRequestsConfig)
)

update_http_defaults

update_http_defaults(
    _for_host: defaultdict[str, HttpRequestsConfig], values: dict[str, Any]
) -> defaultdict[str, HttpRequestsConfig]
Source code in src/omnipy/config/data.py
@pyd.validator('for_host', always=True)
def update_http_defaults(cls,
                         _for_host: defaultdict[str, HttpRequestsConfig],
                         values: dict[str, Any]) -> defaultdict[str, HttpRequestsConfig]:
    return defaultdict(lambda: values['defaults'].copy())

HttpRequestsConfig

Bases: ConfigBase

Configuration for HTTP requests.

ATTRIBUTE DESCRIPTION
requests_per_time_period

TYPE: float

retry_attempts

TYPE: int

retry_backoff_strategy

TYPE: BackoffStrategy.Literals

retry_http_statuses

TYPE: tuple[int, ...]

time_period_in_secs

TYPE: float

Source code in src/omnipy/config/data.py
class HttpRequestsConfig(ConfigBase):
    """
    Configuration for HTTP requests.
    """
    # For RateLimitingClientSession helper class
    requests_per_time_period: float = 60
    time_period_in_secs: float = 60

    # For get_*_from_api_endpoint tasks
    retry_http_statuses: tuple[int, ...] = (408, 425, 429, 500, 502, 503, 504)
    retry_attempts: int = 5
    retry_backoff_strategy: BackoffStrategy.Literals = BackoffStrategy.EXPONENTIAL

requests_per_time_period class-attribute instance-attribute

requests_per_time_period: float = 60

retry_attempts class-attribute instance-attribute

retry_attempts: int = 5

retry_backoff_strategy class-attribute instance-attribute

retry_http_statuses class-attribute instance-attribute

retry_http_statuses: tuple[int, ...] = (408, 425, 429, 500, 502, 503, 504)

time_period_in_secs class-attribute instance-attribute

time_period_in_secs: float = 60

JupyterUserInterfaceConfig

Bases: HtmlUserInterfaceConfig, DimsModeConfig

METHOD DESCRIPTION
__init__
ATTRIBUTE DESCRIPTION
height

width

Source code in src/omnipy/config/data.py
class JupyterUserInterfaceConfig(HtmlUserInterfaceConfig, DimsModeConfig):
    @classmethod
    @override
    def _get_available_display_dims(
            cls) -> tuple[pyd.NonNegativeInt | None, pyd.NonNegativeInt | None]:
        # For now, Jupyter width is pushed, not fetched. Hence, we return None.
        return None, None

    def __init__(self, **data: Any) -> None:
        super().__init__(**data)
        self.width = JUPYTER_DEFAULT_WIDTH
        self.height = JUPYTER_DEFAULT_HEIGHT
        self.color.system = detect_display_color_system(UserInterfaceType.JUPYTER)
        self.color.dark_background = False

height instance-attribute

width instance-attribute

__init__

__init__(**data: Any) -> None
Source code in src/omnipy/config/data.py
def __init__(self, **data: Any) -> None:
    super().__init__(**data)
    self.width = JUPYTER_DEFAULT_WIDTH
    self.height = JUPYTER_DEFAULT_HEIGHT
    self.color.system = detect_display_color_system(UserInterfaceType.JUPYTER)
    self.color.dark_background = False

LayoutConfig

Bases: ConfigBase

ATTRIBUTE DESCRIPTION
justify

TYPE: Justify.Literals

max_nesting_depth

TYPE: pyd.NonNegativeInt | None

max_panels_hor

TYPE: pyd.NonNegativeInt | None

max_title_height

TYPE: MaxTitleHeight.Literals

min_crop_width

TYPE: pyd.NonNegativeInt

min_panel_width

TYPE: pyd.NonNegativeInt

overflow

TYPE: IsOverflowConfig

panel_design

TYPE: PanelDesign.Literals

panel_title_at_top

TYPE: bool

Source code in src/omnipy/config/data.py
class LayoutConfig(ConfigBase):
    overflow: IsOverflowConfig = pyd.Field(default_factory=OverflowConfig)
    panel_design: PanelDesign.Literals = PanelDesign.TABLE
    panel_title_at_top: bool = True
    max_title_height: MaxTitleHeight.Literals = MaxTitleHeight.AUTO
    min_panel_width: pyd.NonNegativeInt = MIN_PANEL_WIDTH
    min_crop_width: pyd.NonNegativeInt = MIN_CROP_WIDTH
    max_panels_hor: pyd.NonNegativeInt | None = MAX_PANELS_HORIZONTALLY
    max_nesting_depth: pyd.NonNegativeInt | None = MAX_PANEL_NESTING_DEPTH
    justify: Justify.Literals = Justify.LEFT

justify class-attribute instance-attribute

max_nesting_depth class-attribute instance-attribute

max_nesting_depth: pyd.NonNegativeInt | None = MAX_PANEL_NESTING_DEPTH

max_panels_hor class-attribute instance-attribute

max_panels_hor: pyd.NonNegativeInt | None = MAX_PANELS_HORIZONTALLY

max_title_height class-attribute instance-attribute

min_crop_width class-attribute instance-attribute

min_crop_width: pyd.NonNegativeInt = MIN_CROP_WIDTH

min_panel_width class-attribute instance-attribute

min_panel_width: pyd.NonNegativeInt = MIN_PANEL_WIDTH

overflow class-attribute instance-attribute

overflow: IsOverflowConfig = pyd.Field(default_factory=OverflowConfig)

panel_design class-attribute instance-attribute

panel_title_at_top class-attribute instance-attribute

panel_title_at_top: bool = True

ModelConfig

Bases: ConfigBase

Configuration for behavior of the Model class.

ATTRIBUTE DESCRIPTION
dynamically_convert_elements_to_models

TYPE: bool

interactive

TYPE: bool

Source code in src/omnipy/config/data.py
class ModelConfig(ConfigBase):
    """
    Configuration for behavior of the Model class.
    """
    interactive: bool = True
    dynamically_convert_elements_to_models: bool = False

dynamically_convert_elements_to_models class-attribute instance-attribute

dynamically_convert_elements_to_models: bool = False

interactive class-attribute instance-attribute

interactive: bool = True

OverflowConfig

Bases: ConfigBase

Configuration for overflow handling.

ATTRIBUTE DESCRIPTION
horizontal

TYPE: HorizontalOverflowMode.Literals

vertical

TYPE: VerticalOverflowMode.Literals

Source code in src/omnipy/config/data.py
class OverflowConfig(ConfigBase):
    """
    Configuration for overflow handling.
    """
    horizontal: HorizontalOverflowMode.Literals = HorizontalOverflowMode.ELLIPSIS
    vertical: VerticalOverflowMode.Literals = VerticalOverflowMode.ELLIPSIS_BOTTOM

horizontal class-attribute instance-attribute

vertical class-attribute instance-attribute

TerminalUserInterfaceConfig

Bases: DimsModeConfig

Source code in src/omnipy/config/data.py
class TerminalUserInterfaceConfig(DimsModeConfig):
    @classmethod
    @override
    def _get_available_display_dims(
            cls) -> tuple[pyd.NonNegativeInt | None, pyd.NonNegativeInt | None]:
        width, height = shutil.get_terminal_size(fallback=(0, 0))
        return None if width == 0 else width, None if height == 0 else height

TextConfig

Bases: ConfigBase

ATTRIBUTE DESCRIPTION
debug_mode

TYPE: bool

indent_tab_size

TYPE: pyd.NonNegativeInt

overflow

TYPE: IsOverflowConfig

pretty_printer

TYPE: PrettyPrinterLib.Literals

proportional_freedom

TYPE: pyd.NonNegativeFloat

tab_size

TYPE: pyd.NonNegativeInt

Source code in src/omnipy/config/data.py
class TextConfig(ConfigBase):
    overflow: IsOverflowConfig = pyd.Field(default_factory=OverflowConfig)
    tab_size: pyd.NonNegativeInt = 4
    indent_tab_size: pyd.NonNegativeInt = 2
    pretty_printer: PrettyPrinterLib.Literals = PrettyPrinterLib.AUTO
    proportional_freedom: pyd.NonNegativeFloat = 2.5
    debug_mode: bool = False

debug_mode class-attribute instance-attribute

debug_mode: bool = False

indent_tab_size class-attribute instance-attribute

indent_tab_size: pyd.NonNegativeInt = 2

overflow class-attribute instance-attribute

overflow: IsOverflowConfig = pyd.Field(default_factory=OverflowConfig)

pretty_printer class-attribute instance-attribute

proportional_freedom class-attribute instance-attribute

proportional_freedom: pyd.NonNegativeFloat = 2.5

tab_size class-attribute instance-attribute

tab_size: pyd.NonNegativeInt = 4

UserInterfaceConfig

Bases: ConfigBase

Configuration for the user interface, including inputs and output devices.

METHOD DESCRIPTION
get_ui_type_config
ATTRIBUTE DESCRIPTION
browser

TYPE: IsBrowserUserInterfaceConfig

cache_dir_path

TYPE: str

detected_type

TYPE: SpecifiedUserInterfaceType.Literals

jupyter

TYPE: IsJupyterUserInterfaceConfig

layout

TYPE: IsLayoutConfig

terminal

TYPE: IsTerminalUserInterfaceConfig

text

TYPE: IsTextConfig

Source code in src/omnipy/config/data.py
class UserInterfaceConfig(ConfigBase):
    """
    Configuration for the user interface, including inputs and output
    devices.
    """
    detected_type: SpecifiedUserInterfaceType.Literals = UserInterfaceType.UNKNOWN
    terminal: IsTerminalUserInterfaceConfig = pyd.Field(default_factory=TerminalUserInterfaceConfig)
    jupyter: IsJupyterUserInterfaceConfig = pyd.Field(default_factory=JupyterUserInterfaceConfig)
    browser: IsBrowserUserInterfaceConfig = pyd.Field(default_factory=BrowserUserInterfaceConfig)
    text: IsTextConfig = pyd.Field(default_factory=TextConfig)
    layout: IsLayoutConfig = pyd.Field(default_factory=LayoutConfig)
    cache_dir_path: str = pyd.Field(default_factory=_get_cache_dir_path)

    def get_ui_type_config(
        self,
        ui_type: SpecifiedUserInterfaceType.Literals,
    ) -> IsUserInterfaceTypeConfig:  # pyright: ignore [reportReturnType]
        match ui_type:
            case x if UserInterfaceType.is_terminal(x):
                return self.terminal
            case x if UserInterfaceType.is_jupyter(x):
                return self.jupyter
            case x if UserInterfaceType.is_browser(x):
                return self.browser

browser class-attribute instance-attribute

cache_dir_path class-attribute instance-attribute

cache_dir_path: str = pyd.Field(default_factory=_get_cache_dir_path)

detected_type class-attribute instance-attribute

jupyter class-attribute instance-attribute

layout class-attribute instance-attribute

layout: IsLayoutConfig = pyd.Field(default_factory=LayoutConfig)

terminal class-attribute instance-attribute

text class-attribute instance-attribute

text: IsTextConfig = pyd.Field(default_factory=TextConfig)

get_ui_type_config

Source code in src/omnipy/config/data.py
def get_ui_type_config(
    self,
    ui_type: SpecifiedUserInterfaceType.Literals,
) -> IsUserInterfaceTypeConfig:  # pyright: ignore [reportReturnType]
    match ui_type:
        case x if UserInterfaceType.is_terminal(x):
            return self.terminal
        case x if UserInterfaceType.is_jupyter(x):
            return self.jupyter
        case x if UserInterfaceType.is_browser(x):
            return self.browser

UserInterfaceTypeConfig

Bases: ConfigBase

METHOD DESCRIPTION
set_width_and_height

Sets width and height, and notifies subscribers of the change. Only

ATTRIBUTE DESCRIPTION
color

TYPE: IsColorConfig

height

TYPE: pyd.NonNegativeInt | None

width

TYPE: pyd.NonNegativeInt | None

Source code in src/omnipy/config/data.py
class UserInterfaceTypeConfig(ConfigBase):
    width: pyd.NonNegativeInt | None = TERMINAL_DEFAULT_WIDTH
    height: pyd.NonNegativeInt | None = TERMINAL_DEFAULT_HEIGHT
    color: IsColorConfig = pyd.Field(default_factory=ColorConfig)

    def set_width_and_height(
        self,
        width: pyd.NonNegativeInt | None,
        height: pyd.NonNegativeInt | None,
    ) -> None:
        """
        Sets width and height, and notifies subscribers of the change. Only
        notifies self-subscribers once after both attributes have been
        updated.
        """
        for (dim_name, dim_value) in (('width', width), ('height', height)):
            object.__setattr__(self, dim_name, dim_value)
            self._call_subscribers(dim_name, dim_value)
        self._call_self_subscribers()

color class-attribute instance-attribute

color: IsColorConfig = pyd.Field(default_factory=ColorConfig)

height class-attribute instance-attribute

width class-attribute instance-attribute

set_width_and_height

set_width_and_height(width: pyd.NonNegativeInt | None, height: pyd.NonNegativeInt | None) -> None

Sets width and height, and notifies subscribers of the change. Only notifies self-subscribers once after both attributes have been updated.

Source code in src/omnipy/config/data.py
def set_width_and_height(
    self,
    width: pyd.NonNegativeInt | None,
    height: pyd.NonNegativeInt | None,
) -> None:
    """
    Sets width and height, and notifies subscribers of the change. Only
    notifies self-subscribers once after both attributes have been
    updated.
    """
    for (dim_name, dim_value) in (('width', width), ('height', height)):
        object.__setattr__(self, dim_name, dim_value)
        self._call_subscribers(dim_name, dim_value)
    self._call_self_subscribers()