Run a particular cell of a jupyter notebook

Hi ,
I want to run a specific cell of a Jupyter notebook using the JupyterHub REST APIs. How can I call the APIs to execute a specific cell? To achieve this, the single-user pod containing the notebooks must be running continuously. How can I ensure that the pod runs continuously? After executing the cell, my goal is to send the output as a message to someone. How can this be achieved?

Can someone please explain clearly about this three questions

Code execution is not done via the REST API, but rather the websocket protocol using the message spec.

So if your inputs are a notebook document and cell number, you would use the contents API to retrieve the notebook, nbformat to locate the cell (don’t need to use the Python code, just understand the JSON schema, e.g. nb['cells'][4]['source']). If the input is the actual code, you can skip this step.

Once you have the code you want to execute, start a kernel, then connect a websocket at /api/kernels/{kernel_id}/channels and send an execute_request. The output messages will come on the same websocket.

1 Like