Skip to content

pywry.commands

Tauri IPC command handlers and event dispatch.


Command Dispatch

pywry.commands.dispatch_command

dispatch_command(command: str, payload: dict[str, Any]) -> dict[str, Any]

Dispatch a command to its handler.

Parameters:

Name Type Description Default
command str

The command name.

required
payload dict of str to Any

The command payload.

required

Returns:

Type Description
dict of str to Any

Response dict from the handler.

pywry.commands.register_commands

register_commands(commands: Commands) -> None

Register IPC commands with pytauri.

Parameters:

Name Type Description Default
commands Commands

pytauri Commands instance.

required

pywry.commands.serialize_response

serialize_response(response: dict[str, Any]) -> str

Serialize a response to JSON string.

Parameters:

Name Type Description Default
response dict of str to Any

The response dict.

required

Returns:

Type Description
str

JSON string.


Event Handlers

pywry.commands.handle_window_close

handle_window_close(label: str) -> dict[str, Any]

Handle window close event - aggressive cleanup.

Parameters:

Name Type Description Default
label str

The window label.

required

Returns:

Type Description
dict of str to Any

Response dict.

pywry.commands.handle_pywry_result

handle_pywry_result(label: str, data: dict[str, Any]) -> dict[str, Any]

Handle result from JavaScript execution.

Parameters:

Name Type Description Default
label str

The window label.

required
data dict of str to Any

The result data.

required

Returns:

Type Description
dict of str to Any

Response dict indicating success/failure.

pywry.commands.handle_pywry_event

handle_pywry_event(label: str, event_data: dict[str, Any]) -> dict[str, Any]

Handle generic events from JavaScript.

Parameters:

Name Type Description Default
label str

The window label.

required
event_data dict of str to Any

The event data including type and payload.

required

Returns:

Type Description
dict of str to Any

Response dict indicating success/failure.

pywry.commands.handle_plotly_event

handle_plotly_event(label: str, event_data: dict[str, Any]) -> dict[str, Any]

Handle Plotly-specific events.

Parameters:

Name Type Description Default
label str

The window label.

required
event_data dict of str to Any

The event data with plotly_event and data fields.

required

Returns:

Type Description
dict of str to Any

Response dict indicating success/failure.

pywry.commands.handle_aggrid_event

handle_aggrid_event(label: str, event_data: dict[str, Any]) -> dict[str, Any]

Handle AG Grid-specific events.

Parameters:

Name Type Description Default
label str

The window label.

required
event_data dict of str to Any

The event data with grid_event and data fields.

required

Returns:

Type Description
dict of str to Any

Response dict indicating success/failure.

pywry.commands.handle_open_file

handle_open_file(path: str) -> dict[str, Any]

Open a file with the system's default application.

Parameters:

Name Type Description Default
path str

The file path to open.

required

Returns:

Type Description
dict of str to Any

Response dict indicating success/failure.

pywry.commands.handle_open_url

handle_open_url(url: str) -> dict[str, Any]

Open a URL in the system's default browser.

Parameters:

Name Type Description Default
url str

The URL to open.

required

Returns:

Type Description
dict of str to Any

Response dict indicating success/failure.


Payload Models

pywry.commands.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.

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.