Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downloading Jupyter notebook from external URL using CLI

I need to download .ipynb-file in a terminal and than run it (using nbconvert or something like that).

  1. I tried use wget and curl for this, but I got web page (with tags and Javascript code) instead of runnable Notebook.

  2. Then I used Jupyter REST API. To get a notebook's content I used /api/contents/<path>/<file> I.e. I simply changed notebooks to api/contents in URL. I got a content of the notebook with some additional text (I'll have to filter it later), and... in a form of one line. So, I have a lot of work to convert this one line into a working notebook.

Is it possible to download Jupyter notebook via terminal and to get working .ipynb-file (the same as file can be downloaded by download as .ipynb in Jupyter Web UI).

like image 372
VeLKerr Avatar asked Aug 05 '17 12:08

VeLKerr


People also ask

How to use and install Jupyter Notebook?

And you can also open the Jupyter notebook using the given below link: ‘http://localhost:8888/tree.’ It is mandatory to start the Jupyter in the command prompt then, and only then you will able to access it in your browser. This was the first way to use and Install a Jupyter notebook. 2. Install Jupyter notebook is using Anaconda

What can I do with the CLI in Jupyter book?

Jupyter Book comes with a command-line interface that makes it easy to build your books and run a few common functions. This page contains information on what you can do with the CLI. This page is a complete reference for the CLI. For newcomers who would like to get started with the Jupyter Book CLI, we recommend starting with Overview

How to open Jupyter Notebook in Anaconda?

This will open your Jupyter notebook in your default browser. You can also open the Jupyter notebook using the following link: ‘http://localhost:8888/tree.’ But it is mandatory to run the Jupyter notebook command in Anaconda prompt; without it, you will not be able to access the notebook.

What do I need to get started with Jupyter?

Getting started with the classic Jupyter Notebook. Prerequisite: Python. While Jupyter runs code in many programming languages, Python is a requirement (Python 3.3 or greater, or Python 2.7) for installing the JupyterLab or the classic Jupyter Notebook.


2 Answers

You have to use the Authorization header and Content-Type application/json and then the notebook will be in the "content" part of the dictionary that is returned. You can use jq to get the content part of the dictionary. If on Mac OS X just brew install jq

curl -H "Authorization: Token {YOUR_TOKEN}" -H "Content-Type: application/json" -XGET https://{YOUR_JUPYTER_DOMAIN}/user/{USERNAME}/api/contents/{PATH_TO_IPYNB} | jq ".content"

Also you can add output redirection after the jq part > my_downloaded.ipynb

And then just open it with jupyter notebook

For /user make sure your personal server is started, for this you have to login to your user account or go into your Control panel, if it is not on or has been culled. For /services the server is usually being proxied so it should always be on.

The Url to use for /services

https://{YOUR_JUPYTER_DOMAIN}/services/{SERVICENAME}/api/contents/{PATH_TO_IPYNB}
like image 109
sigurdb Avatar answered Oct 12 '22 19:10

sigurdb


I've also found simple solution. But it is applicable only if the notebook isn't secured by a token. The notebooks can be downloaded by wget.

Assume that our notebook is located by the following URL:

http://<DOMAIN>:<PORT>/notebooks/my_notebook.ipynb 

We can simply replace "notebooks" to "files" and download the source ipynb-file by the following command:

wget http://<DOMAIN>:<PORT>/files/my_notebook.ipynb 
like image 44
VeLKerr Avatar answered Oct 12 '22 19:10

VeLKerr