pywry.notebook¶
Notebook environment detection and widget creation helpers.
Environment Detection¶
pywry.notebook.NotebookEnvironment
¶
Bases: Enum
Detected notebook environment type.
pywry.notebook.detect_notebook_environment
cached
¶
detect_notebook_environment() -> NotebookEnvironment
Detect the current notebook environment.
This function is cached - environment detection only happens once.
| RETURNS | DESCRIPTION |
|---|---|
NotebookEnvironment
|
The detected environment. NONE means use native window, IPYTHON_TERMINAL means use native window (not inline). |
pywry.notebook.should_use_inline_rendering
¶
Check if inline notebook rendering should be used.
Returns True for: - Notebook environments (Jupyter, Colab, VS Code, etc.) - When PYWRY_SERVER__FORCE_NOTEBOOK=true (for headless web deployments)
Returns False for: - No IPython - IPython terminal - Unknown environments (unless force_notebook is set)
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if inline rendering should be used. |
pywry.notebook.is_anywidget_available
¶
Check if anywidget is installed and available.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if anywidget >= 0.9.0 is available. |
pywry.notebook.is_cloud_environment
¶
Check if running in a cloud-hosted notebook environment.
Cloud environments may use CDN assets instead of embedded.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True for Colab, Kaggle, Azure, Databricks. |
pywry.notebook.clear_environment_cache
¶
Clear the cached environment detection.
Useful for testing or when environment changes.
Widget Factories¶
pywry.notebook.create_plotly_widget
¶
create_plotly_widget(figure_json: str, widget_id: str, title: str = 'PyWry', theme: str = 'dark', width: str = '100%', height: int = 500, port: int | None = None, toolbars: list[Any] | None = None, modals: list[Any] | None = None, force_iframe: bool = False) -> Any
Create a Plotly widget using the best available backend.
Automatically selects: 1. PyWryPlotlyWidget (anywidget) if available - best performance 2. InlineWidget (FastAPI) as fallback - broader compatibility
| PARAMETER | DESCRIPTION |
|---|---|
figure_json
|
Plotly figure as JSON string (should include 'config' if needed).
TYPE:
|
widget_id
|
Unique widget identifier.
TYPE:
|
title
|
Widget title.
TYPE:
|
theme
|
'dark' or 'light'.
TYPE:
|
width
|
Widget width (CSS).
TYPE:
|
height
|
Widget height in pixels.
TYPE:
|
port
|
Server port (only for InlineWidget fallback).
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 modals. Each can be a Modal model or dict with: - component_id: unique identifier for the modal - title: modal header title - items: list of content items (HTML, form elements, etc.) - size: 'small', 'medium', 'large', or 'fullscreen'
TYPE:
|
force_iframe
|
If True, force use of InlineWidget instead of anywidget. Required for BROWSER mode which needs open_in_browser() method. Default: False.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BaseWidget
|
Widget instance implementing BaseWidget protocol. |
pywry.notebook.create_dataframe_widget
¶
create_dataframe_widget(config: Any, widget_id: str, title: str = 'PyWry', theme: str = 'dark', aggrid_theme: str = 'alpine', width: str = '100%', height: int = 500, header_html: str = '', toolbars: list[Any] | None = None, modals: list[Any] | None = None, port: int | None = None, force_iframe: bool = False) -> Any
Create a DataFrame/AG Grid widget using the best available backend.
Automatically selects: 1. PyWryAgGridWidget (anywidget) if available - best performance 2. InlineWidget (FastAPI) as fallback - broader compatibility
| PARAMETER | DESCRIPTION |
|---|---|
config
|
Unified grid configuration from grid.build_grid_config().
TYPE:
|
widget_id
|
Unique widget identifier.
TYPE:
|
title
|
Widget title.
TYPE:
|
theme
|
'dark' or 'light'.
TYPE:
|
aggrid_theme
|
AG Grid theme name.
TYPE:
|
width
|
Widget width (CSS).
TYPE:
|
height
|
Widget height in pixels.
TYPE:
|
header_html
|
Custom HTML for header section.
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 modals. Each can be a Modal model or dict with: - component_id: unique identifier for the modal - title: modal header title - items: list of content items (HTML, form elements, etc.) - size: 'small', 'medium', 'large', or 'fullscreen'
TYPE:
|
port
|
Server port (only for InlineWidget fallback).
TYPE:
|
force_iframe
|
If True, force use of InlineWidget instead of anywidget. Required for BROWSER mode which needs open_in_browser() method. Default: False.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BaseWidget
|
Widget instance implementing BaseWidget protocol. |