Skip to content

pywry.models

Core Pydantic models for content, window configuration, and events.


Window Mode

pywry.models.WindowMode

Bases: str, Enum

Window management mode.

Attributes

NEW_WINDOW class-attribute instance-attribute

NEW_WINDOW = 'new_window'

SINGLE_WINDOW class-attribute instance-attribute

SINGLE_WINDOW = 'single_window'

MULTI_WINDOW class-attribute instance-attribute

MULTI_WINDOW = 'multi_window'

NOTEBOOK class-attribute instance-attribute

NOTEBOOK = 'notebook'

BROWSER class-attribute instance-attribute

BROWSER = 'browser'

Theme Mode

pywry.models.ThemeMode

Bases: str, Enum

Window theme mode.

Attributes

LIGHT class-attribute instance-attribute

LIGHT = 'light'

DARK class-attribute instance-attribute

DARK = 'dark'

SYSTEM class-attribute instance-attribute

SYSTEM = 'system'

Window Configuration

pywry.models.WindowConfig

Bases: BaseModel

Configuration for window creation.

Fields are split into two groups:

Application-level fields — used by PyWry's template and content pipeline (theme, enable_plotly, aggrid_theme, etc.).

Builder-level fields — forwarded to WebviewWindowBuilder.build() in the subprocess. Fields marked (build-only) can only be set at window creation time; they have no post-creation set_* equivalent.

Attributes

title class-attribute instance-attribute

title: str = 'PyWry'

width class-attribute instance-attribute

width: int = Field(default=1280, ge=200)

height class-attribute instance-attribute

height: int = Field(default=720, ge=150)

min_width class-attribute instance-attribute

min_width: int = Field(default=400, ge=100)

min_height class-attribute instance-attribute

min_height: int = Field(default=300, ge=100)

theme class-attribute instance-attribute

theme: ThemeMode = DARK

center class-attribute instance-attribute

center: bool = True

devtools class-attribute instance-attribute

devtools: bool = False

allow_network class-attribute instance-attribute

allow_network: bool = True

enable_plotly class-attribute instance-attribute

enable_plotly: bool = False

enable_aggrid class-attribute instance-attribute

enable_aggrid: bool = False

plotly_theme class-attribute instance-attribute

plotly_theme: Literal['plotly', 'plotly_white', 'plotly_dark', 'ggplot2', 'seaborn', 'simple_white'] = 'plotly_dark'

aggrid_theme class-attribute instance-attribute

aggrid_theme: Literal['quartz', 'alpine', 'balham', 'material'] = 'alpine'

resizable class-attribute instance-attribute

resizable: bool = True

decorations class-attribute instance-attribute

decorations: bool = True

always_on_top class-attribute instance-attribute

always_on_top: bool = False

always_on_bottom class-attribute instance-attribute

always_on_bottom: bool = False

transparent class-attribute instance-attribute

transparent: bool = False

fullscreen class-attribute instance-attribute

fullscreen: bool = False

maximized class-attribute instance-attribute

maximized: bool = False

focused class-attribute instance-attribute

focused: bool = True

visible class-attribute instance-attribute

visible: bool = True

shadow class-attribute instance-attribute

shadow: bool = True

skip_taskbar class-attribute instance-attribute

skip_taskbar: bool = False

content_protected class-attribute instance-attribute

content_protected: bool = False

user_agent class-attribute instance-attribute

user_agent: str | None = None

incognito class-attribute instance-attribute

incognito: bool = False

initialization_script class-attribute instance-attribute

initialization_script: str | None = None

drag_and_drop class-attribute instance-attribute

drag_and_drop: bool = True

_BUILDER_FIELDS class-attribute

_BUILDER_FIELDS: set[str] = {'resizable', 'decorations', 'always_on_top', 'always_on_bottom', 'transparent', 'fullscreen', 'maximized', 'focused', 'visible', 'shadow', 'skip_taskbar', 'content_protected', 'user_agent', 'incognito', 'initialization_script', 'drag_and_drop'}

Functions

builder_kwargs

builder_kwargs() -> dict[str, Any]

Return non-default builder kwargs for WebviewWindowBuilder.build().

Only includes fields whose values differ from the Pydantic defaults, keeping the IPC payload minimal. title and inner_size are always handled separately by the caller.

validate_dimensions

validate_dimensions() -> WindowConfig

Validate min dimensions don't exceed actual dimensions.


HTML Content

pywry.models.HtmlContent

Bases: BaseModel

HTML content to display in a window.

Attributes

html instance-attribute

html: str

json_data class-attribute instance-attribute

json_data: dict[str, Any] | None = None

init_script class-attribute instance-attribute

init_script: str | None = None

css_files class-attribute instance-attribute

css_files: list[Path | str] | None = None

script_files class-attribute instance-attribute

script_files: list[Path | str] | None = None

inline_css class-attribute instance-attribute

inline_css: str | None = None

watch class-attribute instance-attribute

watch: bool = False

Functions

convert_paths classmethod

convert_paths(v: Any) -> list[Path | str] | None

Convert string paths to Path objects.

PARAMETER DESCRIPTION
v

The value to convert.

TYPE: Any

RETURNS DESCRIPTION
list of Path or str, or None

Converted path list or None.


Event Models

Generic Event

pywry.models.GenericEvent

Bases: BaseModel

Generic event for custom event handling.

Attributes
event_type instance-attribute
event_type: str
data class-attribute instance-attribute
data: Any = None
window_label instance-attribute
window_label: str
timestamp class-attribute instance-attribute
timestamp: datetime = Field(default_factory=now)
Functions
validate_event_type_format classmethod
validate_event_type_format(v: str) -> str

