jupyter / nbgrader

A system for assigning and grading notebooks
https://nbgrader.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.3k stars 317 forks source link

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

Open adarshverma19 opened 2 years ago

adarshverma19 commented 2 years ago

I have deployed Jupyterhub on Kubernetes following this guide link, I have setup nbgrader and ngshare on jupyterhub using this guide link, I have a Learning management system(LMS) similar to moodle, 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 = 'http://35.225.169.22/user/kevin/api/contents/release'
payload = {'token': 'XXXXXXXXXXXXXXXXXXXXXXXXXX'}
r = requests.get(api_url,params = payload)

r.raise_for_status()
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 instructor notebook server and going to 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.

brichet commented 8 months ago

@adarshverma19 did you find a solution for your problem ?

Maybe you can take a look at this endpoint https://github.com/jupyter/nbgrader/blob/12136c2eccde44ca7a86b7805e240a406704cb74/nbgrader/server_extensions/formgrader/apihandlers.py#L332