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:
| Type | Description |
|---|---|
bool
|
True if PYWRY_HEADLESS environment variable is set. |
pywry.runtime.start
¶
Start the pytauri subprocess.
Returns:
| Type | 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:
| Type | 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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
behavior
|
str
|
Either "hide" (keep window alive) or "close" (destroy window). |
required |
pywry.runtime.set_window_mode
¶
Set the window mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
str
|
Either "single", "multi", or "new". |
required |
pywry.runtime.set_tauri_plugins
¶
Set the Tauri plugins to initialise in the subprocess.
Must be called before start().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plugins
|
list[str]
|
Plugin names (e.g. |
required |
pywry.runtime.set_extra_capabilities
¶
Set additional Tauri capability permission strings.
Must be called before start().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
caps
|
list[str]
|
Permission strings (e.g. |
required |
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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
dict[str, Any]
|
Command to send. A request_id will be added automatically. |
required |
timeout
|
float
|
Maximum time to wait for response. |
5.0
|
Returns:
| Type | 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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
Window label (unique identifier). |
required |
title
|
str
|
Window title text. |
'PyWry'
|
width
|
int
|
Window width in pixels. |
800
|
height
|
int
|
Window height in pixels. |
600
|
**builder_opts
|
Any
|
Additional keyword arguments forwarded to
|
{}
|
pywry.runtime.set_content
¶
Set window content via IPC. Waits for content to be set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
Window label. |
required |
html
|
str
|
HTML content. |
required |
theme
|
str
|
Theme mode ('dark' or 'light') - MUST match window background. |
'dark'
|
pywry.runtime.check_window_open
¶
Check if a window exists and is open via IPC.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
Window label. |
required |
Returns:
| Type | 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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
Window label to refresh. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if content was re-sent successfully. |
pywry.runtime.refresh_all_windows
¶
Trigger a full page refresh for all windows.
Returns:
| Type | Description |
|---|---|
bool
|
True if command succeeded. |
CSS & Script Injection¶
pywry.runtime.inject_css
¶
Inject or update CSS in a window without page reload.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
Window label to inject into. |
required |
css
|
str
|
CSS content to inject. |
required |
asset_id
|
str
|
ID for the style element (for updates). |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if command succeeded. |
pywry.runtime.remove_css
¶
Remove a CSS style element from a window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
Window label. |
required |
asset_id
|
str
|
ID of the style element to remove. |
required |
Returns:
| Type | 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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
Window label. |
required |
script
|
str
|
JavaScript code to execute. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if command was sent and succeeded. |
Events¶
pywry.runtime.emit_event
¶
Emit a custom event to a window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
Window label (or "*" for all windows). |
required |
event
|
str
|
Event name. |
required |
payload
|
dict[str, Any] or None
|
Event payload data. |
None
|
Returns:
| Type | 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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
Window label. |
required |
property_name
|
str
|
Name of the property to get. |
required |
args
|
dict or None
|
Optional arguments for parameterised getters (e.g. |
None
|
timeout
|
float
|
Maximum time to wait for response. |
5.0
|
Returns:
| Type | Description |
|---|---|
Any
|
The property value. |
Raises:
| Type | 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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
Window label. |
required |
method
|
str
|
Name of the method to call. |
required |
args
|
dict[str, Any] or None
|
Method arguments. |
None
|
expect_response
|
bool
|
Whether to wait for a response. |
False
|
timeout
|
float
|
Maximum time to wait for response (if expect_response=True). |
5.0
|
Returns:
| Type | Description |
|---|---|
Any
|
The method result (if expect_response=True), otherwise None. |
Raises:
| Type | Description |
|---|---|
WindowError
|
If the method call fails. |
IPCTimeoutError
|
If the request times out (when expect_response=True). |