Skip to content

How to render a viewer in a Jupyter notebook

How-to. Target: a live globe inside a notebook cell, with buttons to control the clock and receive click events.

The widget runs CesiumJS in the notebook from the CDN — notebooks have no local server — and mirrors the runtime control API of show(). There is no HTTP server to start or stop.

Prefer a plain browser window?

The same control API works over show()'s local server — see How to control a live viewer.

1. Install the widget extra

pip install "cesiumkit[widget]"

2. Build a viewer and turn it into a widget

import cesiumkit

viewer = cesiumkit.Viewer()
viewer.add_entity(
    cesiumkit.Entity(
        name="NYC",
        position=cesiumkit.Cartesian3.from_degrees(-74.006, 40.7128, 400),
    )
)

widget = viewer.to_widget()
widget  # display this cell to render the globe

3. Drive the clock and read it back

widget.set_time("2026-07-14T18:00:00Z")
widget.set_multiplier(60)  # seconds of simulation per real second
widget.animate(True)

current = widget.get_current_time()  # reads the live clock from the browser

4. React to clicks and save screenshots

widget.on_click(lambda entity_id: print("clicked", entity_id))
widget.screenshot("globe.png")

API reference

  • widget

    Jupyter widget integration (anywidget).

    CesiumKitWidget renders a Viewer inside a notebook with a live bidirectional command channel: Python sends commands (clock, selection, screenshot) over the comm, the widget's JavaScript evaluates them against window.viewer and sends results/click events back.

    Requires the [widget] extra (anywidget). Import lazily:

    from cesiumkit.widget import CesiumKitWidget
    widget = viewer.to_widget()
    

    Classes:

    Name Description
    CesiumKitWidget

    A Jupyter widget rendering a cesiumkit Viewer with live control.

    CesiumKitWidget

    CesiumKitWidget(
        viewer: Any, *, height: str = "600px", cesium_version: str | None = None
    )
    

    Bases: AnyWidget

    A Jupyter widget rendering a cesiumkit Viewer with live control.

    Methods:

    Name Description
    set_time

    Set the clock to an ISO-8601 time.

    set_multiplier

    Set the clock multiplier (simulation speed).

    animate

    Start or stop the clock animation.

    get_current_time

    Return the current clock time as ISO-8601.

    on_click

    Register a callback invoked with the clicked entity id (or None).

    screenshot

    Save a PNG screenshot of the live canvas.

    close

    Close the widget and fail any commands still awaiting a browser reply.

    set_time

    set_time(iso: str) -> None
    

    Set the clock to an ISO-8601 time.

    set_multiplier

    set_multiplier(multiplier: float) -> None
    

    Set the clock multiplier (simulation speed).

    animate

    animate(on: bool) -> None
    

    Start or stop the clock animation.

    get_current_time

    get_current_time(timeout: float = 10.0) -> str
    

    Return the current clock time as ISO-8601.

    on_click

    on_click(callback: Callable[[Any], None]) -> None
    

    Register a callback invoked with the clicked entity id (or None).

    screenshot

    screenshot(path: str) -> None
    

    Save a PNG screenshot of the live canvas.

    close

    close() -> None
    

    Close the widget and fail any commands still awaiting a browser reply.