1

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://xx.xxx.xxx.xx/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 it.

Anonymous
  • 25
  • 7
  • Cross-posted [here](https://discourse.jupyter.org/t/how-to-execute-a-command-on-jupyter-notebook-server-terminal-via-the-rest-api-or-any-method/15674?u=fomightez). Please don't cross-post without referencing all posts in all places. Otherwise, it divides up efforts. – Wayne Sep 08 '22 at 20:09

1 Answers1

1

An easier way to invoke terminal using jupyter-notebooks is to use magic function %%bash and use the jupyter cell as a terminal:

%%bash
head xyz.txt
pip install keras
git add model.h5.dvc data.dvc metrics.json
git commit -m "Second model, trained with 2000 images"

For more information refer to this Advance Jupyter notebook Tricks.

Check this Link to Interact with Jupyter Notebooks via AP

Hemanth Kumar
  • 2,728
  • 1
  • 4
  • 19
  • i know that i can use magic functions to run terminal commands but that will be inside a jupyter notebook inside a user's directory but I don't want to create a notebook and then run that notebook on a notebook server I just want to run the command directly on the server's terminal via an API call or any other method that does not involve creating a notebook. – Anonymous Sep 08 '22 at 12:05
  • @Anonymous : Check this [Link](https://stackoverflow.com/questions/54475896/interact-with-jupyter-notebooks-via-api) to Interact with Jupyter Notebooks via API – Hemanth Kumar Sep 08 '22 at 12:10
  • 1
    thanks, I was able to do it with WebSocket connections. – Anonymous Sep 12 '22 at 06:43