JupyterLab extension to get info from hub api

Hi @frouzbeh, I am also interested to do exactly this! I hope you had some progress since. If not, please let me outline my thoughts and if you are still interested we can continue discussion here.

  1. Send a request to JupyterHub API from backend
    This part is relatively easy to do on the backend. You need a token and API url. For eaxmple, I was able to get the username of the current user:
import requests

api_url = os.environ['JUPYTERHUB_API_URL']

r = requests.get(api_url + '/user',
    headers={
             'Authorization': 'token %s' % os.environ['JUPYTERHUB_API_TOKEN'],
            }
    )

r.raise_for_status()
user = r.json()
  1. To get the same information in the frontend, you will need to to either send the information from the backend or send the API key and API url and make a API request from the frontend. In either case, you will need to have both frontend and backend part of the extension. I do not yet know how to make the connection between the two, but there are a lot of extensions using this scheme so it should be possible to replicate.

Does anyone have experience in doing this? If not, I can post my next steps here, so hopefully we can make it work for everyone

1 Like