Validate event type matches namespace:event-name pattern.

PARAMETER DESCRIPTION
v

The event type string to validate.

TYPE: str

RETURNS DESCRIPTION
str

The validated event type.

RAISES DESCRIPTION
ValueError

If the event type is invalid.

Result Event

pywry.models.ResultEvent

Bases: BaseModel

Result sent from JavaScript via window.pywry.result().

Attributes
data instance-attribute
data: Any
window_label instance-attribute
window_label: str

Plotly Click Event

pywry.models.PlotlyClickEvent

Bases: BaseModel

Plotly click event data.

Attributes
point_indices class-attribute instance-attribute
point_indices: list[int] = Field(default_factory=list)
curve_number class-attribute instance-attribute
curve_number: int = 0
point_data class-attribute instance-attribute
point_data: dict[str, Any] = Field(default_factory=dict)
window_label class-attribute instance-attribute
window_label: str = ''

Plotly Select Event

pywry.models.PlotlySelectEvent

Bases: BaseModel

Plotly selection event data.

Attributes
points class-attribute instance-attribute
points: list[dict[str, Any]] = Field(default_factory=list)
range class-attribute instance-attribute
range: dict[str, Any] | None = None
window_label class-attribute instance-attribute
window_label: str = ''

Plotly Hover Event

pywry.models.PlotlyHoverEvent

Bases: BaseModel

Plotly hover event data.

Attributes
point_indices class-attribute instance-attribute
point_indices: list[int] = Field(default_factory=list)
curve_number class-attribute instance-attribute
curve_number: int = 0
point_data class-attribute instance-attribute
point_data: dict[str, Any] = Field(default_factory=dict)
window_label class-attribute instance-attribute
window_label: str = ''

Plotly Relayout Event

pywry.models.PlotlyRelayoutEvent

Bases: BaseModel

Plotly relayout event data (zoom, pan, etc.).

Attributes
relayout_data class-attribute instance-attribute
relayout_data: dict[str, Any] = Field(default_factory=dict)
window_label class-attribute instance-attribute
window_label: str = ''

Validation Functions

pywry.models.validate_event_type

validate_event_type(event_type: str) -> bool

Validate event type matches namespace:event-name pattern or is wildcard.

PARAMETER DESCRIPTION
event_type

The event type string to validate.

TYPE: str

RETURNS DESCRIPTION
bool

True if valid, False otherwise.


Grid Events

pywry.models.GridSelectionEvent

Bases: BaseModel

AG Grid selection event data.

Attributes

selected_rows class-attribute instance-attribute

selected_rows: list[dict[str, Any]] = Field(default_factory=list)

selected_row_ids class-attribute instance-attribute

selected_row_ids: list[str] = Field(default_factory=list)

window_label class-attribute instance-attribute

window_label: str = ''

pywry.models.GridCellEvent

Bases: BaseModel

AG Grid cell edit event data.

Attributes

row_id class-attribute instance-attribute

row_id: str = ''

row_index class-attribute instance-attribute

row_index: int = 0

column class-attribute instance-attribute

column: str = ''

old_value class-attribute instance-attribute

old_value: Any = None

new_value class-attribute instance-attribute

new_value: Any = None

window_label class-attribute instance-attribute

window_label: str = ''

pywry.models.GridRowClickEvent

Bases: BaseModel

AG Grid row click event data.

Attributes

row_data class-attribute instance-attribute

row_data: dict[str, Any] = Field(default_factory=dict)

row_id class-attribute instance-attribute

row_id: str = ''

row_index class-attribute instance-attribute

row_index: int = 0

window_label class-attribute instance-attribute

window_label: str = ''

Event Payloads

pywry.models.ResultPayload

Bases: BaseModel

Payload for pywry_result command.

Attributes

data instance-attribute

data: Any

window_label instance-attribute

window_label: str

pywry.models.GenericEventPayload

Bases: BaseModel

Payload for pywry_event command.

Attributes

event_type instance-attribute

event_type: str

data class-attribute instance-attribute

data: Any = None

window_label instance-attribute

window_label: str

Functions

validate_event_type_format classmethod

validate_event_type_format(v: str) -> str

Validate event type matches namespace:event-name pattern.

PARAMETER DESCRIPTION
v

The event type string to validate.

TYPE: str

RETURNS DESCRIPTION
str

The validated event type.

RAISES DESCRIPTION
ValueError

If the event type is invalid.

pywry.models.FilePathPayload

Bases: BaseModel

Payload for open_file command.

Attributes

path instance-attribute

path: str

pywry.models.WindowClosedPayload

Bases: BaseModel

Payload for window closed notification.

Attributes

window_label instance-attribute

window_label: str

pywry.models.AlertPayload

Bases: BaseModel

Enhanced alert event payload for pywry:alert system event.

Supports typed toast notifications with auto-dismiss, persistence, and confirmation dialogs with callbacks.

Attributes

message class-attribute instance-attribute

message: str = Field(..., description='Alert message text (required)')

type class-attribute instance-attribute

type: Literal['info', 'success', 'warning', 'error', 'confirm'] = Field(default='info', description='Alert type determining icon and behavior')

title class-attribute instance-attribute

title: str | None = Field(default=None, description='Optional alert title/header')

duration class-attribute instance-attribute

duration: int | None = Field(default=None, description='Auto-dismiss duration in ms (None uses type default)')

callback_event class-attribute instance-attribute

callback_event: str | None = Field(default=None, description="Event to emit on confirm/cancel (for type='confirm')")

position class-attribute instance-attribute

position: Literal['top-right', 'bottom-right', 'bottom-left', 'top-left'] = Field(default='top-right', description='Toast position on screen')