Skip to content
Feeding a clanker? Grab this page as raw .md

LiveEdit API#

Bases: AnyWidget

Read-only function trace widget for inspecting one Python run.

LiveEdit.inspect_run(fn, *args, **kwargs) is the primary constructor for v1. The widget stores the original Python args privately and only syncs repr-based trace data to the browser, which keeps future editable code updates possible without serializing arbitrary Python objects.

Source code in wigglystuff/live_edit.py
def __init__(
    self,
    code: str,
    *,
    args: tuple[Any, ...] = (),
    kwargs: dict[str, Any] | None = None,
    editable: bool = False,
    function_name: str | None = None,
    globalns: dict[str, Any] | None = None,
    height: int | None = None,
    float_precision: int | None = None,
    visible_columns: list[str] | None = None,
    **widget_kwargs: Any,
) -> None:
    self._liveedit_args = tuple(args)
    self._liveedit_kwargs = {} if kwargs is None else dict(kwargs)
    self._liveedit_function_name = function_name
    self._liveedit_globalns = dict(globalns or {})
    trace, annotations, error = _trace_code(
        code,
        self._liveedit_args,
        self._liveedit_kwargs,
        function_name=function_name,
        globalns=self._liveedit_globalns,
        float_precision=float_precision,
    )
    if height is None:
        # Fit the source by default: ~21px per rendered line (13px font *
        # 1.55 line-height) plus top/bottom padding, floored at 520px so the
        # trace panel keeps a roomy scroll area. Lines never wrap (they sit
        # in an overflow-x panel), so a line-count estimate is accurate.
        n_lines = len(code.splitlines()) or 1
        height = max(520, n_lines * 21 + 40)
    super().__init__(
        code=code,
        trace=trace,
        annotations=annotations,
        error=error,
        editable=editable,
        height=height,
        float_precision=float_precision,
        visible_columns=list(visible_columns or []),
        **widget_kwargs,
    )

Inspect one run of a Python function with LiveEdit.

Source code in wigglystuff/live_edit.py
def inspect_run(fn: Any, *args: Any, **kwargs: Any) -> LiveEdit:
    """Inspect one run of a Python function with ``LiveEdit``."""

    return LiveEdit.inspect_run(fn, *args, **kwargs)

Synced traitlets#

Traitlet Type Notes
code str Source code for the traced function. This is the future live-edit source of truth.
trace dict Structured setup values, loop passes, nested child loops, and returned value.
annotations dict Static line/token metadata used by the browser for hover linking.
error dict or None Parse, runtime, or argument mismatch error payload; None when the run succeeds.
editable bool Reserved for the future browser editor mode. Defaults to False.
theme str "auto", "light", or "dark".
width int Widget width in pixels.
height int Maximum widget height in pixels.