RemoteFrameBuffer class

class jupyter_rfb.RemoteFrameBuffer(**kwargs: Any)

A widget implementing a remote frame buffer.

This is a subclass of ipywidgets.DOMWidget. To use this class, it should be subclassed, and its .get_frame() and .handle_event() methods should be implemented.

This widget has the following traits:

  • css_width: the logical width of the frame as a CSS string. Default ‘500px’.

  • css_height: the logical height of the frame as a CSS string. Default ‘300px’.

  • resizable: whether the frame can be manually resized. Default True.

  • quality: the quality of the JPEG encoding during interaction/animation as a number between 1 and 100. Default 80. Set to lower numbers for more performance on slow connections. Note that each interaction is ended with a lossless image (PNG). If set to 100 or if JPEG encoding isn’t possible (missing pillow or simplejpeg dependencies), then lossless PNGs will always be sent.

  • max_buffered_frames: the number of frames that is allowed to be “in-flight”, i.e. sent, but not yet confirmed by the client. Default 2. Higher values may result in a higher FPS at the cost of introducing lag.

print(*args, **kwargs)

Print to the widget’s output area (for debugging purposes).

In Jupyter, print calls that occur in a callback or an asyncio task may (depending on your version of the notebook/lab) not be shown. Inside .get_frame() and .handle_event() you can use this method instead. The signature of this method is fully compatible with the builtin print function (except for the file argument).

close(*args, **kwargs)

Close all views of the widget and emit a close event.

snapshot(pixel_ratio=None, _initial=False)

Create a snapshot of the current state of the widget.

Returns an IPython DisplayObject that can simply be used as a cell output. The display object has a data attribute that holds the image array data (typically a numpy array).

The pixel_ratio can optionally be set to influence the resolution. By default the widgets’ “native” pixel-ratio is used.


Schedule a new draw. This method itself returns immediately.

This method is automatically called on each resize event. During a draw, the .get_frame() method is called, and the resulting array is sent to the client. See the docs for details about scheduling.


Restart measuring statistics from the next sent frame.


Get the current stats since the last time .reset_stats() was called.

Stats is a dict with the following fields:

  • sent_frames: the number of frames sent.

  • confirmed_frames: number of frames confirmed by the client.

  • roundtrip: avererage time for processing a frame, including receiver confirmation.

  • delivery: average time for processing a frame until it’s received by the client. This measure assumes that the clock of the server and client are precisely synced.

  • img_encoding: the average time spent on encoding the array into an image.

  • b64_encoding: the average time spent on base64 encoding the data.

  • fps: the average FPS, measured from the first frame sent since .reset_stats() was called, until the last confirmed frame.


Return image array for the next frame.

Subclasses should overload this method. It is automatically called during a draw. The returned numpy array must be NxM (grayscale), NxMx3 (RGB) or NxMx4 (RGBA). May also return None to cancel the draw.


Handle an incoming event.

Subclasses should overload this method. Events include widget resize, mouse/touch interaction, key events, and more. An event is a dict with at least the key event_type. See for details.