Python Cells

Write and execute Python code with rich output rendering.

Creating Python Cells

In .py files, a Python cell starts with a # %% comment marker. Everything between two markers is one cell:

# %%
import polars as pl
df = pl.read_csv("data.csv")

# %%
df.head()

In .ipynb files, cells follow the standard Jupyter format. Use the + button or toolbar to add new cells.

Running Cells

  • Cmd+Enter runs the current cell
  • Shift+Enter runs the current cell and advances to the next
  • The Run All button executes every cell top to bottom

Output appears directly below the cell. If the last expression in a cell has a value, pynb displays it automatically (no print() needed).

Rich Output

pynb renders a variety of output types inline:

  • Charts: Vega, Vega-Lite, Plotly, and Matplotlib figures render as interactive visualizations
  • DataFrames: Polars and Pandas DataFrames display in a scrollable, sortable data table
  • Images: PIL/Pillow images and raw image data render inline
  • HTML: Rich HTML output from libraries like IPython.display.HTML
  • LaTeX: Mathematical expressions rendered via KaTeX
  • Maps: Leaflet-based maps from libraries like Folium

Variable Inspector

The variable inspector panel shows all variables in the current kernel session. It displays each variable's name, type, and a preview of its value. Toggle it from the toolbar to keep track of your workspace state.

Code Completion and Inspection

pynb provides code completion as you type. Press Tab to accept a suggestion, or continue typing to narrow the list. Hover over a symbol to see its type signature and docstring.

Widgets

pynb supports interactive widgets via anywidget and ipywidgets. Widgets render inline in the notebook, and their state syncs between Python and the frontend. This works for sliders, dropdowns, text inputs, and custom anywidget components.

Reactive Execution

pynb includes optional reactive execution powered by ipyflow. When enabled, changing a variable in one cell automatically re-runs all downstream cells that depend on it. This keeps your notebook state consistent without manually tracking which cells to re-execute.

Reactive mode is opt-in and can be toggled from the notebook toolbar.