pywry.runtime¶
Low-level PyTauri subprocess management and IPC communication.
Process Lifecycle¶
pywry.runtime.is_headless
¶
Check if headless mode is enabled.
Headless mode creates windows that are fully functional but not visible, allowing full E2E testing in CI environments without a display.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if PYWRY_HEADLESS environment variable is set. |
pywry.runtime.start
¶
Start the pytauri subprocess.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if started successfully. |
pywry.runtime.wait_ready
¶
Wait for the subprocess to be ready.
pywry.runtime.get_portal
¶
Get the async portal if initialized.
| RETURNS | DESCRIPTION |
|---|---|
BlockingPortal or None
|
The portal, or None if not yet initialized. |
pywry.runtime.get_pywry_dir
¶
Get the pywry directory containing the subprocess entry point.
Configuration¶
pywry.runtime.set_on_window_close
¶
Set the global window close behavior.
| PARAMETER | DESCRIPTION |
|---|---|
behavior
|
Either "hide" (keep window alive) or "close" (destroy window).
TYPE:
|
pywry.runtime.set_window_mode
¶
Set the window mode.
| PARAMETER | DESCRIPTION |
|---|---|
mode
|
Either "single", "multi", or "new".
TYPE:
|
pywry.runtime.set_tauri_plugins
¶
Set the Tauri plugins to initialise in the subprocess.
Must be called before start().
| PARAMETER | DESCRIPTION |
|---|---|
plugins
|
Plugin names (e.g.
TYPE:
|
pywry.runtime.set_extra_capabilities
¶
Set additional Tauri capability permission strings.
Must be called before start().
| PARAMETER | DESCRIPTION |
|---|---|
caps
|
Permission strings (e.g.
TYPE:
|
Command IPC¶
pywry.runtime.send_command
¶
Send a command to the subprocess.
pywry.runtime.get_response
¶
Get a response from the subprocess.
pywry.runtime.send_command_with_response
¶
Send a command and wait for a correlated response.
Uses request_id for response correlation, allowing multiple concurrent blocking calls without response mixup.
| PARAMETER | DESCRIPTION |
|---|---|
cmd
|
Command to send. A request_id will be added automatically.
TYPE:
|
timeout
|
Maximum time to wait for response.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any] or None
|
The response, or None on timeout. |
Window Operations¶
pywry.runtime.create_window
¶
create_window(label: str, title: str = 'PyWry', width: int = 800, height: int = 600, **builder_opts: Any) -> bool
Create a window via IPC. Waits for window to be created.
| PARAMETER | DESCRIPTION |
|---|---|
label
|
Window label (unique identifier).
TYPE:
|
title
|
Window title text.
TYPE:
|
width
|
Window width in pixels.
TYPE:
|
height
|
Window height in pixels.
TYPE:
|
**builder_opts
|
Additional keyword arguments forwarded to
TYPE:
|
pywry.runtime.set_content
¶
Set window content via IPC. Waits for content to be set.
| PARAMETER | DESCRIPTION |
|---|---|
label
|
Window label.
TYPE:
|
html
|
HTML content.
TYPE:
|
theme
|
Theme mode ('dark' or 'light') - MUST match window background.
TYPE:
|
pywry.runtime.check_window_open
¶
Check if a window exists and is open via IPC.
| PARAMETER | DESCRIPTION |
|---|---|
label
|
Window label.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if window exists. |
pywry.runtime.hide_window
¶
Hide a window via IPC (keeps it alive, just not visible).
pywry.runtime.refresh_window
¶
Refresh a window by re-sending its stored content.
Re-sends the HTML content that was last set on this window. This is useful when you want to restore the window to its original state after dynamic DOM changes.
| PARAMETER | DESCRIPTION |
|---|---|
label
|
Window label to refresh.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if content was re-sent successfully. |
pywry.runtime.refresh_all_windows
¶
Trigger a full page refresh for all windows.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if command succeeded. |
CSS & Script Injection¶
pywry.runtime.inject_css
¶
Inject or update CSS in a window without page reload.
| PARAMETER | DESCRIPTION |
|---|---|
label
|
Window label to inject into.
TYPE:
|
css
|
CSS content to inject.
TYPE:
|
asset_id
|
ID for the style element (for updates).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if command succeeded. |
pywry.runtime.remove_css
¶
Remove a CSS style element from a window.
| PARAMETER | DESCRIPTION |
|---|---|
label
|
Window label.
TYPE:
|
asset_id
|
ID of the style element to remove.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if command succeeded. |
pywry.runtime.eval_js
¶
Evaluate arbitrary JavaScript in a window.
This runs JavaScript without replacing window content, useful for DOM queries and dynamic updates.
| PARAMETER | DESCRIPTION |
|---|---|
label
|
Window label.
TYPE:
|
script
|
JavaScript code to execute.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if command was sent and succeeded. |
Events¶
pywry.runtime.emit_event
¶
Emit a custom event to a window.
| PARAMETER | DESCRIPTION |
|---|---|
label
|
Window label (or "*" for all windows).
TYPE:
|
event
|
Event name.
TYPE:
|
payload
|
Event payload data.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if command succeeded. |
Window Property Access¶
pywry.runtime.window_get
¶
window_get(label: str, property_name: str, args: dict[str, Any] | None = None, timeout: float = 5.0) -> Any
Get a window property via IPC.
| PARAMETER | DESCRIPTION |
|---|---|
label
|
Window label.
TYPE:
|
property_name
|
Name of the property to get.
TYPE:
|
args
|
Optional arguments for parameterised getters (e.g.
TYPE:
|
timeout
|
Maximum time to wait for response.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Any
|
The property value. |
| RAISES | DESCRIPTION |
|---|---|
PropertyError
|
If the property cannot be retrieved. |
IPCTimeoutError
|
If the request times out. |
pywry.runtime.window_call
¶
window_call(label: str, method: str, args: dict[str, Any] | None = None, expect_response: bool = False, timeout: float = 5.0) -> Any
Call a window method via IPC.
| PARAMETER | DESCRIPTION |
|---|---|
label
|
Window label.
TYPE:
|
method
|
Name of the method to call.
TYPE:
|
args
|
Method arguments.
TYPE:
|
expect_response
|
Whether to wait for a response.
TYPE:
|
timeout
|
Maximum time to wait for response (if expect_response=True).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Any
|
The method result (if expect_response=True), otherwise None. |
| RAISES | DESCRIPTION |
|---|---|
WindowError
|
If the method call fails. |
IPCTimeoutError
|
If the request times out (when expect_response=True). |