How to execute a command on Jupyter Notebook Server Terminal via the Rest API or any Method

I have deployed Jupyterhub on Kubernetes following the ztjh guide I have setup nbgrader and ngshare on jupyterhub using this ngshare readocs, I have a Learning management system(LMS), I want to view the list of assignments both for instructors and students I can do that by using the rest API of Jupyternotebook like this

import requests
import json

api_url = ''
r = requests.get(api_url,params = payload)

users = r.json()
print(json.dumps(users, indent = 1))

now I want to grade all submitted assignments using the nbgrader command nbgrader autograde "Assignment1", I can do that by logging into the instructor notebook server and going to the terminal and running the same command but I want to run this command on the notebook server terminal using Jupyter Notebook server rest API, so that instructor clicks on grade button on the LMS frontend which sends a request to LMS backend and which sends a rest API request(which has the above command) to jupyter notebook , which runs the command on terminal and returns the response to LMS backend. I cannot find anything similar on the Jupyter Notebook API documentation there is endpoint to start a terminal but not how to run commands on. @willingc @minrk Please help.

To interact with nbgrader, you’ll have to use one of its APIs, which are separate from other projects, even though they are running in the same server.

One way to do this would be to open your browser and do the thing you want with the UI, then watch what goes over the wire, and write equivalent code.

Alternately, a more knowledge-driven approach: every HTML form or REST API endpoint will have a corresponding JupyterHandler (or subclass declared) for it:

Reading through those would show the various get_argument fields that would become parts of, data={"field_1"=foo}), or if there is a JSON slug to use.

It might even make sense to build your own extension which implements these features, using the PythonAPI, if you are going to write custom UI on top of it.

1 Like

Cross-posted here.