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 used when creating or reusing windows.

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 preference used by PyWry templates and windows.

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

enable_tvchart class-attribute instance-attribute

enable_tvchart: 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'

tvchart_theme class-attribute instance-attribute

tvchart_theme: Literal['dark', 'light'] = 'dark'

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 bundle rendered inside a PyWry window.

Attributes:

Name Type Description
html str

HTML markup to load into the window.

json_data dict[str, Any] | None

Optional JSON payload injected into the page bootstrap.

init_script str | None

JavaScript executed after the page is initialized.

css_files list[Path | str] | None

External CSS files to load alongside the HTML.

script_files list[Path | str] | None

External JavaScript files to load alongside the HTML.

inline_css str | None

Inline CSS appended to the generated document.

watch bool

Whether the content should participate in hot-reload file watching.

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.

Parameters:

Name Type Description Default
v Any

The value to convert.

required

Returns:

Type Description
list of Path or str, or None

Converted path list or None.


Event Models

Generic Event

pywry.models.GenericEvent

Bases: BaseModel

Generic event envelope for custom event handling.

Attributes:

Name Type Description
event_type str

Event name in namespace:event-name format.

data Any

Arbitrary event payload forwarded from the frontend.

window_label str

Window identifier that emitted the event.

timestamp datetime

Event creation time.

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.

Parameters:

Name Type Description Default
v str

The event type string to validate.

required

Returns:

Type Description
str

The validated event type.

Raises:

Type Description
ValueError

If the event type is invalid.

Result Event

pywry.models.ResultEvent

Bases: BaseModel

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

Attributes:

Name Type Description
data Any

Arbitrary result payload returned by the page.

window_label str

Window identifier that produced the 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 payload.

Attributes:

Name Type Description
point_indices list[int]

Indices of points included in the click interaction.

curve_number int

Trace index for the clicked point.

point_data dict[str, Any]

Raw Plotly point payload for the clicked datum.

window_label str

Window identifier that emitted the event.

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 payload.

Attributes:

Name Type Description
points list[dict[str, Any]]

Plotly point payloads included in the current selection.

range dict[str, Any] | None

Selected axis range when Plotly reports it.

window_label str

Window identifier that emitted the event.

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 payload.

Attributes:

Name Type Description
point_indices list[int]

Indices of points under the cursor.

curve_number int

Trace index for the hovered point.

point_data dict[str, Any]

Raw Plotly point payload for the hover target.

window_label str

Window identifier that emitted the event.

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 payload for zoom, pan, and layout changes.

Attributes:

Name Type Description
relayout_data dict[str, Any]

Raw Plotly relayout payload.

window_label str

Window identifier that emitted the event.

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.

Parameters:

Name Type Description Default
event_type str

The event type string to validate.

required

Returns:

Type Description
bool

True if valid, False otherwise.


Grid Events

pywry.models.GridSelectionEvent

Bases: BaseModel

AG Grid selection event payload.

Attributes:

Name Type Description
selected_rows list[dict[str, Any]]

Full row objects currently selected in the grid.

selected_row_ids list[str]

Stable identifiers for the selected rows.

window_label str

Window identifier that emitted the event.

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 event payload.

Attributes:

Name Type Description
row_id str

Stable identifier for the edited row.

row_index int

Visible row index in the current grid view.

column str

Column field associated with the event.

old_value Any

Previous cell value before the edit.

new_value Any

New cell value after the edit.

window_label str

Window identifier that emitted the event.

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 payload.

Attributes:

Name Type Description
row_data dict[str, Any]

Full row object for the clicked row.

row_id str

Stable identifier for the clicked row.

row_index int

Visible row index in the current grid view.

window_label str

Window identifier that emitted the event.

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 the pywry_result command.

Attributes:

Name Type Description
data Any

Result payload supplied by the frontend.

window_label str

Window identifier associated with the result.

Attributes

data instance-attribute

data: Any

window_label instance-attribute

window_label: str

pywry.models.GenericEventPayload

Bases: BaseModel

Payload for the pywry_event command.

Attributes:

Name Type Description
event_type str

Event name in namespace:event-name format.

data Any

Arbitrary event payload.

window_label str

Window identifier associated with the event.

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.

Parameters:

Name Type Description Default
v str

The event type string to validate.

required

Returns:

Type Description
str

The validated event type.

Raises:

Type Description
ValueError

If the event type is invalid.

pywry.models.FilePathPayload

Bases: BaseModel

Payload for the open_file command.

Attributes:

Name Type Description
path str

File path requested by the frontend.

Attributes

path instance-attribute

path: str

pywry.models.WindowClosedPayload

Bases: BaseModel

Payload for a window closed notification.

Attributes:

Name Type Description
window_label str

Identifier of the window that was closed.

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')