JupyterLabSession#

class rubin.nublado.client.JupyterLabSession(*, username, session_id, socket, logger)#

Bases: object

Open WebSocket session to a JupyterLab.

Objects of this type should be created via the JupyterLabSessionManager context manager.

Parameters:
  • username (str) – User the session is for.

  • session_id (str) – Session ID of the JupyterLab session.

  • socket (ClientConnection) – Open WebSocket connection.

  • logger (BoundLogger) – Logger to use.

Methods Summary

run_python(code[, context])

Run a block of Python code in a Jupyter lab kernel.

Methods Documentation

async run_python(code, context=None)#

Run a block of Python code in a Jupyter lab kernel.

Parameters:

code (str) – Code to run.

Returns:

Output from the kernel.

Return type:

str

Raises:

Notes

The output returned is only what the cell prints (its standard output). When run inside Jupyter, the cell will display the result of the last Python code line run. This parser ignores that information (the execute_result message).

display_data is also ignored. This is the message type sent for other types of output, such as when you ask Bokeh to show a figure. It’s a bunch of Javascript that will be interpreted by your browser.

See the JupyterLab wire protocol for the full protocol. What we use is half a layer above that. We care what some messages on the various channels are, but not about the low-level implementation details of how those channels are established over ZMQ, for instance.

Parameters:

context (CodeContext | None, default: None)