Home › Forums › FABRIC General Questions and Discussion › Download file to local system from Jupyter notebook
Tagged: file-download, jupyter
- This topic has 5 replies, 2 voices, and was last updated 11 months, 3 weeks ago by Ilya Baldin.
-
AuthorPosts
-
November 30, 2023 at 5:11 pm #6145
Hi,
This question maybe have more to do with Jupyter notebook then FABRIC, but hopefully someone can suggest some ideas.
I have a couple of compressed files on the Jupyter server that I want to download to my local computer. I can do this by right-clicking on the file and selecting ‘Download’.
However, I want to automate this process, instead of manually clicking things. Is there a way to access the compressed files via wget or scp from the local system.November 30, 2023 at 5:59 pm #6148What an excellent question!
Yes JupyterHub has two levels of REST APIs – one – the JupyterHub API (for admins) the other the Notebook Server API accessible to users.
You need to obtain the API token by going to Hub Control Panel (see the image)
The APIs can be invoked using the following URL:
https://jupyter.fabric-testbed.net/user/<username>/api
where <username> is your primary email (in fact you should see it in your browser address field when you start the notebook, except it will look like
https://jupyter.fabric-testbed.net/user/<username>/lab
)You can use cURL to make the call (this shows how to start a particular notebook, moving files in and out is similar):
curl -X POST -H "Authorization: token <token string>" "https://jupyter.fabric-testbed.net/user/<username>/api/sessions" -d '{"name":"configure_environment.ipynb","type":"notebook","path":"jupyter-examples-rel1.3.3/fabric_examples/fablib_api/configure_environment/configure_environment.ipynb"}'
December 1, 2023 at 12:53 pm #6152Thanks Ilya for the very useful answer. I was able to download my compressed file with a GET request via curl using this method.
Just some additional information for others,
1) To access the Hub Panel in Jupyter notebook, click on ‘File’->’Hub Control Panel’2) From here click on ‘Token’->’Request New API token’ and save the generated token number, which can be used in the curl request as a header (-H).
I still have to look into generating tokens without manual intervention, that will close the automation loop. If there are any updates I will post them here.
December 1, 2023 at 1:17 pm #6153Nishanth,
I do not believe it is possible to automate getting the token – it requires someone to login using your credentials. However the token should be good for a while – you should be able to select the lifetime.
Also please note that the token allows access to your container via API without any other checks – if someone steals it they may act on your behalf in the container so long as you have an active container (e.g. upload and execute a notebook) or wipe its contents clean. You must secure the token. Be mindful of e.g. uploading into GitHub or sharing it with others.
December 1, 2023 at 1:37 pm #6154Thanks, I agree with you Ilya. I have seen some of the APIs in the link you shared, and they can delete files, and shutdown the kernel etc. which is a huge security risk.
It’s probably more pragmatic to download using the right click option via the UI.December 1, 2023 at 1:41 pm #6155The APIs are enabled for your use, you do need to use them judiciously and keep in mind that if you can invoke them, so can someone else if they have your token.
-
AuthorPosts
- You must be logged in to reply to this topic.