pywry¶
Main PyWry application class and top-level functions.
PyWry Class¶
pywry.app.PyWry
¶
PyWry(mode: WindowMode = NEW_WINDOW, theme: ThemeMode = DARK, title: str = 'PyWry', width: int = 800, height: int = 600, settings: PyWrySettings | None = None, hot_reload: bool = False)
Bases: GridStateMixin, PlotlyStateMixin, ToolbarStateMixin
Main PyWry application for displaying content in native windows.
Supports three window modes: - NEW_WINDOW: Creates a new window for each show() call - SINGLE_WINDOW: Reuses one window, replaces content - MULTI_WINDOW: Multiple independent windows
Examples:
Initialize PyWry.
| PARAMETER | DESCRIPTION |
|---|---|
mode
|
Window mode to use.
TYPE:
|
theme
|
Default theme mode. |
title
|
Default window title.
TYPE:
|
width
|
Default window width.
TYPE:
|
height
|
Default window height.
TYPE:
|
settings
|
Configuration settings. If None, loads from env/files.
TYPE:
|
hot_reload
|
Enable hot reload for CSS/JS files.
TYPE:
|
Attributes¶
is_authenticated
property
¶
Check if the app has a successful authentication result.
default_config
property
¶
default_config: WindowConfig
Return the mutable default WindowConfig.
Callers may set builder-level fields directly::
app.default_config.resizable = False
app.default_config.transparent = True
Functions¶
login
¶
Authenticate via OAuth2.
In native mode, opens a dedicated auth window pointing at the provider's authorize URL. Blocks until authentication completes.
In deploy mode, returns the login URL for the frontend.
| PARAMETER | DESCRIPTION |
|---|---|
provider
|
Override the default provider from settings.
TYPE:
|
**kwargs
|
Additional keyword arguments passed to
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AuthFlowResult
|
The result of the authentication flow. |
| RAISES | DESCRIPTION |
|---|---|
AuthenticationError
|
If authentication fails. |
logout
¶
Log out and clear authentication state.
Clears stored tokens and cancels any background refresh.
set_initialization_script
¶
Set the default initialization_script for new windows.
This JavaScript is injected by WebviewWindowBuilder before
the page loads and persists across navigations. Individual
show() calls can override this via the initialization_script
keyword argument.
| PARAMETER | DESCRIPTION |
|---|---|
js
|
JavaScript source code to inject.
TYPE:
|
create_menu
¶
Create a native menu.
| PARAMETER | DESCRIPTION |
|---|---|
menu_id
|
Unique menu identifier.
TYPE:
|
items
|
Menu items.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MenuProxy
|
Proxy for the created menu. |
create_tray
¶
create_tray(tray_id: str, tooltip: str | None = None, title: str | None = None, icon: bytes | None = None, icon_width: int = 32, icon_height: int = 32, menu: Any = None, menu_on_left_click: bool = True) -> Any
Create a system tray icon.
| PARAMETER | DESCRIPTION |
|---|---|
tray_id
|
Unique tray icon identifier.
TYPE:
|
tooltip
|
Hover tooltip text.
TYPE:
|
title
|
Tray title (macOS menu bar text).
TYPE:
|
icon
|
RGBA icon bytes.
TYPE:
|
icon_width
|
Icon width.
TYPE:
|
icon_height
|
Icon height.
TYPE:
|
menu
|
Menu to attach.
TYPE:
|
menu_on_left_click
|
Whether left click opens the menu.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TrayProxy
|
Proxy for the created tray icon. |
remove_tray
¶
Remove a system tray icon.
Works for trays created via :meth:create_tray and those
created directly via TrayProxy.from_config() or
TrayProxy.create().
| PARAMETER | DESCRIPTION |
|---|---|
tray_id
|
The tray icon identifier.
TYPE:
|
show
¶
show(content: str | HtmlContent, title: str | None = None, width: int | str | None = None, height: int | None = None, callbacks: dict[str, CallbackFunc] | None = None, include_plotly: bool = False, include_aggrid: bool = False, aggrid_theme: Literal['quartz', 'alpine', 'balham', 'material'] = 'alpine', label: str | None = None, watch: bool | None = None, toolbars: list[dict[str, Any] | Toolbar] | None = None, modals: list[dict[str, Any] | Modal] | None = None, initialization_script: str | None = None, menu: MenuConfig | None = None) -> NativeWindowHandle | BaseWidget
Show content in a window.
In a notebook environment (Jupyter, IPython, Colab, etc.), this will automatically render content inline via IFrame instead of opening a native window.
| PARAMETER | DESCRIPTION |
|---|---|
content
|
HTML content or HtmlContent object.
TYPE:
|
title
|
Window title (overrides default).
TYPE:
|
width
|
Window width - int for pixels, str for CSS value (e.g., "60%", "500px").
TYPE:
|
height
|
Window height (overrides default).
TYPE:
|
callbacks
|
Event callbacks (event_type -> handler).
TYPE:
|
include_plotly
|
Include Plotly.js library.
TYPE:
|
include_aggrid
|
Include AG Grid library.
TYPE:
|
aggrid_theme
|
AG Grid theme name (default: 'alpine').
TYPE:
|
label
|
Window label (for MULTI_WINDOW mode updates).
TYPE:
|
watch
|
Enable hot reload for CSS/JS files (overrides HtmlContent.watch).
TYPE:
|
toolbars
|
List of toolbar configs. Each toolbar has 'position' and 'items' keys.
TYPE:
|
modals
|
List of modal configs. Each modal has 'title' and 'items' keys.
TYPE:
|
initialization_script
|
JavaScript to inject via
TYPE:
|
menu
|
Native menu bar configuration. Item handlers are automatically
registered before the window is created so menus work from
the moment the window appears. Pass a :class:
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NativeWindowHandle or PyWryWidget or InlineWidget
|
A NativeWindowHandle (native window) or widget (notebook). All implement the BaseWidget protocol. |
show_plotly
¶
show_plotly(figure: Any, title: str | None = None, width: int | None = None, height: int | None = None, callbacks: dict[str, CallbackFunc] | None = None, label: str | None = None, inline_css: str | None = None, on_click: Any = None, on_hover: Any = None, on_select: Any = None, toolbars: list[dict[str, Any] | Toolbar] | None = None, modals: list[dict[str, Any] | Modal] | None = None, config: Any = None) -> NativeWindowHandle | BaseWidget
Show a Plotly figure.
In a notebook environment, this will automatically render the figure inline via IFrame with full interactivity.
| PARAMETER | DESCRIPTION |
|---|---|
figure
|
Plotly figure object (must have to_html method) or dictionary spec.
TYPE:
|
title
|
Window title.
TYPE:
|
width
|
Window/IFrame width (overrides default).
TYPE:
|
height
|
Window/IFrame height (overrides default).
TYPE:
|
callbacks
|
Event callbacks.
TYPE:
|
label
|
Window label (for MULTI_WINDOW mode).
TYPE:
|
inline_css
|
Custom CSS to inject (e.g., override window background).
TYPE:
|
on_click
|
Click callback for notebook mode.
TYPE:
|
on_hover
|
Hover callback for notebook mode.
TYPE:
|
on_select
|
Selection callback for notebook mode.
TYPE:
|
toolbars
|
List of toolbar configs. Each toolbar has 'position' and 'items' keys.
TYPE:
|
modals
|
List of modal configs. Each modal has 'title' and 'items' keys.
TYPE:
|
config
|
Plotly.js configuration (modebar, responsive, etc.).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NativeWindowHandle or BaseWidget
|
A NativeWindowHandle (native window) or widget (notebook). All implement the BaseWidget protocol. |
show_dataframe
¶
show_dataframe(data: Any, title: str | None = None, width: int | None = None, height: int | None = None, callbacks: dict[str, CallbackFunc] | None = None, label: str | None = None, column_defs: list[dict[str, Any]] | None = None, aggrid_theme: Literal['quartz', 'alpine', 'balham', 'material'] = 'alpine', grid_options: dict[str, Any] | None = None, toolbars: list[dict[str, Any] | Toolbar] | None = None, modals: list[dict[str, Any] | Modal] | None = None, inline_css: str | None = None, on_cell_click: Any = None, on_row_selected: Any = None, server_side: bool = False) -> NativeWindowHandle | BaseWidget
Show a DataFrame in an AG Grid table.
In a notebook environment, this will automatically render the table inline via IFrame with full interactivity.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
DataFrame or list of dicts to display.
TYPE:
|
title
|
Window title.
TYPE:
|
width
|
Window/IFrame width (overrides default).
TYPE:
|
height
|
Window/IFrame height (overrides default).
TYPE:
|
callbacks
|
Event callbacks.
TYPE:
|
label
|
Window label (for MULTI_WINDOW mode).
TYPE:
|
column_defs
|
AG Grid column definitions.
TYPE:
|
aggrid_theme
|
AG Grid theme.
TYPE:
|
grid_options
|
Custom AG Grid options to merge with defaults.
TYPE:
|
toolbars
|
List of toolbar configs. Each toolbar has 'position' and 'items' keys.
TYPE:
|
inline_css
|
Custom CSS to inject (e.g., override window background).
TYPE:
|
on_cell_click
|
Cell click callback for notebook mode.
TYPE:
|
on_row_selected
|
Row selection callback for notebook mode.
TYPE:
|
server_side
|
Enable server-side mode where data stays in Python memory. Useful for very large datasets (>100K rows) where you want to filter/sort the full data. Data is fetched via IPC on demand. Default is False.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NativeWindowHandle or BaseWidget
|
A NativeWindowHandle (native window) or widget (notebook). All implement the BaseWidget protocol. |
emit
¶
Emit an event to the JavaScript side.
| PARAMETER | DESCRIPTION |
|---|---|
event_type
|
Event name.
TYPE:
|
data
|
Event data.
TYPE:
|
label
|
Window label. If None, targets all active windows.
TYPE:
|
alert
¶
alert(message: str, alert_type: Literal['info', 'success', 'warning', 'error', 'confirm'] = 'info', title: str | None = None, duration: int | None = None, callback_event: str | None = None, position: Literal['top-right', 'bottom-right', 'bottom-left', 'top-left'] = 'top-right', label: str | None = None) -> None
Show a toast notification.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
The message to display.
TYPE:
|
alert_type
|
Alert type: 'info', 'success', 'warning', 'error', or 'confirm'.
TYPE:
|
title
|
Optional title for the toast.
TYPE:
|
duration
|
Auto-dismiss duration in ms. Defaults based on type.
TYPE:
|
callback_event
|
Event name to emit when confirm dialog is answered.
TYPE:
|
position
|
Toast position: 'top-right', 'top-left', 'bottom-right', 'bottom-left'.
TYPE:
|
label
|
Window label. If None, targets all active windows.
TYPE:
|
on
¶
on(event_type: str, handler: CallbackFunc, label: str | None = None, widget_id: str | None = None) -> bool
Register an event handler.
| PARAMETER | DESCRIPTION |
|---|---|
event_type
|
Event type (namespace:event-name or * for wildcard).
TYPE:
|
handler
|
Callback function.
TYPE:
|
label
|
Window label. If None, registers on all active windows.
TYPE:
|
widget_id
|
Widget ID to target specific component events.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if registered successfully. |
command
¶
Register a custom IPC command callable from JavaScript.
The decorated function becomes available to the front-end via
window.__TAURI__.pytauri.pyInvoke('name', body).
Must be called before show() / start() so the command
is registered in the subprocess before the Tauri app builder runs.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Command name exposed to JS. Defaults to the function's
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
callable
|
Decorator that registers the handler. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the handler is not callable. |
RuntimeError
|
If the app is in a non-native mode (BROWSER, NOTEBOOK) where
|
Examples:
on_grid
¶
on_grid(event_type: str, handler: CallbackFunc, label: str | None = None, grid_id: str = '*') -> bool
Register an event handler for grid events.
Convenience method that filters events to only AG Grid widgets.
| PARAMETER | DESCRIPTION |
|---|---|
event_type
|
Event type (e.g., "grid:cell-click", "cell_click").
TYPE:
|
handler
|
Callback function.
TYPE:
|
label
|
Window label. If None, registers on all active windows.
TYPE:
|
grid_id
|
Grid ID to target specific grid instance (default "*" for all).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if registered successfully. |
on_chart
¶
on_chart(event_type: str, handler: CallbackFunc, label: str | None = None, chart_id: str = '*') -> bool
Register an event handler for chart (Plotly) events.
Convenience method that filters events to only Plotly chart widgets.
| PARAMETER | DESCRIPTION |
|---|---|
event_type
|
Event type (e.g., "plotly:click", "plotly:hover").
TYPE:
|
handler
|
Callback function.
TYPE:
|
label
|
Window label. If None, registers on all active windows.
TYPE:
|
chart_id
|
Chart ID to target specific chart instance (default "*" for all).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if registered successfully. |
on_toolbar
¶
on_toolbar(event_type: str, handler: CallbackFunc, label: str | None = None, toolbar_id: str = '*') -> bool
Register an event handler for toolbar events.
Convenience method that filters events to only toolbar widgets.
| PARAMETER | DESCRIPTION |
|---|---|
event_type
|
Event type (e.g., "toolbar:change", custom button events).
TYPE:
|
handler
|
Callback function.
TYPE:
|
label
|
Window label. If None, registers on all active windows.
TYPE:
|
toolbar_id
|
Toolbar ID to target specific toolbar (default "*" for all).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if registered successfully. |
on_html
¶
on_html(event_type: str, handler: CallbackFunc, label: str | None = None, element_id: str = '*') -> bool
Register an event handler for HTML element events.
Convenience method that filters events to HTML content.
| PARAMETER | DESCRIPTION |
|---|---|
event_type
|
Event type (e.g., custom events from HTML elements).
TYPE:
|
handler
|
Callback function.
TYPE:
|
label
|
Window label. If None, registers on all active windows.
TYPE:
|
element_id
|
HTML element ID to target specific element (default "*" for all).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if registered successfully. |
on_window
¶
on_window(event_type: str, handler: CallbackFunc, label: str | None = None) -> bool
Register an event handler for window-level events.
Convenience method that filters events to window lifecycle events.
| PARAMETER | DESCRIPTION |
|---|---|
event_type
|
Event type (e.g., "window:close", "window:resize").
TYPE:
|
handler
|
Callback function.
TYPE:
|
label
|
Window label. If None, registers on all active windows.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if registered successfully. |
send_event
¶
Send an event to window(s).
| PARAMETER | DESCRIPTION |
|---|---|
event_type
|
Event type (namespace:event-name).
TYPE:
|
data
|
Event data.
TYPE:
|
label
|
Specific window label (None = all windows).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if event was sent to at least one window. |
update_content
¶
Update window content.
| PARAMETER | DESCRIPTION |
|---|---|
html
|
New HTML content.
TYPE:
|
label
|
Window label (required for NEW_WINDOW/MULTI_WINDOW).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if updated successfully. |
eval_js
¶
Evaluate JavaScript in a window without replacing content.
This is useful for DOM queries and dynamic updates that should not replace the window content.
| PARAMETER | DESCRIPTION |
|---|---|
script
|
JavaScript code to execute.
TYPE:
|
label
|
Window label (None = main window in SINGLE_WINDOW mode).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if command was sent. |
show_window
¶
Show a hidden window.
| PARAMETER | DESCRIPTION |
|---|---|
label
|
Window label to show.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if window was shown. |
hide_window
¶
Hide a window (keeps it alive, just not visible).
| PARAMETER | DESCRIPTION |
|---|---|
label
|
Window label to hide.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if window was hidden. |
close
¶
Close window(s).
| PARAMETER | DESCRIPTION |
|---|---|
label
|
Window label to close (None = close all).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if any window was closed. |
get_labels
¶
Get all active window labels.
| RETURNS | DESCRIPTION |
|---|---|
list of str
|
List of window labels. |
is_open
¶
Check if window(s) are open.
| PARAMETER | DESCRIPTION |
|---|---|
label
|
Specific window to check (None = any window).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if window(s) are open. |
refresh
¶
Refresh window content.
Triggers a full page refresh while preserving scroll position.
| PARAMETER | DESCRIPTION |
|---|---|
label
|
Specific window to refresh (None = all windows).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if at least one window was refreshed. |
refresh_css
¶
Hot-reload CSS files for window(s).
Re-injects CSS files without page refresh.
| PARAMETER | DESCRIPTION |
|---|---|
label
|
Specific window to refresh CSS (None = all windows).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if at least one window's CSS was refreshed. |
get_lifecycle
¶
get_lifecycle() -> WindowLifecycle
Get the window lifecycle manager.
| RETURNS | DESCRIPTION |
|---|---|
WindowLifecycle
|
WindowLifecycle instance. |
block
¶
Block until window(s) are closed or KeyboardInterrupt.
This is the recommended way to keep your script running while windows are open. Works for all modes:
- Native modes (NEW_WINDOW, SINGLE_WINDOW, MULTI_WINDOW): Waits for windows to close via the Tauri event loop.
- BROWSER mode: Delegates to pywry.inline.block() to wait for browser tabs to disconnect.
| PARAMETER | DESCRIPTION |
|---|---|
label
|
Specific window label to wait for. If None, waits for all windows.
TYPE:
|
Examples:
request_toolbar_state
¶
Request values of all toolbar inputs.
set_toolbar_value
¶
set_toolbar_value(component_id: str, value: Any = _UNSET, toolbar_id: str | None = None, **attrs: Any) -> None
Set a toolbar component's value and/or attributes.
| PARAMETER | DESCRIPTION |
|---|---|
component_id
|
The component_id of the toolbar item to update.
TYPE:
|
value
|
The new value for the component.
TYPE:
|
toolbar_id
|
The toolbar ID (if applicable).
TYPE:
|
**attrs
|
Additional attributes to set on the component: - label/text: Update text content - disabled: Enable/disable the component - variant: Button variant (primary, secondary, danger, etc.) - tooltip/description: Update tooltip text - options: Update dropdown/select options - style: Inline styles (str or dict) - className/class: Add/remove CSS classes - placeholder, min, max, step: Input constraints
TYPE:
|
set_toolbar_values
¶
Set multiple toolbar input values at once.
update_figure
¶
update_figure(figure: Any, chart_id: str | None = None, animate: bool = False, config: dict[str, Any] | None = None) -> None
Update the entire chart figure (data and layout).
update_layout
¶
Update specific layout properties (Plotly.relayout).
update_traces
¶
update_traces(patch: dict[str, Any], indices: list[int] | None = None, chart_id: str | None = None) -> None
Update specific trace properties (Plotly.restyle).
request_plotly_state
¶
Request current chart state (viewport, zoom, selections).
set_zoom
¶
set_zoom(xaxis_range: tuple[Any, Any] | None = None, yaxis_range: tuple[Any, Any] | None = None, chart_id: str | None = None) -> None
Set specific zoom ranges for axes.
set_trace_visibility
¶
set_trace_visibility(visible: bool | str | list[bool | str], indices: list[int] | None = None, chart_id: str | None = None) -> None
Set visibility for specific traces.
request_grid_state
¶
Request the current state of the grid (sort, filter, columns, etc.).
The frontend will respond with a 'grid:state-response' event.
| PARAMETER | DESCRIPTION |
|---|---|
context
|
Context data to include in the response. This is echoed back unchanged in the state_response event, useful for tracking which request triggered the response (e.g., view switching).
TYPE:
|
grid_id
|
The ID of the grid to query.
TYPE:
|
restore_state
¶
Restore the grid state from a previous state object.
reset_state
¶
Reset the grid state to default values.
| PARAMETER | DESCRIPTION |
|---|---|
grid_id
|
The ID of the grid to reset.
TYPE:
|
hard
|
If True, completely destroys and recreates the grid instance. If False (default), only resets state columns/filters/sort.
TYPE:
|
update_cell
¶
Update a single cell value.
update_data
¶
Update grid data rows.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
List of row data dictionaries.
TYPE:
|
grid_id
|
The ID of the grid.
TYPE:
|
strategy
|
Update strategy ('set', 'append', 'update'). 'set' replaces all data.
TYPE:
|
update_columns
¶
Update column definitions.
update_grid
¶
update_grid(data: list[dict[str, Any]] | Any | None = None, columns: list[dict[str, Any]] | None = None, restore_state: dict[str, Any] | None = None, grid_id: str | None = None) -> None
Update the grid with new data, columns, and/or restore saved state.
This is the primary method for switching views or making bulk updates. It combines data, column, and state updates into a single operation to minimize UI flicker.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
New row data. If a DataFrame, it will be converted to records.
TYPE:
|
columns
|
New column definitions.
TYPE:
|
restore_state
|
Previously saved grid state to restore (from grid:state-response). Contains columnState, filterModel, sortModel.
TYPE:
|
grid_id
|
The ID of the grid to update.
TYPE:
|
Inline Rendering Functions¶
These functions provide quick one-liner display for Plotly figures and DataFrames.
pywry.inline.show_plotly
¶
show_plotly(figure: Figure, callbacks: dict[str, Callable[..., Any]] | None = None, title: str = 'PyWry', width: str = '100%', height: int = 500, theme: ThemeLiteral | None = None, port: int | None = None, config: dict[str, Any] | PlotlyConfig | None = None, toolbars: list[dict[str, Any] | Toolbar] | None = None, modals: list[dict[str, Any] | Modal] | None = None, open_browser: bool = False) -> BaseWidget
Show a Plotly figure inline in a notebook with automatic event handling.
This function automatically wires up Plotly events (click, hover, selected) and uses the best available widget backend (anywidget or InlineWidget).
| PARAMETER | DESCRIPTION |
|---|---|
figure
|
Plotly figure to display.
TYPE:
|
callbacks
|
Event callbacks. Keys are event names (e.g., 'plotly_click', 'plotly_hover', 'plotly_selected'), values are handler functions receiving (data, event_type, label). The function signature should be: callback(data: dict, event_type: str, label: str).
TYPE:
|
title
|
Page title.
TYPE:
|
width
|
Widget width (CSS format).
TYPE:
|
height
|
Widget height in pixels.
TYPE:
|
theme
|
Color theme.
TYPE:
|
port
|
Server port (only used if InlineWidget fallback is needed).
TYPE:
|
config
|
Plotly config dictionary (e.g., {'modeBarButtonsToAdd': [...]}).
TYPE:
|
toolbars
|
List of toolbar configurations, each with: - position: "top", "bottom", "left", "right", "inside" - items: list of item configs
TYPE:
|
modals
|
List of modal configurations.
TYPE:
|
open_browser
|
If True, open in system browser instead of displaying IFrame in notebook. Used by BROWSER mode. Default: False.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BaseWidget
|
Widget implementing BaseWidget protocol (PyWryPlotlyWidget or InlineWidget). |
Examples:
>>> import plotly.graph_objects as go
>>> fig = go.Figure(data=go.Scatter(x=[1, 2, 3], y=[4, 5, 6]))
>>> widget = show_plotly(
... fig,
... callbacks={
... "plotly_click": lambda d, t, l: print(f"Clicked: {d['points']}"),
... "plotly_hover": lambda d, t, l: print(f"Hover: {d['points']}"),
... },
... )
pywry.inline.show_dataframe
¶
show_dataframe(df: Any, callbacks: dict[str, Callable[..., Any]] | None = None, title: str = 'PyWry', width: str = '100%', height: int = 500, theme: ThemeLiteral | None = None, aggrid_theme: Literal['quartz', 'alpine', 'balham', 'material'] = 'alpine', header_html: str = '', grid_options: dict[str, Any] | None = None, toolbars: list[Any] | None = None, modals: list[Any] | None = None, port: int | None = None, widget_id: str | None = None, column_defs: list[Any] | None = None, row_selection: Any | bool = False, enable_cell_span: bool | None = None, pagination: bool | None = None, pagination_page_size: int = 100, open_browser: bool = False) -> BaseWidget
Show a DataFrame (or dict/list) inline in a notebook with automatic event handling.
This function automatically wires up AG Grid events (grid:cell-click, grid:row-selected) and uses the best available widget backend (anywidget or InlineWidget).
| PARAMETER | DESCRIPTION |
|---|---|
df
|
Data to display. Can be pandas DataFrame, list of row dicts, or dict of columns.
TYPE:
|
callbacks
|
Event callbacks.
TYPE:
|
title
|
Page title.
TYPE:
|
width
|
Widget width (CSS format).
TYPE:
|
height
|
Widget height in pixels.
TYPE:
|
theme
|
Color theme.
TYPE:
|
aggrid_theme
|
AG Grid theme.
TYPE:
|
header_html
|
Custom HTML to display above the grid (e.g., buttons).
TYPE:
|
grid_options
|
Custom AG Grid options.
TYPE:
|
toolbars
|
List of toolbars. Each can be a Toolbar model or dict with: - position: "top", "bottom", "left", "right", "inside" - items: list of item configs (Button, Select, etc.)
TYPE:
|
modals
|
List of modal configurations.
TYPE:
|
port
|
Server port (only used if InlineWidget fallback is needed).
TYPE:
|
widget_id
|
Unique ID for the widget. If None, a random UUID is generated.
TYPE:
|
column_defs
|
Custom column definitions. Can be dicts or ColDef objects.
TYPE:
|
row_selection
|
Row selection config. True = multiRow with checkboxes.
TYPE:
|
enable_cell_span
|
Enable row spanning for index columns. None = auto-detect from MultiIndex.
TYPE:
|
pagination
|
Enable pagination. None = auto-enable for datasets > 10 rows.
TYPE:
|
pagination_page_size
|
Rows per page when pagination is enabled.
TYPE:
|
open_browser
|
If True, open in system browser instead of displaying IFrame in notebook. Used by BROWSER mode. Default: False.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BaseWidget
|
Widget implementing BaseWidget protocol. |
pywry.inline.block
¶
Block until all widgets disconnect or KeyboardInterrupt.
Use this in scripts using BROWSER mode to keep the server alive until all browser tabs are closed.
Examples:
Menu & Tray¶
App-level convenience methods for native menus and tray icons. See the Native Menus and System Tray guides.
The following methods are on the PyWry class (documented above via autodoc):
create_menu(menu_id, items)→MenuProxycreate_tray(tray_id, ...)→TrayProxyremove_tray(tray_id)— remove a tracked tray iconset_initialization_script(js)— set default init script for new windowsdefault_configproperty — mutableWindowConfigwith builder defaults
Window Lifecycle¶
pywry.window_manager.get_lifecycle
¶
get_lifecycle() -> WindowLifecycle
Get the global window lifecycle manager.
| RETURNS | DESCRIPTION |
|---|---|
WindowLifecycle
|
The window lifecycle singleton. |