Jupyter Notebook Readthedocs Io en v6.4.5
Jupyter Notebook Readthedocs Io en v6.4.5
Release 6.4.5
https://jupyter.org
3 Notebook Examples 15
5 Changelog 63
6 Comms 101
16 My Notebook 173
i
ii
Jupyter Notebook Documentation, Release 6.4.5
• Installation
• Starting the Notebook
USER DOCUMENTATION 1
Jupyter Notebook Documentation, Release 6.4.5
2 USER DOCUMENTATION
CHAPTER
ONE
1.1 Introduction
The notebook extends the console-based approach to interactive computing in a qualitatively new direction, providing a
web-based application suitable for capturing the whole computation process: developing, documenting, and executing
code, as well as communicating the results. The Jupyter notebook combines two components:
A web application: a browser-based tool for interactive authoring of documents which combine explanatory text,
mathematics, computations and their rich media output.
Notebook documents: a representation of all content visible in the web application, including inputs and outputs of
the computations, explanatory text, mathematics, images, and rich media representations of objects.
See also:
See the installation guide on how to install the notebook and its dependencies.
• In-browser editing for code, with automatic syntax highlighting, indentation, and tab completion/introspection.
• The ability to execute code from the browser, with the results of computations attached to the code which gener-
ated them.
• Displaying the result of computation using rich media representations, such as HTML, LaTeX, PNG, SVG, etc.
For example, publication-quality figures rendered by the matplotlib library, can be included inline.
• In-browser editing for rich text using the Markdown markup language, which can provide commentary for the
code, is not limited to plain text.
• The ability to easily include mathematical notation within markdown cells using LaTeX, and rendered natively
by MathJax.
Notebook documents contains the inputs and outputs of a interactive session as well as additional text that accompanies
the code but is not meant for execution. In this way, notebook files can serve as a complete computational record of a
session, interleaving executable code with explanatory text, mathematics, and rich representations of resulting objects.
These documents are internally JSON files and are saved with the .ipynb extension. Since JSON is a plain text format,
they can be version-controlled and shared with colleagues.
Notebooks may be exported to a range of static formats, including HTML (for example, for blog posts), reStructured-
Text, LaTeX, PDF, and slide shows, via the nbconvert command.
3
Jupyter Notebook Documentation, Release 6.4.5
Furthermore, any .ipynb notebook document available from a public URL can be shared via the Jupyter Notebook
Viewer <nbviewer>. This service loads the notebook document from the URL and renders it as a static web page.
The results may thus be shared with a colleague, or as a public blog post, without other users needing to install the
Jupyter notebook themselves. In effect, nbviewer is simply nbconvert as a web service, so you can do your own static
conversions with nbconvert, without relying on nbviewer.
See also:
Details on the notebook JSON file format
Because you use Jupyter in a web browser, some people are understandably concerned about using it with sensitive
data. However, if you followed the standard install instructions, Jupyter is actually running on your own computer. If
the URL in the address bar starts with http://localhost: or http://127.0.0.1:, it’s your computer acting as
the server. Jupyter doesn’t send your data anywhere else—and as it’s open source, other people can check that we’re
being honest about this.
You can also use Jupyter remotely: your company or university might run the server for you, for instance. If you want
to work with sensitive data in those cases, talk to your IT or data protection staff about it.
We aim to ensure that other pages in your browser or other users on the same computer can’t access your notebook
server. See Security in the Jupyter notebook server for more about this.
You can start running a notebook server from the command line using the following command:
jupyter notebook
This will print some information about the notebook server in your console, and open a web browser to the URL of the
web application (by default, http://127.0.0.1:8888).
The landing page of the Jupyter notebook web application, the dashboard, shows the notebooks currently available in
the notebook directory (by default, the directory from which the notebook server was started).
You can create new notebooks from the dashboard with the New Notebook button, or open existing ones by clicking
on their name. You can also drag and drop .ipynb notebooks and standard .py Python source code files into the
notebook list area.
When starting a notebook server from the command line, you can also open a particular notebook directly, bypassing
the dashboard, with jupyter notebook my_notebook.ipynb. The .ipynb extension is assumed if no extension is
given.
When you are inside an open notebook, the File | Open. . . menu option will open the dashboard in a new browser tab,
to allow you to open another notebook from the notebook directory or to create a new notebook.
Note: You can start more than one notebook server at the same time, if you want to work on notebooks in different
directories. By default the first notebook server starts on port 8888, and later notebook servers search for ports near
that one. You can also manually specify the port with the --port option.
A new notebook may be created at any time, either from the dashboard, or using the File → New menu option from
within an active notebook. The new notebook is created within the same directory and will open in a new browser tab.
It will also be reflected as a new entry in the notebook list on the dashboard.
An open notebook has exactly one interactive session connected to a kernel, which will execute code sent by the user
and communicate back results. This kernel remains active if the web browser window is closed, and reopening the
same notebook from the dashboard will reconnect the web application to the same kernel. In the dashboard, notebooks
with an active kernel have a Shutdown button next to them, whereas notebooks without an active kernel have a Delete
button in its place.
Other clients may connect to the same kernel. When each kernel is started, the notebook server prints to the terminal
a message like this:
This long string is the kernel’s ID which is sufficient for getting the information necessary to connect to the kernel. If
the notebook uses the IPython kernel, you can also see this connection data by running the %connect_info magic,
which will print the same ID information along with other details.
You can then, for example, manually start a Qt console connected to the same kernel from the command line, by passing
a portion of the ID:
Without an ID, --existing will connect to the most recently started kernel.
With the IPython kernel, you can also run the %qtconsole magic in the notebook to open a Qt console connected to
the same kernel.
See also:
Decoupled two-process model
When you create a new notebook document, you will be presented with the notebook name, a menu bar, a toolbar
and an empty code cell.
Notebook name: The name displayed at the top of the page, next to the Jupyter logo, reflects the name of the .ipynb
file. Clicking on the notebook name brings up a dialog which allows you to rename it. Thus, renaming a notebook
from “Untitled0” to “My first notebook” in the browser, renames the Untitled0.ipynb file to My first notebook.
ipynb.
Menu bar: The menu bar presents different options that may be used to manipulate the way the notebook functions.
Toolbar: The tool bar gives a quick way of performing the most-used operations within the notebook, by clicking on
an icon.
Code cell: the default type of cell; read on for an explanation of cells.
The notebook consists of a sequence of cells. A cell is a multiline text input field, and its contents can be executed by
using Shift-Enter, or by clicking either the “Play” button the toolbar, or Cell, Run in the menu bar. The execution
behavior of a cell is determined by the cell’s type. There are three types of cells: code cells, markdown cells, and raw
cells. Every cell starts off being a code cell, but its type can be changed by using a drop-down on the toolbar (which
will be “Code”, initially), or via keyboard shortcuts.
For more information on the different things you can do in a notebook, see the collection of examples.
A code cell allows you to edit and write new code, with full syntax highlighting and tab completion. The programming
language you use depends on the kernel, and the default kernel (IPython) runs Python code.
When a code cell is executed, code that it contains is sent to the kernel associated with the notebook. The results that
are returned from this computation are then displayed in the notebook as the cell’s output. The output is not limited to
text, with many other possible forms of output are also possible, including matplotlib figures and HTML tables (as
used, for example, in the pandas data analysis package). This is known as IPython’s rich display capability.
See also:
Rich Output example notebook
You can document the computational process in a literate way, alternating descriptive text with code, using rich text.
In IPython this is accomplished by marking up text with the Markdown language. The corresponding cells are called
Markdown cells. The Markdown language provides a simple way to perform this text markup, that is, to specify which
parts of the text should be emphasized (italics), bold, form lists, etc.
If you want to provide structure for your document, you can use markdown headings. Markdown headings consist of
1 to 6 hash # signs # followed by a space and the title of your section. The markdown heading will be converted to a
clickable link for a section of the notebook. It is also used as a hint when exporting to other document formats, like
PDF.
When a Markdown cell is executed, the Markdown code is converted into the corresponding formatted rich text. Mark-
down allows arbitrary HTML code for formatting.
Within Markdown cells, you can also include mathematics in a straightforward way, using standard LaTeX notation:
$...$ for inline mathematics and $$...$$ for displayed mathematics. When the Markdown cell is executed, the
LaTeX portions are automatically rendered in the HTML output as equations with high quality typography. This is
made possible by MathJax, which supports a large subset of LaTeX functionality
Standard mathematics environments defined by LaTeX and AMS-LaTeX (the amsmath package) also work, such as
\begin{equation}...\end{equation}, and \begin{align}...\end{align}. New LaTeX macros may be de-
fined using standard methods, such as \newcommand, by placing them anywhere between math delimiters in a Mark-
down cell. These definitions are then available throughout the rest of the IPython session.
See also:
Working with Markdown Cells example notebook
Raw cells provide a place in which you can write output directly. Raw cells are not evaluated by the notebook. When
passed through nbconvert, raw cells arrive in the destination format unmodified. For example, you can type full LaTeX
into a raw cell, which will only be rendered by LaTeX after conversion by nbconvert.
The normal workflow in a notebook is, then, quite similar to a standard IPython session, with the difference that you
can edit cells in-place multiple times until you obtain the desired results, rather than having to rerun separate scripts
with the %run magic command.
Typically, you will work on a computational problem in pieces, organizing related ideas into cells and moving forward
once previous parts work correctly. This is much more convenient for interactive exploration than breaking up a com-
putation into scripts that must be executed together, as was previously necessary, especially if parts of them take a long
time to run.
To interrupt a calculation which is taking too long, use the Kernel, Interrupt menu option, or the i,i keyboard shortcut.
Similarly, to restart the whole computational process, use the Kernel, Restart menu option or 0,0 shortcut.
A notebook may be downloaded as a .ipynb file or converted to a number of other formats using the menu option
File, Download as.
See also:
Running Code in the Jupyter Notebook example notebook
Notebook Basics example notebook
All actions in the notebook can be performed with the mouse, but keyboard shortcuts are also available for the most
common ones. The essential shortcuts to remember are the following:
• Shift-Enter: run cell Execute the current cell, show any output, and jump to the next cell below. If
Shift-Enter is invoked on the last cell, it makes a new cell below. This is equivalent to clicking the
Cell, Run menu item, or the Play button in the toolbar.
• Esc: Command mode In command mode, you can navigate around the notebook using keyboard shortcuts.
• Enter: Edit mode In edit mode, you can edit text in cells.
For the full list of available shortcuts, click Help, Keyboard Shortcuts in the notebook menus.
1.6 Plotting
One major feature of the Jupyter notebook is the ability to display plots that are the output of running code cells. The
IPython kernel is designed to work seamlessly with the matplotlib plotting library to provide this functionality. Specific
plotting library integration is a feature of the kernel.
For information on how to install a Python kernel, refer to the IPython install page.
The Jupyter wiki has a long list of Kernels for other languages. They usually come with instructions on how to make
the kernel available in the notebook.
To prevent untrusted code from executing on users’ behalf when notebooks open, we store a signature of each trusted
notebook. The notebook server verifies this signature when a notebook is opened. If no matching signature is found,
Javascript and HTML output will not be displayed until they are regenerated by re-executing the cells.
Any notebook that you have fully executed yourself will be considered trusted, and its HTML and Javascript output
will be displayed on load.
If you need to see HTML or Javascript output without re-executing, and you are sure the notebook is not malicious,
you can tell Jupyter to trust it at the command-line with:
See Security in notebook documents for more details about the trust mechanism.
The Jupyter Notebook aims to support the latest versions of these browsers:
• Chrome
• Safari
• Firefox
Up to date versions of Opera and Edge may also work, but if they don’t, please use one of the supported browsers.
Using Safari with HTTPS and an untrusted certificate is known to not work (websockets will fail).
TWO
When opening bug reports or sending emails to the Jupyter mailing list, it is useful to know the names of different UI
components so that other developers and users have an easier time helping you diagnose your problems. This section
will familiarize you with the names of UI elements within the Notebook and the different Notebook modes.
When you launch jupyter notebook the first page that you encounter is the Notebook Dashboard.
11
Jupyter Notebook Documentation, Release 6.4.5
Once you’ve selected a Notebook to edit, the Notebook will open in the Notebook Editor.
If you would like to learn more about the specific elements within the Notebook Editor, you can go through the user
interface tour by selecting Help in the menubar then selecting User Interface Tour.
When a cell is in edit mode, the Cell Mode Indicator will change to reflect the cell’s state. This state is indicated by a
small pencil icon on the top right of the interface. When the cell is in command mode, there is no icon in that location.
Now let’s say that you’ve chosen to open a Markdown file instead of a Notebook file whilst in the Notebook Dashboard.
If so, the file will be opened in the File Editor.
THREE
NOTEBOOK EXAMPLES
The pages in this section are all converted notebook files. You can also view these notebooks on nbviewer.
3.1.1 Introduction
The Jupyter Notebook is an interactive computing environment that enables users to author notebook documents that
include: - Live code - Interactive widgets - Plots - Narrative text - Equations - Images - Video
These documents provide a complete and self-contained record of a computation that can be converted to various
formats and shared with others using email, Dropbox, version control systems (like git/GitHub) or nbviewer.jupyter.org.
Components
15
Jupyter Notebook Documentation, Release 6.4.5
• Include mathematical equations using LaTeX syntax in Markdown, which are rendered in-browser by MathJax.
3.1.3 Kernels
Through Jupyter’s kernel and messaging architecture, the Notebook allows code to be run in a range of different pro-
gramming languages. For each notebook document that a user opens, the web application starts a kernel that runs the
code for that notebook. Each kernel is capable of running code in a single programming language and there are kernels
available in the following languages:
• Python(https://github.com/ipython/ipython)
• Julia (https://github.com/JuliaLang/IJulia.jl)
• R (https://github.com/IRkernel/IRkernel)
• Ruby (https://github.com/minrk/iruby)
• Haskell (https://github.com/gibiansky/IHaskell)
• Scala (https://github.com/Bridgewater/scala-notebook)
• node.js (https://gist.github.com/Carreau/4279371)
• Go (https://github.com/takluyver/igo)
The default kernel runs Python code. The notebook provides a simple way for users to pick which of these kernels is
used for a given notebook.
Each of these kernels communicate with the notebook web application and web browser using a JSON over Ze-
roMQ/WebSockets message protocol that is described here. Most users don’t need to know about these details, but
it helps to understand that “kernels run code.”
Notebook documents contain the inputs and outputs of an interactive session as well as narrative text that accompa-
nies the code but is not meant for execution. Rich output generated by running code, including HTML, images, video,
and plots, is embeddeed in the notebook, which makes it a complete and self-contained record of a computation.
When you run the notebook web application on your computer, notebook documents are just files on your local filesys-
tem with a .ipynb extension. This allows you to use familiar workflows for organizing your notebooks into folders
and sharing them with others.
Notebooks consist of a linear sequence of cells. There are three basic cell types:
• Code cells: Input and output of live code that is run in the kernel
• Markdown cells: Narrative text with embedded LaTeX equations
• Raw cells: Unformatted text that is included, without modification, when notebooks are converted to different
formats using nbconvert
Internally, notebook documents are JSON data with binary values base64 encoded. This allows them to be read and
manipulated programmatically by any programming language. Because JSON is a text format, notebook documents
are version control friendly.
Notebooks can be exported to different static formats including HTML, reStructeredText, LaTeX, PDF, and slide
shows (reveal.js) using Jupyter’s nbconvert utility.
Furthermore, any notebook document available from a public URL or on GitHub can be shared via nbviewer. This
service loads the notebook document from the URL and renders it as a static web page. The resulting web page may
thus be shared with others without their needing to install the Jupyter Notebook.
When you first start the notebook server, your browser will open to the notebook dashboard. The dashboard serves
as a home page for the notebook. Its main purpose is to display the notebooks and files in the current directory. For
example, here is a screenshot of the dashboard page for the examples directory in the Jupyter repository:
The top of the notebook list displays clickable breadcrumbs of the current directory. By clicking on these breadcrumbs
or on sub-directories in the notebook list, you can navigate your file system.
To create a new notebook, click on the “New” button at the top of the list and select a kernel from the dropdown (as
seen below). Which kernels are listed depend on what’s installed on the server. Some of the kernels in the screenshot
below may not exist as an option to you.
Notebooks and files can be uploaded to the current directory by dragging a notebook file onto the notebook list or by
the “click here” text above the list.
The notebook list shows green “Running” text and a green notebook icon next to running notebooks (as seen below).
Notebooks remain running until you explicitly shut them down; closing the notebook’s page is not sufficient.
To shutdown, delete, duplicate, or rename a notebook check the checkbox next to it and an array of controls will appear
at the top of the notebook list (as seen below). You can also use the same operations on directories and files when
applicable.
To see all of your running notebooks along with their directories, click on the “Running” tab:
This view provides a convenient way to track notebooks that you start as you navigate the file system in a long running
notebook server.
If you create a new notebook or open an existing one, you will be taken to the notebook user interface (UI). This UI
allows you to run code and author notebook documents interactively. The notebook UI has the following main areas:
• Menu
• Toolbar
• Notebook area and cells
The notebook has an interactive tour of these elements that can be started in the “Help:User Interface Tour” menu item.
Starting with IPython 2.0, the Jupyter Notebook has a modal user interface. This means that the keyboard does different
things depending on which mode the Notebook is in. There are two modes: edit mode and command mode.
Edit mode
Edit mode is indicated by a green cell border and a prompt showing in the editor area:
When a cell is in edit mode, you can type into the cell, like a normal text editor.
Enter edit mode by pressing Enter or using the mouse to click on a cell’s editor area.
Command mode
Command mode is indicated by a grey cell border with a blue left margin:
When you are in command mode, you are able to edit the notebook as a whole, but not type into individual cells. Most
importantly, in command mode, the keyboard is mapped to a set of shortcuts that let you perform notebook and cell
actions efficiently. For example, if you are in command mode and you press c, you will copy the current cell - no
modifier is needed.
Don’t try to type into a cell in command mode; unexpected things will happen!
Enter command mode by pressing Esc or using the mouse to click outside a cell’s editor area.
All navigation and actions in the Notebook are available using the mouse through the menubar and toolbar, which are
both above the main Notebook area:
The first idea of mouse based navigation is that cells can be selected by clicking on them. The currently selected cell
gets a grey or green border depending on whether the notebook is in edit or command mode. If you click inside a cell’s
editor area, you will enter edit mode. If you click on the prompt or output area of a cell you will enter command mode.
If you are running this notebook in a live session (not on http://nbviewer.jupyter.org) try selecting different cells and
going between edit and command mode. Try typing into a cell.
The second idea of mouse based navigation is that cell actions usually apply to the currently selected cell. Thus if
you want to run the code in a cell, you would select it and click the
button in the toolbar or the “Cell:Run” menu item. Similarly, to copy a cell you would select it and click the
button in the toolbar or the “Edit:Copy” menu item. With this simple pattern, you should be able to do most everything
you need with the mouse.
Markdown cells have one other state that can be modified with the mouse. These cells can either be rendered or
unrendered. When they are rendered, you will see a nice formatted representation of the cell’s contents. When they are
unrendered, you will see the raw text source of the cell. To render the selected cell with the mouse, click the
button in the toolbar or the “Cell:Run” menu item. To unrender the selected cell, double click on the cell.
The modal user interface of the Jupyter Notebook has been optimized for efficient keyboard usage. This is made
possible by having two different sets of keyboard shortcuts: one set that is active in edit mode and another in command
mode.
The most important keyboard shortcuts are Enter, which enters edit mode, and Esc, which enters command mode.
In edit mode, most of the keyboard is dedicated to typing into the cell’s editor. Thus, in edit mode there are relatively
few shortcuts. In command mode, the entire keyboard is available for shortcuts, so there are many more. The Help-
>``Keyboard Shortcuts`` dialog lists the available shortcuts.
We recommend learning the command mode shortcuts in the following rough order:
1. Basic navigation: enter, shift-enter, up/k, down/j
2. Saving the notebook: s
3. Change Cell types: y, m, 1-6, t
4. Cell creation: a, b
5. Cell editing: x, c, v, d, z
6. Kernel operations: i, 0 (press twice)
First and foremost, the Jupyter Notebook is an interactive environment for writing and running code. The notebook is
capable of running code in a wide range of languages. However, each notebook is associated with a single kernel. This
notebook is associated with the IPython kernel, therefore runs Python code.
[2]: a = 10
[3]: print(a)
10
Code is run in a separate process called the Kernel. The Kernel can be interrupted or restarted. Try running the
following cell and then hit the
button in the toolbar above.
If the Kernel dies you will be prompted to restart it. Here we call the low-level system libc.time routine with the wrong
argument via ctypes to segfault the Python interpreter:
The “Cell” menu has a number of menu items for running code in different ways. These includes:
• Run and Select Below
• Run and Insert Below
• Run All
• Run All Above
• Run All Below
The kernel maintains the state of a notebook’s computations. You can reset this state by restarting the kernel. This is
done by clicking on the
in the toolbar above.
The stdout and stderr streams are displayed as text in the output area.
hi, stderr
All output is displayed asynchronously as it is generated in the Kernel. If you execute the next cell, you will see the
output one piece at a time, not all at the end.
To better handle large outputs, the output area can be collapsed. Run the following cell and then single- or double-
click on the active area to the left of the output:
Text can be added to Jupyter Notebooks using Markdown cells. You can change the cell type to Markdown by using the
Cell menu, the toolbar, or the key shortcut m. Markdown is a popular markup language that is a superset of HTML.
Its specification can be found here:
https://daringfireball.net/projects/markdown/
You can make text italic or bold by surrounding a block of text with a single or double * respectively
You can build nested itemized or enumerated lists:
• One
– Sublist
∗ This
• Sublist - That - The other thing
• Two
• Sublist
• Three
• Sublist
Now another list:
1. Here we go
1. Sublist
2. Sublist
2. There we go
3. Now this
Here is a blockquote:
Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is
better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special
cases aren’t special enough to break the rules. Although practicality beats purity. Errors should never
pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There
should be one– and preferably only one –obvious way to do it. Although that way may not be obvious at
first unless you’re Dutch. Now is better than never. Although never is often better than right now. If the
implementation is hard to explain, it’s a bad idea. If the implementation is easy to explain, it may be a
good idea. Namespaces are one honking great idea – let’s do more of those!
And shorthand for links:
Jupyter’s website
You can use backslash to generate literal characters which would otherwise have special meaning in the Markdown
syntax.
\*literal asterisks\*
*literal asterisks*
3.4.2 Headings
You can add headings by starting a line with one (or multiple) # followed by a space, as in the following example:
# Heading 1
# Heading 2
## Heading 2.1
## Heading 2.2
You can embed code meant for illustration instead of execution in Python:
def f(x):
"""a docstring"""
return x**2
or other languages:
Courtesy of MathJax, you can include mathematical expressions both inline: 𝑒𝑖𝜋 + 1 = 0 and displayed:
∞
∑︁ 1 𝑖
𝑒𝑥 = 𝑥 (3.1)
𝑖=0
𝑖!
$e^{i\pi} + 1 = 0$
\begin{equation}
e^x=\sum_{i=0}^\infty \frac{1}{i!}x^i
\end{equation}
The Notebook webapp supports Github flavored markdown meaning that you can use triple backticks for code blocks:
```python
print "Hello World"
```
```javascript
console.log("Hello World")
```
Gives:
console.log("Hello World")
| This | is |
|------|------|
| a | table|
This is
a table
Because Markdown is a superset of HTML you can even add things like HTML tables:
Header 1
Header 2
row 1, cell 1
row 1, cell 2
row 2, cell 1
row 2, cell 2
If you have local files in your Notebook directory, you can refer to these files in Markdown cells directly:
[subdirectory/]<filename>
animation
These do not embed the data into the notebook file, and require that the files exist when you are viewing the notebook.
Note that this means that the Jupyter notebook server also acts as a generic file server for files inside the same tree as
your notebooks. Access is not granted outside the notebook folder so you have strict control over what files are visible,
but for this reason it is highly recommended that you do not run the notebook server with a notebook directory at a
high level in your filesystem (e.g. your home directory).
When you run the notebook in a password-protected manner, local file access is restricted to authenticated users unless
read-only views are active.
Markdown attachments
Since Jupyter notebook version 5.0, in addition to referencing external file you can attach a file to a markdown cell. To
do so drag the file from in a markdown cell while editing it:
Files are stored in cell metadata and will be automatically scrubbed at save-time if not referenced. You can recognized
attached images from other files by their url that starts with attachment:. For the image above:

Keep in mind that attached files will increase the size of your notebook.
You can manually edit the attachment by using the View > Cell Toolbar > Attachment menu, but you should
not need to.
Starting with Jupyter Notebook 5.0, you can customize the command mode shortcuts from within the Notebook Appli-
cation itself.
Head to the ``Help`` menu and select the ``Edit keyboard Shortcuts`` item. A dialog will guide you through the
process of adding custom keyboard shortcuts.
Keyboard shortcut set from within the Notebook Application will be persisted to your configuration file. A single action
may have several shortcuts attached to it.
Starting with IPython 2.0 keyboard shortcuts in command and edit mode are fully customizable. These customizations
are made using the Jupyter JavaScript API. Here is an example that makes the r key available for running a cell:
[ ]: %%javascript
Jupyter.keyboard_manager.command_shortcuts.add_shortcut('r', {
help : 'run cell',
help_index : 'zz',
handler : function (event) {
IPython.notebook.execute_cell();
return false;
}}
);
“By default the keypress r, while in command mode, changes the type of the selected cell to raw. This shortcut is
overridden by the code in the previous cell, and thus the action no longer be available via the keypress r.”
There are a couple of points to mention about this API:
• The help_index field is used to sort the shortcuts in the Keyboard Shortcuts help dialog. It defaults to zz.
• When a handler returns false it indicates that the event should stop propagating and the default action should
not be performed. For further details about the event object or event handling, see the jQuery docs.
• If you don’t need a help or help_index field, you can simply pass a function as the second argument to
add_shortcut.
[ ]: %%javascript
[ ]: %%javascript
Jupyter.keyboard_manager.command_shortcuts.remove_shortcut('r');
If you want your keyboard shortcuts to be active for all of your notebooks, put the above API calls into your custom.js
file.
Of course we provide name for majority of existing action so that you do not have to re-write everything, here is for
example how to bind r back to it’s initial behavior:
[ ]: %%javascript
Jupyter.keyboard_manager.command_shortcuts.add_shortcut('r', 'jupyter-notebook:change-
˓→cell-to-raw');
One of the main reasons why we developed the current notebook web application was to embrace the web technology.
By being a pure web application using HTML, JavaScript, and CSS, the Notebook can get all the web technology
improvement for free. Thus, as browser support for different media extend, the notebook web app should be able to be
compatible without modification.
This is also true with performance of the User Interface as the speed of JavaScript VM increases.
The other advantage of using only web technology is that the code of the interface is fully accessible to the end user
and is modifiable live. Even if this task is not always easy, we strive to keep our code as accessible and reusable as
possible. This should allow us - with minimum effort - development of small extensions that customize the behavior
of the web interface.
The first tool that is available to you and that you should be aware of are browser “developers tool”. The exact nam-
ing can change across browser and might require the installation of extensions. But basically they can allow you to
inspect/modify the DOM, and interact with the JavaScript code that runs the frontend.
• In Chrome and Safari, Developer tools are in the menu View > Developer > JavaScript Console
• In Firefox you might need to install Firebug
Those will be your best friends to debug and try different approaches for your extensions.
Injecting JS
Using magics
The above tools can be tedious for editing edit long JavaScript files. Therefore we provide the %%javascript magic.
This allows you to quickly inject JavaScript into the notebook. Still the JavaScript injected this way will not survive
reloading. Hence, it is a good tool for testing and refining a script.
You might see here and there people modifying css and injecting js into the notebook by reading file(s) and publishing
them into the notebook. Not only does this often break the flow of the notebook and make the re-execution of the
notebook broken, but it also means that you need to execute those cells in the entire notebook every time you need to
update the code.
This can still be useful in some cases, like the %autosave magic that allows you to control the time between each save.
But this can be replaced by a JavaScript dropdown menu to select the save interval.
custom.js
To inject JavaScript we provide an entry point: custom.js that allows the user to execute and load other resources
into the notebook. JavaScript code in custom.js will be executed when the notebook app starts and can then be used
to customize almost anything in the UI and in the behavior of the notebook.
custom.js can be found in the ~/.jupyter/custom/custom.js. You can share your custom.js with others.
Back to theory
and custom js is in
[ ]: import os.path
custom_js_path = os.path.join(jupyter_dir, 'custom', 'custom.js')
[ ]: # my custom js
if os.path.isfile(custom_js_path):
with open(custom_js_path) as f:
print(f.read())
else:
print("You don't have a custom.js file")
Note that custom.js is meant to be modified by user. When writing a script, you can define it in a separate file and
add a line of configuration into custom.js that will fetch and execute the file.
Warning : even if modification of custom.js takes effect immediately after browser refresh (except if browser cache
is aggressive), creating a file in static/ directory needs a server restart.
3.7.2 Exercise :
We’ve seen above that you can change the autosave rate by using a magic. This is typically something I don’t want to
type every time, and that I don’t like to embed into my workflow and documents. (readers don’t care what my autosave
time is). Let’s build an extension that allows us to do it.
Create a dropdown element in the toolbar (DOM Jupyter.toolbar.element), you will need
• Jupyter.notebook.set_autosave_interval(milliseconds)
• know that 1 min = 60 sec, and 1 sec = 1000 ms
// TODO:
//the_toolbar_element.append(label)
//the_toolbar_element.append(select);
select.change(function() {
var val = jQuery(this).val() // val will be the value in [2]
// TODO
// this will be called when dropdown changes
});
Jupyter.config.cell_magic_highlight['magic_text/x-cython'] = {}
Jupyter.config.cell_magic_highlight['magic_text/x-cython'].reg = [/^%%cython/]
text/x-cython is the name of CodeMirror mode name, magic_ prefix will just patch the mode so that the first line
that contains a magic does not screw up the highlighting. regis a list or regular expression that will trigger the change
of mode.
Sadly, you will have to read the js source file (but there are lots of comments) and/or build the JavaScript documentation
using yuidoc. If you have node and yui-doc installed:
$ cd ~/jupyter/notebook/notebook/static/notebook/js/
$ yuidoc . --server
warn: (yuidoc): Failed to extract port, setting to the default :3000
info: (yuidoc): Starting [email protected] using [email protected] with [email protected]
info: (yuidoc): Scanning for yuidoc.json file.
info: (yuidoc): Starting YUIDoc with the following options:
info: (yuidoc):
{ port: 3000,
nocode: false,
paths: [ '.' ],
server: true,
outdir: './out' }
info: (yuidoc): Scanning for yuidoc.json file.
info: (server): Starting server: http://127.0.0.1:3000
By browsing the documentation you will see that we have some convenience methods that allows us to avoid re-inventing
the UI every time :
Jupyter.toolbar.add_buttons_group([
{
'label' : 'run qtconsole',
'icon' : 'fa-terminal', // select your icon from
// http://fontawesome.io/icons/
'callback': function(){Jupyter.notebook.kernel.execute('%qtconsole')}
}
// add more button here if needed.
]);
The most requested feature is generally to be able to distinguish an individual cell in the notebook, or run a specific ac-
tion with them. To do so, you can either use Jupyter.notebook.get_selected_cell(), or rely on CellToolbar.
This allows you to register a set of actions and graphical elements that will be attached to individual cells.
Cell Toolbar
You can see some example of what can be done by toggling the Cell Toolbar selector in the toolbar on top of the
notebook. It provides two default presets that are Default and slideshow. Default allows the user to edit the
metadata attached to each cell manually.
First we define a function that takes at first parameter an element on the DOM in which to inject UI element. The
second element is the cell this element wis registered with. Then we will need to register that function and give it a
name.
Register a callback
[ ]: %%javascript
var CellToolbar = Jupyter.CellToolbar
var toggle = function(div, cell) {
var button_container = $(div)
// let's create a button that shows the current value of the metadata
var button = $('<button/>').addClass('btn btn-mini').text(String(cell.metadata.
˓→foo));
// On click, change the metadata value and update the button label
button.click(function(){
var v = cell.metadata.foo;
cell.metadata.foo = !v;
button.text(String(!v));
})
// now we register the callback under the name foo to give the
// user the ability to use it later
CellToolbar.register_callback('tuto.foo', toggle);
Registering a preset
[ ]: %%javascript
Jupyter.CellToolbar.register_preset('Tutorial 1',['tuto.foo','default.rawedit'])
Jupyter.CellToolbar.register_preset('Tutorial 2',['slideshow.select','tuto.foo'])
Exercise:
Try to wrap the all code in a file, put this file in {jupyter_dir}/custom/<a-name>.js, and add
require(['custom/<a-name>']);
could be read as
import a.b as e
import c.d as f
e.something()
f.something()
// read that as
// import custom.zenmode.main as zenmode
require(['custom/zenmode/main'],function(zenmode){
zenmode.background('images/back12.jpg');
})
[ ]:
It is a common problem that people want to import code from Jupyter Notebooks. This is made difficult by the fact that
Notebooks are not plain Python files, and thus cannot be imported by the regular Python machinery.
Fortunately, Python provides some fairly sophisticated hooks into the import machinery, so we can actually make
Jupyter notebooks importable without much difficulty, and only using public APIs.
Here we have our Notebook Loader. It’s actually quite simple - once we figure out the filename of the module, all it
does is:
1. load the notebook document into memory
2. create an empty Module
3. execute every cell in the Module namespace
Since IPython cells can have extended syntax, the IPython transform is applied to turn each of these cells into their
pure-Python counterparts before executing them. If all of your notebook cells are pure-Python, this step is unnecessary.
[ ]: class NotebookLoader(object):
"""Module Loader for Jupyter Notebooks"""
(continues on next page)
# extra work to ensure that magics that would affect the user_ns
# actually affect the notebook module's ns
save_user_ns = self.shell.user_ns
self.shell.user_ns = mod.__dict__
try:
for cell in nb.cells:
if cell.cell_type == 'code':
# transform the input to executable Python
code = self.shell.input_transformer_manager.transform_cell(cell.source)
# run the code in themodule
exec(code, mod.__dict__)
finally:
self.shell.user_ns = save_user_ns
return mod
The finder is a simple object that tells you whether a name can be imported, and returns the appropriate loader. All this
one does is check, when you do:
import mynotebook
[ ]: class NotebookFinder(object):
"""Module finder that locates Jupyter Notebooks"""
def __init__(self):
self.loaders = {}
key = path
if path:
# lists aren't hashable
key = os.path.sep.join(path)
[ ]: sys.meta_path.append(NotebookFinder())
[ ]: ls nbpackage
[ ]: import nbpackage.mynotebook
Here is some simple code to display the contents of a notebook with syntax highlighting, etc.
formatter = HtmlFormatter()
lexer = PythonLexer()
[ ]: def show_notebook(fname):
"""display a short summary of the cells of a notebook"""
with io.open(fname, 'r', encoding='utf-8') as f:
nb = read(f, 4)
html = []
for cell in nb.cells:
html.append("<h4>%s cell</h4>" % cell.cell_type)
if cell.cell_type == 'code':
html.append(highlight(cell.source, lexer, formatter))
else:
html.append("<pre>%s</pre>" % cell.source)
display(HTML('\n'.join(html)))
show_notebook(os.path.join("nbpackage", "mynotebook.ipynb"))
So my notebook has some code cells, one of which contains some IPython syntax.
Let’s see what happens when we import it
[ ]: mynotebook.foo()
Hooray again!
Even the function that contains IPython syntax works:
[ ]: mynotebook.has_ip_syntax()
We also have a notebook inside the nb package, so let’s make sure that works as well.
[ ]: ls nbpackage/nbs
Note that the __init__.py is necessary for nb to be considered a package, just like usual.
So now we have importable notebooks, from both the local directory and inside packages.
I can even put a notebook inside IPython, to further demonstrate that this is working properly:
[ ]: import shutil
from IPython.paths import get_ipython_package_dir
This approach can even import functions and classes that are defined in a notebook using the %%cython magic.
The traditional IPython (ipython) consists of a single process that combines a terminal based UI with the process that
runs the users code.
While this traditional application still exists, the modern Jupyter consists of two processes:
• Kernel: this is the process that runs the users code.
• Frontend: this is the process that provides the user interface where the user types code and sees results.
Jupyter currently has 3 frontends:
• Terminal Console (jupyter console)
• Qt Console (jupyter qtconsole)
• Notebook (jupyter notebook)
The Kernel and Frontend communicate over a ZeroMQ/JSON based messaging protocol, which allows multiple Fron-
tends (even of different types) to communicate with a single Kernel. This opens the door for all sorts of interesting
things, such as connecting a Console or Qt Console to a Notebook’s Kernel. For example, you may want to connect
a Qt console to your Notebook’s Kernel and use it as a help browser, calling ?? on objects in the Qt console (whose
pager is more flexible than the one in the notebook).
This Notebook describes how you would connect another Frontend to an IPython Kernel that is associated with a
Notebook. The commands currently given here are specific to the IPython kernel.
To connect another Frontend to a Kernel manually, you first need to find out the connection information for the Kernel
using the %connect_info magic:
[ ]: %connect_info
You can see that this magic displays everything you need to connect to this Notebook’s Kernel.
You can also start a new Qt Console connected to your current Kernel by using the %qtconsole magic. This will
detect the necessary connection information and start the Qt Console for you automatically.
[ ]: a = 10
[ ]: %qtconsole
The Markdown parser included in the Jupyter Notebook is MathJax-aware. This means that you can freely mix in
mathematical expressions using the MathJax subset of Tex and LaTeX. Some examples from the MathJax demos site
are reproduced below, as well as the Markdown+TeX source.
Source
\begin{align}
\dot{x} & = \sigma(y-x) \\
\dot{y} & = \rho x - y - xz \\
\dot{z} & = -\beta z + xy
\end{align}
Display
Source
\begin{equation*}
\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_
˓→{k=1}^n b_k^2 \right)
\end{equation*}
Display
∑︀𝑛 2 (︀∑︀𝑛 2
)︀ (︀∑︀𝑛 2
)︀
( 𝑘=1 𝑎𝑘 𝑏𝑘 ) ≤ 𝑘=1 𝑎𝑘 𝑘=1 𝑏𝑘
Source
\begin{equation*}
\mathbf{V}_1 \times \mathbf{V}_2 = \begin{vmatrix}
\mathbf{i} & \mathbf{j} & \mathbf{k} \\
\frac{\partial X}{\partial u} & \frac{\partial Y}{\partial u} & 0 \\
\frac{\partial X}{\partial v} & \frac{\partial Y}{\partial v} & 0
\end{vmatrix}
\end{equation*}
Display
⃒ ⃒
⃒ i j k⃒⃒
V1 × V2 = ⃒⃒ 𝜕𝑋
⃒ 𝜕𝑌
𝜕𝑢 𝜕𝑢 0 ⃒⃒
⃒ 𝜕𝑋 𝜕𝑌
0⃒
𝜕𝑣 𝜕𝑣
3.10.4 The probability of getting (k) heads when flipping (n) coins is
Source
\begin{equation*}
P(E) = {n \choose k} p^k (1-p)^{ n-k}
\end{equation*}
Display
(︀𝑛)︀
𝑃 (𝐸) = 𝑘 𝑝𝑘 (1 − 𝑝)𝑛−𝑘
Source
\begin{equation*}
\frac{1}{\Bigl(\sqrt{\phi \sqrt{5}}-\phi\Bigr) e^{\frac25 \pi}} =
1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}}
{1+\frac{e^{-8\pi}} {1+\ldots} } } }
\end{equation*}
Display
1 )︁ 𝑒−2𝜋
(︁√
√
=1+ 𝑒−4𝜋
2 1+
𝜑 5−𝜑 𝑒 5 𝜋 1+ 𝑒−6𝜋
−8𝜋
1+ 𝑒
1+...
Source
\begin{equation*}
1 + \frac{q^2}{(1-q)}+\frac{q^6}{(1-q)(1-q^2)}+\cdots =
\prod_{j=0}^{\infty}\frac{1}{(1-q^{5j+2})(1-q^{5j+3})},
\quad\quad \text{for $|q|<1$}.
\end{equation*}
Display
∞
𝑞2 𝑞6 ∏︁ 1
1+ + + · · · = , for |𝑞| < 1.
(1 − 𝑞) (1 − 𝑞)(1 − 𝑞 2 ) 𝑗=0
(1 − 𝑞 5𝑗+2 )(1 − 𝑞 5𝑗+3 )
Source
\begin{align}
\nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t}␣
˓→& = \frac{4\pi}{c}\vec{\mathbf{j}} \\ \nabla \cdot \vec{\mathbf{E}} & = 4 \pi \rho \\
\nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial␣
˓→t} & = \vec{\mathbf{0}} \\
Display
Equation numbering and referencing will be available in a future version of the Jupyter notebook.
While display equations look good for a page of samples, the ability to mix math and formatted text in a paragraph is
also important.
Source
Display
√
This expression 3𝑥 − 1 + (1 + 𝑥)2 is an example of a TeX inline equation in a Markdown-formatted sentence.
You will notice in other places on the web that $$ are needed explicitly to begin and end MathJax typesetting. This
is not required if you will be using TeX environments, but the Jupyter notebook will accept this syntax on legacy
notebooks.
3.10.11 Source
$$
\begin{array}{c}
y_1 \\\
y_2 \mathtt{t}_i \\\
z_{3,4}
\end{array}
$$
$$
\begin{array}{c}
y_1 \cr
y_2 \mathtt{t}_i \cr
y_{3}
\end{array}
$$
$$\begin{eqnarray}
x' &=& &x \sin\phi &+& z \cos\phi \\
z' &=& - &x \cos\phi &+& z \sin\phi \\
\end{eqnarray}$$
$$
x=4
$$
3.10.12 Display
𝑦1
𝑦2 t𝑖
𝑧3,4
𝑦1
𝑦2 t𝑖
𝑦3
𝑡𝑜
𝑥′ =
𝑥 sin 𝜑
+𝑧 cos 𝜑
𝑧′ =
−𝑥 cos 𝜑
+𝑧 sin 𝜑
(3.2)
+
-=
+𝑥 cos 𝜑
𝑧 sin 𝜑
𝑥=4
FOUR
First, have a look at the common problems listed below. If you can figure it out from these notes, it will be quicker than
asking for help.
Check that you have the latest version of any packages that look relevant. Unfortunately it’s not always easy to figure
out what packages are relevant, but if there was a bug that’s already been fixed, it’s easy to upgrade and get on with
what you wanted to do.
• Try in another browser (e.g. if you normally use Firefox, try with Chrome). This helps pin down where the
problem is.
• Try disabling any browser extensions and/or any Jupyter extensions you have installed.
• Some internet security software can interfere with Jupyter. If you have security software, try turning it off
temporarily, and look in the settings for a more long-term solution.
• In the address bar, try changing between localhost and 127.0.0.1. They should be the same, but in some
cases it makes a difference.
57
Jupyter Notebook Documentation, Release 6.4.5
Files called kernel specs tell Jupyter how to start different kinds of kernels. To see where these are on your system, run
jupyter kernelspec list:
There’s a special fallback for the Python kernel: if it doesn’t find a real kernelspec, but it can import the ipykernel
package, it provides a kernel which will run in the same Python environment as the notebook server. A path ending
in ipykernel/resources, like in the example above, is this default kernel. The default often does what you want,
so if the python3 kernelspec points somewhere else and you can’t start a Python kernel, try deleting or renaming that
kernelspec folder to expose the default.
If your problem is with another kernel, not the Python one we maintain, you may need to look for support about that
kernel.
Multiple python environments, whether based on Anaconda or Python Virtual environments, are often the source of
reported issues. In many cases, these issues stem from the Notebook server running in one environment, while the
kernel and/or its resources, derive from another environment. Indicators of this scenario include:
• import statements within code cells producing ImportError or ModuleNotFound exceptions.
• General kernel startup failures exhibited by nothing happening when attempting to execute a cell.
In these situations, take a close look at your environment structure and ensure all packages required by your note-
book’s code are installed in the correct environment. If you need to run the kernel from different environments than
your Notebook server, check out IPython’s documentation for using kernels from different environments as this is the
recommended approach. Anaconda’s nb_conda_kernels package might also be an option for you in these scenarios.
Another thing to check is the kernel.json file that will be located in the aforementioned kernel specs directory
identified by running jupyter kernelspec list. This file will contain an argv stanza that includes the actual
command to run when launching the kernel. Oftentimes, when reinstalling python environments, a previous kernel.
json will reference an python executable from an old or non-existent location. As a result, it’s always a good idea when
encountering kernel startup issues to validate the argv stanza to ensure all file references exist and are appropriate.
Although Jupyter Notebook is primarily developed on the various flavors of the Unix operating system it also supports
Microsoft Windows - which introduces its own set of commonly encountered issues, particularly in the areas of security,
process management and lower-level libraries.
File "c:\users\jovyan\python\myenv.venv\lib\site-packages\jupyter_core\paths.py",␣
˓→line 424, in secure_write
win32_restrict_file_to_user(fname)
File "c:\users\jovyan\python\myenv.venv\lib\site-packages\jupyter_core\paths.py",␣
˓→line 359, in win32_restrict_file_to_user
import win32api
ImportError: DLL load failed: The specified module could not be found.
• As noted earlier, the installation of pywin32 can be problematic on Windows configurations. When such an
issue occurs, you may need to revisit how the environment was setup. Pay careful attention to whether you’re
running the 32 or 64 bit versions of Windows and be sure to install appropriate packages for that environment.
Here’s a portion of such a traceback:
File "C:\Users\jovyan\AppData\Roaming\Python\Python37\site-packages\jupyter_core\
˓→paths.py", line 435, in secure_write
win32_restrict_file_to_user(fname)
File "C:\Users\jovyan\AppData\Roaming\Python\Python37\site-packages\jupyter_core\
˓→paths.py", line 361, in win32_restrict_file_to_user
import win32api
ImportError: DLL load failed: %1 is not a valid Win32 application
In this case, your pywin32 module may not be installed correctly and the following should be attempted:
or:
followed by:
The Jupyter stack is very complex and rightfully so, there’s a lot going on. On occassion you might find the system
working perfectly well, then, suddenly, you can’t get past a certain cell due to import failures. In these situations, it’s
best to ask yourself if any new python files were added to your notebook development area.
These issues are usually evident by carefully analyzing the traceback produced in the notebook error or the Notebook
server’s command window. In these cases, you’ll typically find the Python kernel code (from IPython and ipykernel)
performing its imports and notice a file from your Notebook development error included in that traceback followed by
an AttributeError:
What has happened is that you have named a file that conflicts with an installed package that is used by the kernel
software and now introduces a conflict preventing the kernel’s startup.
Resolution: You’ll need to rename your file. A best practice would be to prefix or namespace your files so as not to
conflict with any python package.
As with any problem, try searching to see if someone has already found an answer. If you can’t find an existing answer,
you can ask questions at:
• The Jupyter Discourse Forum
• The jupyter-notebook tag on Stackoverflow
• Peruse the jupyter/help repository on Github (read-only)
• Or in an issue on another repository, if it’s clear which component is responsible. Typical repositories include:
– jupyter_core - secure_write() and file path issues
– jupyter_client - kernel management issues found in Notebook server’s command window.
– IPython and ipykernel - kernel runtime issues typically found in Notebook server’s command window
and/or Notebook cell execution.
Should you find that your problem warrants that an issue be opened in notebook please don’t forget to provide details
like the following:
• What error messages do you see (within your notebook and, more importantly, in the Notebook server’s command
window)?
• What platform are you on?
• How did you install Jupyter?
• What have you tried already?
The jupyter troubleshoot command collects a lot of information about your installation, which can also be useful.
When providing textual information, it’s most helpful if you can scrape the contents into the issue rather than providing
a screenshot. This enables others to select pieces of that content so they can search more efficiently and try to help.
Remember that it’s not anyone’s job to help you. We want Jupyter to work for you, but we can’t always help everyone
individually.
FIVE
CHANGELOG
A summary of changes in the Jupyter notebook. For more detailed information, see GitHub.
Use pip install notebook --upgrade or conda upgrade notebook to upgrade to the latest release.
We strongly recommend that you upgrade pip to version 9+ of pip before upgrading notebook.
Use pip install pip --upgrade to upgrade pip. Check pip version with pip --version.
5.1 6.4.5
(Full Changelog)
63
Jupyter Notebook Documentation, Release 6.4.5
5.2 6.4.4
(Full Changelog)
• Use default JupyterLab CSS sanitizer options for Markdown #6160 (@krassowski)
• Fix syntax highlight #6128 (@massongit)
5.3 6.4.3
(Full Changelog)
64 Chapter 5. Changelog
Jupyter Notebook Documentation, Release 6.4.5
5.4 6.4.2
(Full Changelog)
5.5 6.4.0
(Full Changelog)
5.4. 6.4.2 65
Jupyter Notebook Documentation, Release 6.4.5
• Revert “do not apply asyncio patch for tornado >=6.1” #6052 (@minrk)
• Use Jupyter Releaser #6048 (@afshin)
• Add Workflow Permissions for Lock Bot #6042 (@jtpio)
• Fixes related to the recent changes in the documentation #6021 (@frenzymadness)
• Add maths checks in CSS reference test #6035 (@stef4k)
• Add Issue Lock and Answered Bots #6019 (@afshin)
5.6 6.3.0
66 Chapter 5. Changelog
Jupyter Notebook Documentation, Release 6.4.5
5.7 6.2.0
5.9 6.1.6
5.7. 6.2.0 67
Jupyter Notebook Documentation, Release 6.4.5
5.11 6.1.5
5.12 6.1.4
5.13 6.1.3
68 Chapter 5. Changelog
Jupyter Notebook Documentation, Release 6.4.5
5.14 6.1.2
5.15 6.1.1
5.16 6.1.0
Please note that this repository is currently maintained by a skeleton crew of maintainers from the Jupyter community.
For our approach moving forward, please see this notice from the README. Thank you.
Here is an enumeration of changes made since the last release and included in 6.1.0.
• Remove deprecated encoding parameter for Python 3.9 compatibility. (5174)
• Add support for async kernel management (4479)
• Fix typo in password_required help message (5320)
• Gateway only: Ensure launch and request timeouts are in sync (5317)
• Update Markdown Cells example to HTML5 video tag (5411)
• Integrated LoginWidget into edit to enable users to logout from the t. . . (5406)
• Update message about minimum Tornado version (5222)
• Logged notebook type (5425)
• Added nl language (5354)
• Add UNIX socket support to notebook server. (4835)
• Update CodeMirror dependency (5198)
• Tree added download multiple files (5351)
• Toolbar buttons tooltip: show help instead of label (5107)
• Remove unnecessary import of requests_unixsocket (5451)
• Add ability to cull terminals and track last activity (5372)
• Code refactoring notebook.js (5352)
5.14. 6.1.2 69
Jupyter Notebook Documentation, Release 6.4.5
70 Chapter 5. Changelog
Jupyter Notebook Documentation, Release 6.4.5
5.16. 6.1.0 71
Jupyter Notebook Documentation, Release 6.4.5
• Kenichi Ito
• Kevin Bates
• Koki Nishihara
• Kris Wilson
• Kyle Kelley
• Laura Merlo
• levinxo
• Luciano Resende
• Luis Cabezon Manchado
• Madhusudhan Srinivasa
• Matthias Geier
• mattn
• Max Klein
• Min RK
• Mingxuan Lin
• Mohammad Mostafa Farzan
• Niko Felger
• Norah Abanumay
• Onno Broekmans
• PierreMB
• pinarkavak
• Ram Rachum
• Reece Hart
• Remi Rampin
• Rohit Sanjay
• Shane Canon
• Simon Li
• Steinar Sturlaugsson
• Steven Silvester
• taohan16
• Thew Dhanat
• Thomas Kluyver
• Toon Baeyens
• Vidar Tonaas Fauske
• Zachary Sailer
72 Chapter 5. Changelog
Jupyter Notebook Documentation, Release 6.4.5
5.17 6.0.3
5.18 6.0.2
5.17. 6.0.3 73
Jupyter Notebook Documentation, Release 6.4.5
• Sasaki Takeru
• Tom Jarosz
• Vidar Tonaas Fauske
• Wes Turner
• Zachary Sailer
5.19 6.0.1
5.20 6.0
This is the first major release of the Jupyter Notebook since version 5.0 (March 2017).
We encourage users to start trying JupyterLab, which has just announced it’s 1.0 release in preparation for a future
transition.
• Remove Python 2.x support in favor of Python 3.5 and higher.
• Multiple accessibility enhancements and bug-fixes.
• Multiple translation enhancements and bug-fixes.
• Remove deprecated ANSI CSS styles.
• Native support to forward requests to Jupyter Gateway(s) (Embedded NB2KG).
• Use JavaScript to redirect users to notebook homepage.
• Enhanced SSL/TLS security by using PROTOCOL_TLS which selects the highest ssl/tls protocol version avail-
able that both the client and server support. When PROTOCOL_TLS is not available use PROTOCOL_SSLv23.
• Add ?no_track_activity=1 argument to allow API requests. to not be registered as activity (e.g. API calls
by external activity monitors).
• Kernels shutting down due to an idle timeout is no longer considered an activity-updating event.
• Further improve compatibility with tornado 6 with improved checks for when websockets are closed.
• Launch the browser with a local file which redirects to the server address including the authentication token. This
prevents another logged-in user from stealing the token from command line arguments and authenticating to the
server. The single-use token previously used to mitigate this has been removed. Thanks to Dr. Owain Kenway
for suggesting the local file approach.
• Respect nbconvert entrypoints as sources for exporters
• Update to CodeMirror to 5.37, which includes f-string syntax for Python 3.6.
• Update jquery-ui to 1.12
• Execute cells by clicking icon in input prompt.
74 Chapter 5. Changelog
Jupyter Notebook Documentation, Release 6.4.5
5.20. 6.0 75
Jupyter Notebook Documentation, Release 6.4.5
• Anastasis Germanidis
• Andrés Sánchez
• Arjun Radhakrishna
• Arovit Narula
• Benda Xu
• Björn Grüning
• Brian E. Granger
• Carol Willing
• Celina Kilcrease
• Chris Holdgraf
• Chris Miller
• Ciaran Langton
• Damian Avila
• Dana Lee
• Daniel Farrell
• Daniel Nicolai
• Darío Hereñú
• Dave Aitken
• Dave Foster
• Dave Hirschfeld
• Denis Ledoux
• Dmitry Mikushin
• Dominic Kuang
• Douglas Hanley
• Elliott Sales de Andrade
• Emilio Talamante Lugo
• Eric Perry
• Ethan T. Hendrix
• Evan Van Dam
• Francesco Franchina
• Frédéric Chapoton
• Félix-Antoine Fortin
• Gabriel
• Gabriel Nützi
• Gabriel Ruiz
• Gestalt LUR
76 Chapter 5. Changelog
Jupyter Notebook Documentation, Release 6.4.5
• Grant Nestor
• Gustavo Efeiche
• Harsh Vardhan
• Heng GAO
• Hisham Elsheshtawy
• Hong Xu
• Ian Rose
• Ivan Ogasawara
• J Forde
• Jason Grout
• Jessica B. Hamrick
• Jiaqi Liu
• John Emmons
• Josh Barnes
• Karthik Balakrishnan
• Kevin Bates
• Kirit Thadaka
• Kristian Gregorius Hustad
• Kyle Kelley
• Leo Gallucci
• Lilian Besson
• Lucas Seiki Oshiro
• Luciano Resende
• Luis Angel Rodriguez Guerrero
• M Pacer
• Maarten Breddels
• Mac Knight
• Madicken Munk
• Maitiú Ó Ciaráin
• Marc Udoff
• Mathis HAMMEL
• Mathis Rosenhauer
• Matthias Bussonnier
• Matthias Geier
• Max Vovshin
• Maxime Mouchet
5.20. 6.0 77
Jupyter Notebook Documentation, Release 6.4.5
• Michael Chirico
• Michael Droettboom
• Michael Heilman
• Michael Scott Cuthbert
• Michal Charemza
• Mike Boyle
• Milos Miljkovic
• Min RK
• Miro Hrončok
• Nicholas Bollweg
• Nitesh Sawant
• Ondrej Jariabka
• Park Hae Jin
• Paul Ivanov
• Paul Masson
• Peter Parente
• Pierre Tholoniat
• Remco Verhoef
• Roland Weber
• Roman Kornev
• Rosa Swaby
• Roy Hyunjin Han
• Sally
• Sam Lau
• Samar Sultan
• Shiti Saxena
• Simon Biggs
• Spencer Park
• Stephen Ward
• Steve (Gadget) Barnes
• Steven Silvester
• Surya Prakash Susarla
• Syed Shah
• Sylvain Corlay
• Thomas Aarholt
• Thomas Kluyver
78 Chapter 5. Changelog
Jupyter Notebook Documentation, Release 6.4.5
• Tim
• Tim Head
• Tim Klever
• Tim Metzler
• Todd
• Tom Jorquera
• Tyler Makaro
• Vaibhav Sagar
• Victor
• Vidar Tonaas Fauske
• Vu Minh Tam
• Vít Tuček
• Will Costello
• Will Starms
• William Hosford
• Xiaohan Li
• Yuvi Panda
• ashley teoh
• nullptr
5.21 5.7.8
• Fix regression in restarting kernels in 5.7.5. The restart handler would return before restart was completed.
• Further improve compatibility with tornado 6 with improved checks for when websockets are closed.
• Fix regression in 5.7.6 on Windows where .js files could have the wrong mime-type.
• Fix Open Redirect vulnerability (CVE-2019-10255) where certain malicious URLs could redirect from the
Jupyter login page to a malicious site after a successful login. 5.7.7 contained only a partial fix for this issue.
5.22 5.7.6
5.7.6 contains a security fix for a cross-site inclusion (XSSI) vulnerability (CVE-2019–9644), where files at a known
URL could be included in a page from an unauthorized website if the user is logged into a Jupyter server. The fix
involves setting the X-Content-Type-Options: nosniff header, and applying CSRF checks previously on all non-
GET API requests to GET requests to API endpoints and the /files/ endpoint.
The attacking page is able to access some contents of files when using Internet Explorer through script errors, but this
has not been demonstrated with other browsers.
5.21. 5.7.8 79
Jupyter Notebook Documentation, Release 6.4.5
5.23 5.7.5
5.24 5.7.4
5.7.4 fixes a bug introduced in 5.7.3, in which the list_running_servers() function attempts to parse HTML files
as JSON, and consequently crashes (4284).
5.25 5.7.3
5.26 5.7.2
5.7.2 contains a security fix preventing malicious directory names from being able to execute javascript. CVE request
pending.
5.27 5.7.1
5.7.1 contains a security fix preventing nbconvert endpoints from executing javascript with access to the server API.
CVE request pending.
5.28 5.7.0
New features:
• Update to CodeMirror to 5.37, which includes f-string syntax for Python 3.6 (3816)
• Update jquery-ui to 1.12 (3836)
• Check Host header to more securely protect localhost deployments from DNS rebinding. This is a pre-
emptive measure, not fixing a known vulnerability (3766). Use .NotebookApp.allow_remote_access and
.NotebookApp.local_hostnames to configure access.
• Allow access-control-allow-headers to be overridden (3886)
• Allow configuring max_body_size and max_buffer_size (3829)
80 Chapter 5. Changelog
Jupyter Notebook Documentation, Release 6.4.5
5.28. 5.7.0 81
Jupyter Notebook Documentation, Release 6.4.5
5.29 5.6.0
New features:
• Execute cells by clicking icon in input prompt (3535, 3687)
• New “Save as” menu option (3289)
• When serving on a loopback interface, protect against DNS rebinding by checking the Host header from the
browser (3714). This check can be disabled if necessary by setting NotebookApp.allow_remote_access.
(Disabled by default while we work out some Mac issues in 3754).
• Add kernel_info_timeout traitlet to enable restarting slow kernels (3665)
• Add custom_display_host config option to override displayed URL (3668)
• Add /metrics endpoint for Prometheus Metrics (3490)
• Update to MathJax 2.7.4 (3751)
• Update to jQuery 3.3 (3655)
• Update marked to 0.4 (3686)
Fixing problems:
• Don’t duplicate token in displayed URL (3656)
• Clarify displayed URL when listening on all interfaces (3703)
• Don’t trash non-empty directories on Windows (3673)
• Include LICENSE file in wheels (3671)
• Don’t show “0 active kernels” when starting the notebook (3696)
Testing:
• Add find replace test (3630)
• Selenium test for deleting all cells (3601)
• Make creating a new notebook more robust (3726)
Thanks to the following contributors:
• Arovit Narula (arovit)
• lucasoshiro (lucasoshiro)
• M Pacer (mpacer)
• Thomas Kluyver (takluyver)
• Todd (toddrme2178)
• Yuvi Panda (yuvipanda)
See the 5.6 milestone on GitHub for a complete list of pull requests involved in this release.
82 Chapter 5. Changelog
Jupyter Notebook Documentation, Release 6.4.5
5.30 5.5.0
New features:
• The files list now shows file sizes (3539)
• Add a quit button in the dashboard (3004)
• Display hostname in the terminal when running remotely (3356, 3593)
• Add slides exportation/download to the menu (3287)
• Add any extra installed nbconvert exporters to the “Download as” menu (3323)
• Editor: warning when overwriting a file that is modified on disk (2783)
• Display a warning message if cookies are not enabled (3511)
• Basic __version__ reporting for extensions (3541)
• Add NotebookApp.terminals_enabled config option (3478)
• Make buffer time between last modified on disk and last modified on last save configurable (3273)
• Allow binding custom shortcuts for ‘close and halt’ (3314)
• Add description for ‘Trusted’ notification (3386)
• Add settings['activity_sources'] (3401)
• Add an output_updated.OutputArea event (3560)
Fixing problems:
• Fixes to improve web accessibility (3507)
• Fixed color contrast issue in tree.less (3336)
• Allow cancelling upload of large files (3373)
• Don’t clear login cookie on requests without cookie (3380)
• Don’t trash files on different device to home dir on Linux (3304)
• Clear waiting asterisks when restarting kernel (3494)
• Fix output prompt when execution_count missing (3236)
• Make the ‘changed on disk’ dialog work when displayed twice (3589)
• Fix going back to root directory with history in notebook list (3411)
• Allow defining keyboard shortcuts for missing actions (3561)
• Prevent default on pageup/pagedown when completer is active (3500)
• Prevent default event handling on new terminal (3497)
• ConfigManager should not write out default values found in the .d directory (3485)
• Fix leak of iopub object in activity monitoring (3424)
• Javascript lint in notebooklist.js (3409)
• Some Javascript syntax fixes (3294)
• Convert native for loop to Array.forEach() (3477)
• Disable cache when downloading nbconvert output (3484)
5.30. 5.5.0 83
Jupyter Notebook Documentation, Release 6.4.5
84 Chapter 5. Changelog
Jupyter Notebook Documentation, Release 6.4.5
5.30. 5.5.0 85
Jupyter Notebook Documentation, Release 6.4.5
5.31 5.4.1
5.32 5.4.0
• Fix creating files and folders after navigating directories in the dashboard (3264).
• Enable printing notebooks in colour, removing the CSS that made everything black and white (3212).
• Limit the completion options displayed in the notebook to 1000, to avoid performance issues with very long lists
(3195).
• Accessibility improvements in tree.html (3271).
• Added alt-text to the kernel logo image in the notebook UI (3228).
• Added a test on Travis CI to flag if symlinks are accidentally introduced in the future. This should prevent the
issue that necessitated release-5.3.1{.interpreted-text role=”ref”} (3227).
• Use lowercase letters for random IDs generated in our Javascript (3264).
• Removed duplicate code setting TextCell.notebook (3256).
Thanks to the following contributors:
• Alex Soderman (asoderman)
• Matthias Bussonnier (Carreau)
• Min RK (minrk)
• Nitesh Sawant (ns23)
• Thomas Kluyver (takluyver)
• Yuvi Panda (yuvipanda)
See the 5.4 milestone on GitHub for a complete list of pull requests involved in this release.
86 Chapter 5. Changelog
Jupyter Notebook Documentation, Release 6.4.5
5.33 5.3.1
Replaced a symlink in the repository with a copy, to fix issues installing on Windows (3220).
5.34 5.3.0
This release introduces a couple noteable improvements, such as terminal support for Windows and support for OS
trash (files deleted from the notebook dashboard are moved to the OS trash vs. deleted permanently).
• Add support for terminals on windows (3087).
• Add a “restart and run all” button to the toolbar (2965).
• Send files to os trash mechanism on delete (1968).
• Allow programmatic copy to clipboard (3088).
• Use DOM History API for navigating between directories in the file browser (3115).
• Add translated files to folder(docs-translations) (3065).
• Allow non empty dirs to be deleted (3108).
• Set cookie on base_url (2959).
• Allow token-authenticated requests cross-origin by default (2920).
• Change cull_idle_timeout_minimum to 1 from 300 (2910).
• Config option to shut down server after n seconds with no kernels (2963).
• Display a “close” button on load notebook error (3176).
• Add action to command pallette to run CodeMirror’s “indentAuto” on selection (3175).
• Add option to specify extra services (3158).
• Warn_bad_name should not use global name (3160).
• Avoid overflow of hidden form (3148).
• Fix shutdown trans loss (3147).
• Find available kernelspecs more efficiently (3136).
• Don’t try to translate missing help strings (3122).
• Frontend/extension-config: allow default json files in a .d directory (3116).
• Use [requirejs]{.title-ref} vs. [require]{.title-ref} (3097).
• Fixes some ui bugs in firefox #3044 (3058).
• Compare non-specific language code when choosing to use arabic numerals (3055).
• Fix save-script deprecation (3053).
• Include moment locales in package_data (3051).
• Fix moment locale loading in bidi support (3048).
• Tornado 5: periodiccallback loop arg will be removed (3034).
• Use [/files]{.title-ref} prefix for pdf-like files (3031).
• Add folder for document translation (3022).
5.33. 5.3.1 87
Jupyter Notebook Documentation, Release 6.4.5
• When login-in via token, let a chance for user to set the password (3008).
• Switch to jupyter_core implementation of ensure_dir_exists (3002).
• Send http shutdown request on ‘stop’ subcommand (3000).
• Work on loading ui translations (2969).
• Fix ansi inverse (2967).
• Add send2trash to requirements for building docs (2964).
• I18n readme.md improvement (2962).
• Add ‘reason’ field to json error responses (2958).
• Add some padding for stream outputs (3194).
• Always use setuptools in setup.py (3206).
• Fix clearing cookies on logout when base_url is configured (3207).
Thanks to the following contributors:
• bacboc (bacboc)
• Steven Silvester (blink1073)
• Matthias Bussonnier (Carreau)
• ChungJooHo (ChungJooHo)
• edida (edida)
• Francesco Franchina (ferdas)
• forbxy (forbxy)
• Grant Nestor (gnestor)
• Josh Barnes (jcb91)
• JocelynDelalande (JocelynDelalande)
• Karthik Balakrishnan (karthikb351)
• Kevin Bates (kevin-bates)
• Kirit Thadaka (kirit93)
• Lilian Besson (Naereen)
• Maarten Breddels (maartenbreddels)
• Madhu94 (Madhu94)
• Matthias Geier (mgeier)
• Michael Heilman (mheilman)
• Min RK (minrk)
• PHaeJin (PHaeJin)
• Sukneet (Sukneet)
• Thomas Kluyver (takluyver)
See the 5.3 milestone on GitHub for a complete list of pull requests involved in this release.
88 Chapter 5. Changelog
Jupyter Notebook Documentation, Release 6.4.5
5.35 5.2.1
5.36 5.2.0
5.35. 5.2.1 89
Jupyter Notebook Documentation, Release 6.4.5
• Changed all python variables named file to file_name to not override built_in file (2830).
• Add more doc tests (2823).
• Typos fix (2815).
• Rename and update license [ci skip] (2810).
• Travis builds doc (2808).
• Pull request i18n (2804).
• Factor out output_prompt_function, as is done with input prompt (2774).
• Use rfc5987 encoding for filenames (2767).
• Added path to the resources metadata, the same as in from_filename(. . . ) in nbconvert.exporters.py (2753).
• Make “extrakeys” consistent for notebook and editor (2745).
• Bidi support (2357).
Special thanks to samarsultan and the Arabic Competence and Globalization Center Team at IBM Egypt for adding
RTL (right-to-left) support to the notebook!
See the 5.2 milestone on GitHub for a complete list of issues and pull requests involved in this release.
5.37 5.1.0
90 Chapter 5. Changelog
Jupyter Notebook Documentation, Release 6.4.5
5.38 5.0.0
This is the first major release of the Jupyter Notebook since version 4.0 was created by the “Big Split” of IPython and
Jupyter.
We encourage users to start trying JupyterLab in preparation for a future transition.
We have merged more than 300 pull requests since 4.0. Some of the major user-facing changes are described here.
Files in the dashboard may now be sorted by last modified date or name (943):
5.38. 5.0.0 91
Jupyter Notebook Documentation, Release 6.4.5
Cell tags are a lightweight way to customise the behaviour of tools working with notebooks; we’re working on building
support for them into tools like nbconvert and nbval. To start using tags, select Tags in the View > Cell Toolbar
menu in a notebook.
The UI for editing cell tags is basic for now; we hope to improve it in future releases.
The default styling for tables in the notebook has been updated (1776).
Before:
After:
You can now edit keyboard shortcuts for Command Mode within the UI (1347):
92 Chapter 5. Changelog
Jupyter Notebook Documentation, Release 6.4.5
See the Help > Edit Keyboard Shortcuts menu item and follow the instructions.
• You can copy and paste cells between notebooks, using Ctrl-C{.interpreted-text role=”kbd”} and
Ctrl-V{.interpreted-text role=”kbd”} (Cmd-C{.interpreted-text role=”kbd”} and Cmd-V{.interpreted-text
role=”kbd”} on Mac).
• It’s easier to configure a password for the notebook with the new jupyter notebook password command
(2007).
• The file list can now be ordered by last modified or by name (943).
• Markdown cells now support attachments. Simply drag and drop an image from your desktop to a markdown
cell to add it. Unlike relative links that you enter manually, attachments are embedded in the notebook itself. An
unreferenced attachment will be automatically scrubbed from the notebook on save (621).
• Undoing cell deletion now supports undeleting multiple cells. Cells may not be in the same order as before their
deletion, depending on the actions you did on the meantime, but this should should help reduce the impact of
accidentally deleting code.
• The file browser now has Edit and View buttons.
• The file browser now supports moving multiple files at once (1088).
• The Notebook will refuse to run as root unless the --allow-root flag is given (1115).
• Keyboard shortcuts are now declarative (1234).
• Toggling line numbers can now affect all cells (1312).
5.38. 5.0.0 93
Jupyter Notebook Documentation, Release 6.4.5
5.39 4.4.0
• Allow override of output callbacks to redirect output messages. This is used to implement the ipywidgets Output
widget, for example.
• Fix an async bug in message handling by allowing comm message handlers to return a promise which halts
message processing until the promise resolves.
See the 4.4 milestone on GitHub for a complete list of issues and pull requests involved in this release.
5.40 4.3.2
4.3.2 is a patch release with a bug fix for CodeMirror and improved handling of the “editable” cell metadata field.
• Monkey-patch for CodeMirror that resolves #2037 without breaking #1967
• Read-only ("editable": false) cells can be executed but cannot be split, merged, or deleted
See the 4.3.2 milestone on GitHub for a complete list of issues and pull requests involved in this release.
5.41 4.3.1
4.3.1 is a patch release with a security patch, a couple bug fixes, and improvements to the newly-released token authen-
tication.
Security fix:
• CVE-2016-9971. Fix CSRF vulnerability, where malicious forms could create untitled files and start kernels
(no remote execution or modification of existing files) for users of certain browsers (Firefox, Internet Explorer /
Edge). All previous notebook releases are affected.
Bug fixes:
• Fix carriage return handling
• Make the font size more robust against fickle browsers
• Ignore resize events that bubbled up and didn’t come from window
• Add Authorization to allowed CORS headers
• Downgrade CodeMirror to 5.16 while we figure out issues in Safari
94 Chapter 5. Changelog
Jupyter Notebook Documentation, Release 6.4.5
Other improvements:
• Better docs for token-based authentication
• Further highlight token info in log output when autogenerated
See the 4.3.1 milestone on GitHub for a complete list of issues and pull requests involved in this release.
5.42 4.3.0
4.3 is a minor release with many bug fixes and improvements. The biggest user-facing change is the addition of token
authentication, which is enabled by default. A token is generated and used when your browser is opened automatically,
so you shouldn’t have to enter anything in the default circumstances. If you see a login page (e.g. by switching browsers,
or launching on a new port with --no-browser), you get a login URL with the token from the command jupyter
notebook list, which you can paste into your browser.
Highlights:
• API for creating mime-type based renderer extensions using OutputArea.register_mime_type and
Notebook.render_cell_output methods. See mimerender-cookiecutter for reference implementations and
cookiecutter.
• Enable token authentication by default. See server_security{.interpreted-text role=”ref”} for more details.
• Update security docs to reflect new signature system
• Switched from term.js to xterm.js
Bug fixes:
• Ensure variable is set if exc_info is falsey
• Catch and log handler exceptions in events.trigger
• Add debug log for static file paths
• Don’t check origin on token-authenticated requests
• Remove leftover print statement
• Fix highlighting of Python code blocks
• json_errors should be outermost decorator on API handlers
• Fix remove old nbserver info files
• Fix notebook mime type on download links
• Fix carriage symbol behavior
• Fix terminal styles
• Update dead links in docs
• If kernel is broken, start a new session
• Include cross-origin check when allowing login URL redirects
Other improvements:
• Allow JSON output data with mime type application/*+json
• Allow kernelspecs to have spaces in them for backward compat
• Allow websocket connections from scripts
5.42. 4.3.0 95
Jupyter Notebook Documentation, Release 6.4.5
5.43 4.2.3
5.44 4.2.2
4.2.2 is a small bugfix release on 4.2, with an important security fix. All users are strongly encouraged to upgrade to
4.2.2.
Highlights:
• Security fix: CVE-2016-6524, where untrusted latex output could be added to the page in a way that could
execute javascript.
• Fix missing POST in OPTIONS responses.
• Fix for downloading non-ascii filenames.
• Avoid clobbering ssl_options, so that users can specify more detailed SSL configuration.
• Fix inverted load order in nbconfig, so user config has highest priority.
• Improved error messages here and there.
96 Chapter 5. Changelog
Jupyter Notebook Documentation, Release 6.4.5
5.45 4.2.1
5.46 4.2.0
Release 4.2 adds a new API for enabling and installing extensions. Extensions can now be enabled at the system-level,
rather than just per-user. An API is defined for installing directly from a Python package, as well.
Highlighted changes:
• Upgrade MathJax to 2.6 to fix vertical-bar appearing on some equations.
• Restore ability for notebook directory to be root (4.1 regression)
• Large outputs are now throttled, reducing the ability of output floods to kill the browser.
• Fix the notebook ignoring cell executions while a kernel is starting by queueing the messages.
• Fix handling of url prefixes (e.g. JupyterHub) in terminal and edit pages.
• Support nested SVGs in output.
And various other fixes and improvements.
5.47 4.1.0
Bug fixes:
• Properly reap zombie subprocesses
• Fix cross-origin problems
• Fix double-escaping of the base URL prefix
• Handle invalid unicode filenames more gracefully
• Fix ANSI color-processing
• Send keepalive messages for web terminals
• Fix bugs in the notebook tour
UI changes:
• Moved the cell toolbar selector into the View menu. Added a button that triggers a “hint” animation to the main
toolbar so users can find the new location. (Click here to see a screencast )
5.45. 4.2.1 97
Jupyter Notebook Documentation, Release 6.4.5
• Added Restart & Run All to the Kernel menu. Users can also bind it to a keyboard shortcut on action
restart-kernel-and-run-all-cells.
• Added multiple-cell selection. Users press Shift-Up/Down or Shift-K/J to extend selection in command
mode. Various actions such as cut/copy/paste, execute, and cell type conversions apply to all selected cells.
• Added a command palette for executing Jupyter actions by name. Users press Cmd/Ctrl-Shift-P or click the
new command palette icon on the toolbar.
98 Chapter 5. Changelog
Jupyter Notebook Documentation, Release 6.4.5
• Added a Find and Replace dialog to the Edit menu. Users can also press F in command mode to show the dialog.
Other improvements:
• Custom KernelManager methods can be Tornado coroutines, allowing async operations.
• Make clearing output optional when rewriting input with set_next_input(replace=True).
• Added support for TLS client authentication via --NotebookApp.client-ca.
• Added tags to jupyter/notebook releases on DockerHub. latest continues to track the master branch.
See the 4.1 milestone on GitHub for a complete list of issues and pull requests handled.
5.48 4.0.x
5.48.1 4.0.6
5.48. 4.0.x 99
Jupyter Notebook Documentation, Release 6.4.5
5.48.2 4.0.5
5.48.3 4.0.4
5.48.4 4.0.2
5.48.5 4.0.0
SIX
COMMS
Comms allow custom messages between the frontend and the kernel. They are used, for instance, in ipywidgets to
update widget state.
A comm consists of a pair of objects, in the kernel and the frontend, with an automatically assigned unique ID. When
one side sends a message, a callback on the other side is triggered with that message data. Either side, the frontend or
kernel, can open or close the comm.
See also:
Custom Messages The messaging specification section on comms
First, the function to accept the comm must be available on the frontend. This can either be specified in a requirejs
module, or registered in a registry, for example when an extension is loaded. This example shows a frontend comm
target registered in a registry:
Jupyter.notebook.kernel.comm_manager.register_target('my_comm_target',
function(comm, msg) {
// comm is the frontend comm instance
// msg is the comm_open message, which can carry data
Now that the frontend comm is registered, you can open the comm from the kernel:
101
Jupyter Notebook Documentation, Release 6.4.5
This example uses the IPython kernel; it’s up to each language kernel what API, if any, it offers for using comms.
This is very similar to above, but in reverse. First, a comm target must be registered in the kernel. For instance, this may
be done by code displaying output: it will register a target in the kernel, and then display output containing Javascript
to connect to it.
get_ipython().kernel.comm_manager.register_target('my_comm_target', target_func)
This example uses the IPython kernel again; this example will be different in other kernels that support comms. Refer
to the specific language kernel’s documentation for comms support.
And then open the comm from the frontend:
// Register a handler
comm.on_msg(function(msg) {
console.log(msg.content.data.foo);
});
SEVEN
CONFIGURATION OVERVIEW
Beyond the default configuration settings, you can configure a rich array of options to suit your workflow. Here are
areas that are commonly configured when using Jupyter Notebook:
• Jupyter’s common configuration system
• Notebook server
• Notebook front-end client
• Notebook extensions
Let’s look at highlights of each area.
Jupyter applications, from the Notebook to JupyterHub to nbgrader, share a common configuration system. The process
for creating a configuration file and editing settings is similar for all the Jupyter applications.
• Jupyter’s Common Configuration Approach
• Common Directories and File Locations
• Language kernels
• traitlets provide a low-level architecture for configuration.
The Notebook server runs the language kernel and communicates with the front-end Notebook client (i.e. the familiar
notebook interface).
• Configuring the Notebook server
To create a jupyter_notebook_config.py file in the .jupyter directory, with all the defaults
commented out, use the following command:
103
Jupyter Notebook Documentation, Release 6.4.5
• Related: Configuring a language kernel to run in the Notebook server enables your server to run other languages,
like R or Julia.
Note: The ability to configure the notebook frontend UI and preferences is still a work in progress.
This document is a rough explanation on how you can persist some configuration options for the notebook JavaScript.
There is no exhaustive list of all the configuration options as most options are passed down to other libraries, which
means that non valid configuration can be ignored without any error messages.
This example explains how to change the default setting indentUnit for CodeMirror Code Cells:
You can enter the previous snippet in your browser’s JavaScript console once. Then reload the notebook page in your
browser. Now, the preferred indent unit should be equal to two spaces. The custom setting persists and you do not need
to reissue the patch on new notebooks.
indentUnit, used in this example, is one of the many CodeMirror options which are available for configuration.
You can similarly change the options of the file editor by entering the following snippet in the browser’s Javascript
console once (from a file editing page).:
If you want to restore a notebook frontend preference to its default value, you will enter a JSON patch with a null
value for the preference setting.
For example, let’s restore the indent setting indentUnit to its default of four spaces. Enter the following code snippet
in your JavaScript console:
Reload the notebook in your browser and the default indent should again be two spaces.
Under the hood, Jupyter will persist the preferred configuration settings in ~/.jupyter/nbconfig/<section>.
json, with <section> taking various value depending on the page where the configuration is issued. <section>
can take various values like notebook, tree, and editor. A common section contains configuration settings shared
by all pages.
EIGHT
The notebook server can be run with a variety of command line arguments. A list of available options can be found
below in the options section.
Defaults for these options can also be set by creating a file named jupyter_notebook_config.py in your Jupyter
folder. The Jupyter folder is in your home directory, ~/.jupyter.
To create a jupyter_notebook_config.py file, with all the defaults commented out, you can use the following
command line:
8.1 Options
This list of options can be generated by running the following and hitting enter:
107
Jupyter Notebook Documentation, Release 6.4.5
This protects against ‘DNS rebinding’ attacks, where a remote web server serves you a page and then
changes its DNS to send later requests to a local IP, bypassing same-origin checks.
Local IP addresses (such as 127.0.0.1 and ::1) are allowed as local, along with hostnames configured
in local_hostnames.
NotebookApp.allow_root [Bool] Default: False
Whether to allow the user to run the notebook as root.
NotebookApp.answer_yes [Bool] Default: False
Answer yes to any prompts.
NotebookApp.authenticate_prometheus [Bool] Default: True
“ Require authentication to access prometheus metrics.
NotebookApp.autoreload [Bool] Default: False
Reload the webapp when changes are made to any Python src files.
NotebookApp.base_project_url [Unicode] Default: '/'
DEPRECATED use base_url
NotebookApp.base_url [Unicode] Default: '/'
The base URL for the notebook server.
Leading and trailing slashes can be omitted, and will automatically be added.
NotebookApp.browser [Unicode] Default: ''
Specify what command to use to invoke a web browser when opening the notebook. If not specified, the de-
fault browser will be determined by the webbrowser standard library module, which allows setting of the
BROWSER environment variable to override it.
NotebookApp.certfile [Unicode] Default: ''
The full path to an SSL/TLS certificate file.
NotebookApp.client_ca [Unicode] Default: ''
The full path to a certificate authority certificate for SSL/TLS client authentication.
NotebookApp.config_file [Unicode] Default: ''
Full path of a config file.
NotebookApp.config_file_name [Unicode] Default: ''
Specify a config file to load.
NotebookApp.config_manager_class [Type] Default: 'notebook.services.config.manager.
ConfigManager'
The config manager class to use
NotebookApp.contents_manager_class [TypeFromClasses] Default: 'notebook.services.contents.
largefilemanager.LargeFileManager'
The notebook manager class to use.
NotebookApp.cookie_options [Dict] Default: {}
Extra keyword arguments to pass to set_secure_cookie. See tornado’s set_secure_cookie docs for details.
NotebookApp.cookie_secret [Bytes] Default: b''
The random bytes used to secure cookies. By default this is a new random number every time you start the
Notebook. Set it to a value in a config file to enable logins to persist across server sessions.
Note: Cookie secrets should be kept private, do not share config files with cookie_secret stored in plaintext
(you can read the value from a file).
NotebookApp.cookie_secret_file [Unicode] Default: ''
The file where the cookie secret is stored.
NotebookApp.custom_display_url [Unicode] Default: ''
Override URL shown to users.
Replace actual URL, including protocol, address, port and base URL, with the given value when
displaying URL to the users. Do not change the actual connection URL. If authentication token is
enabled, the token is added to the custom URL automatically.
This option is intended to be used when the URL to display to the user cannot be determined reliably
by the Jupyter notebook server (proxified or containerized setups for example).
NotebookApp.default_url [Unicode] Default: '/tree'
The default URL to redirect to from /
NotebookApp.disable_check_xsrf [Bool] Default: False
Disable cross-site-request-forgery protection
Jupyter notebook 4.3.1 introduces protection from cross-site request forgeries, requiring API requests
to either:
• originate from pages served by this server (validated with XSRF cookie and token), or
• authenticate with a token
Some anonymous compute resources still desire the ability to run code, completely without authenti-
cation. These services can disable all authentication and security checks, with the full knowledge of
what that implies.
NotebookApp.enable_mathjax [Bool] Default: True
Whether to enable MathJax for typesetting math/TeX
MathJax is the javascript library Jupyter uses to render math/LaTeX. It is very large, so you may want
to disable it if you have a slow internet connection, or for offline use of the notebook.
When disabled, equations etc. will appear as their untransformed TeX source.
NotebookApp.extra_nbextensions_path [List] Default: []
extra paths to look for Javascript notebook extensions
NotebookApp.extra_services [List] Default: []
handlers that should be loaded at higher priority than the default services
NotebookApp.extra_static_paths [List] Default: []
Extra paths to search for serving static files.
This allows adding javascript/css to be available from the notebook server machine, or overriding
individual files in the IPython
NotebookApp.extra_template_paths [List] Default: []
Extra paths to search for serving jinja templates.
Forces users to use a password for the Notebook server. This is useful in a multi user environment, for in-
stance when everybody in the LAN can access each other’s machine through ssh.
In such a case, serving the notebook server on localhost is not secure since any user can connect to the
notebook server via ssh.
NotebookApp.port [Int] Default: 8888
The port the notebook server will listen on (env: JUPYTER_PORT).
NotebookApp.port_retries [Int] Default: 50
The number of additional ports to try if the specified port is not available (env: JUPYTER_PORT_RETRIES).
NotebookApp.pylab [Unicode] Default: 'disabled'
DISABLED: use %pylab or %matplotlib in the notebook to enable matplotlib.
NotebookApp.quit_button [Bool] Default: True
If True, display a button in the dashboard to quit (shutdown the notebook server).
NotebookApp.rate_limit_window [Float] Default: 3
(sec) Time window used to check the message and data rate limits.
NotebookApp.reraise_server_extension_failures [Bool] Default: False
Reraise exceptions encountered loading server extensions?
NotebookApp.server_extensions [List] Default: []
DEPRECATED use the nbserver_extensions dict instead
NotebookApp.session_manager_class [Type] Default: 'notebook.services.sessions.sessionmanager.
SessionManager'
The session manager class to use.
NotebookApp.show_config [Bool] Default: False
Instead of starting the Application, dump configuration to stdout
NotebookApp.show_config_json [Bool] Default: False
Instead of starting the Application, dump configuration to stdout (as JSON)
NotebookApp.shutdown_no_activity_timeout [Int] Default: 0
Shut down the server after N seconds with no kernels or terminals running and no activity. This can be used
together with culling idle kernels (MappingKernelManager.cull_idle_timeout) to shutdown the notebook server
when it’s not in use. This is not precisely timed: it may shut down up to a minute later. 0 (the default) disables
this automatic shutdown.
NotebookApp.sock [Unicode] Default: ''
The UNIX socket the notebook server will listen on.
NotebookApp.sock_mode [Unicode] Default: '0600'
The permissions mode for UNIX socket creation (default: 0600).
NotebookApp.ssl_options [Dict] Default: {}
Supply SSL options for the tornado HTTPServer. See the tornado docs for details.
Default is a fallback that talks to the ContentsManager API, which may be inefficient, especially for
large files.
Local files-based ContentsManagers can use a StaticFileHandler subclass, which will be much more
efficient.
Access to these files should be Authenticated.
ContentsManager.files_handler_params [Dict] Default: {}
Extra parameters to pass to files_handler_class.
For example, StaticFileHandlers generally expect a path argument specifying the root directory from
which to serve files.
ContentsManager.hide_globs [List] Default: ['__pycache__', '*.pyc', '*.pyo', '.DS_Store', '*.
so', '*.dyl...
Glob patterns to hide in file and directory listings.
ContentsManager.pre_save_hook [Any] Default: None
Python callable or importstring thereof
To be called on a contents model prior to save.
This can be used to process the structure, such as removing notebook outputs or other side effects that
should not be saved.
It will be called as (all arguments passed by keyword):
• model: the model to be saved. Includes file contents. Modifying this dict will affect the file that
is stored.
• path: the API path of the save destination
• contents_manager: this ContentsManager instance
ContentsManager.root_dir [Unicode] Default: '/'
No description
ContentsManager.untitled_directory [Unicode] Default: 'Untitled Folder'
The base name used when creating untitled directories.
ContentsManager.untitled_file [Unicode] Default: 'untitled'
The base name used when creating untitled files.
ContentsManager.untitled_notebook [Unicode] Default: 'Untitled'
The base name used when creating untitled notebooks.
FileManagerMixin.use_atomic_writing [Bool] Default: True
By default notebooks are saved on disk on a temporary file and then if successfully written, it replaces the old ones.
This procedure, namely ‘atomic_writing’, causes some bugs on file system without operation order en-
forcement (like some networked fs). If set to False, the new notebook is written directly on the old one
which could fail (eg: full filesystem or quota )
FileContentsManager.allow_hidden [Bool] Default: False
Allow access to hidden files
• model: the model to be saved. Includes file contents. Modifying this dict will affect the file that
is stored.
• path: the API path of the save destination
• contents_manager: this ContentsManager instance
FileContentsManager.root_dir [Unicode] Default: ''
No description
FileContentsManager.save_script [Bool] Default: False
DEPRECATED, use post_save_hook. Will be removed in Notebook 5.0
FileContentsManager.untitled_directory [Unicode] Default: 'Untitled Folder'
The base name used when creating untitled directories.
FileContentsManager.untitled_file [Unicode] Default: 'untitled'
The base name used when creating untitled files.
FileContentsManager.untitled_notebook [Unicode] Default: 'Untitled'
The base name used when creating untitled notebooks.
FileContentsManager.use_atomic_writing [Bool] Default: True
By default notebooks are saved on disk on a temporary file and then if successfully written, it replaces the old ones.
This procedure, namely ‘atomic_writing’, causes some bugs on file system without operation order en-
forcement (like some networked fs). If set to False, the new notebook is written directly on the old one
which could fail (eg: full filesystem or quota )
NotebookNotary.algorithm [any of 'sha512'``|’md5’|’sha1’|’sha224’|’sha384’|’sha3_512’|’blake2b’|’blake2s’|’sha3_224’|’sh
Default: 'sha256'
The hashing algorithm used to sign notebooks.
NotebookNotary.data_dir [Unicode] Default: ''
The storage directory for notary secret and database.
NotebookNotary.db_file [Unicode] Default: ''
The sqlite file in which to store notebook signatures. By default, this will be in your Jupyter data directory.
You can set it to ‘:memory:’ to disable sqlite writing to the filesystem.
NotebookNotary.secret [Bytes] Default: b''
The secret key with which notebooks are signed.
NotebookNotary.secret_file [Unicode] Default: ''
The file where the secret key is stored.
NotebookNotary.store_factory [Callable] Default: traitlets.Undefined
A callable returning the storage backend for notebook signatures. The default uses an SQLite database.
If there is no Python kernelspec registered and the IPython kernel is available, ensure it is added to the spec
list.
GatewayKernelSpecManager.kernel_spec_class [Type] Default: 'jupyter_client.kernelspec.KernelSpec'
The kernel spec class. This is configurable to allow subclassing of the KernelSpecManager for customized
behavior.
GatewayKernelSpecManager.whitelist [Set] Default: set()
Deprecated, use KernelSpecManager.allowed_kernelspecs
GatewayClient.auth_token [Unicode] Default: None
The authorization token used in the HTTP headers. (JUPYTER_GATEWAY_AUTH_TOKEN env var)
GatewayClient.ca_certs [Unicode] Default: None
The filename of CA certificates or None to use defaults. (JUPYTER_GATEWAY_CA_CERTS env var)
GatewayClient.client_cert [Unicode] Default: None
The filename for client SSL certificate, if any. (JUPYTER_GATEWAY_CLIENT_CERT env var)
GatewayClient.client_key [Unicode] Default: None
The filename for client SSL key, if any. (JUPYTER_GATEWAY_CLIENT_KEY env var)
GatewayClient.connect_timeout [Float] Default: 40.0
The time allowed for HTTP connection establishment with the Gateway server.
(JUPYTER_GATEWAY_CONNECT_TIMEOUT env var)
GatewayClient.env_whitelist [Unicode] Default: ''
A comma-separated list of environment variable names that will be included, along with their values, in
the kernel startup request. The corresponding env_whitelist configuration value must also be set on the
Gateway server - since that configuration value indicates which environmental values to make available to
the kernel. (JUPYTER_GATEWAY_ENV_WHITELIST env var)
GatewayClient.gateway_retry_interval [Float] Default: 1.0
The time allowed for HTTP reconnection with the Gateway server for the first time. Next
will be JUPYTER_GATEWAY_RETRY_INTERVAL multiplied by two in factor of
numbers of retries but less than JUPYTER_GATEWAY_RETRY_INTERVAL_MAX.
(JUPYTER_GATEWAY_RETRY_INTERVAL env var)
GatewayClient.gateway_retry_interval_max [Float] Default: 30.0
The maximum time allowed for HTTP reconnection retry with the Gateway server.
(JUPYTER_GATEWAY_RETRY_INTERVAL_MAX env var)
GatewayClient.gateway_retry_max [Int] Default: 5
The maximum retries allowed for HTTP reconnection with the Gateway server.
(JUPYTER_GATEWAY_RETRY_MAX env var)
GatewayClient.headers [Unicode] Default: '{}'
Additional HTTP headers to pass on the request. This value will be converted to a dict.
(JUPYTER_GATEWAY_HEADERS env var)
GatewayClient.http_pwd [Unicode] Default: None
The password for HTTP authentication. (JUPYTER_GATEWAY_HTTP_PWD env var)
NINE
The Jupyter notebook web application is based on a server-client structure. The notebook server uses a two-process
kernel architecture based on ZeroMQ, as well as Tornado for serving HTTP requests.
Note: By default, a notebook server runs locally at 127.0.0.1:8888 and is accessible only from localhost. You may
access the notebook server from the browser using http://127.0.0.1:8888.
This document describes how you can secure a notebook server and how to run it on a public interface.
Important: This is not the multi-user server you are looking for. This document describes how you can run a
public server with a single user. This should only be done by someone who wants remote access to their personal
machine. Even so, doing this requires a thorough understanding of the set-ups limitations and security implications. If
you allow multiple users to access a notebook server as it is described in this document, their commands may collide,
clobber and overwrite each other.
If you want a multi-user server, the official solution is JupyterHub. To use JupyterHub, you need a Unix server (typically
Linux) running somewhere that is accessible to your users on a network. This may run over the public internet, but
doing so introduces additional security concerns.
You can protect your notebook server with a simple single password. As of notebook 5.0 this can be done
automatically. To set up a password manually you can configure the NotebookApp.password setting in
jupyter_notebook_config.py.
Check to see if you have a notebook configuration file, jupyter_notebook_config.py. The default location for this
file is your Jupyter folder located in your home directory:
• Windows: C:\Users\USERNAME\.jupyter\jupyter_notebook_config.py
• OS X: /Users/USERNAME/.jupyter/jupyter_notebook_config.py
• Linux: /home/USERNAME/.jupyter/jupyter_notebook_config.py
If you don’t already have a Jupyter folder, or if your Jupyter folder doesn’t contain a notebook configuration file, run
the following command:
127
Jupyter Notebook Documentation, Release 6.4.5
This command will create the Jupyter folder if necessary, and create notebook configuration file,
jupyter_notebook_config.py, in this folder.
As of notebook 5.3, the first time you log-in using a token, the notebook server should give you the opportunity to setup
a password from the user interface.
You will be presented with a form asking for the current _token_, as well as your _new_ _password_ ; enter both and
click on Login and setup new password.
Next time you need to log in you’ll be able to use the new password instead of the login token, otherwise follow the
procedure to set a password from the command line.
The ability to change the password at first login time may be disabled by integrations by setting the --NotebookApp.
allow_password_change=False
Starting at notebook version 5.0, you can enter and store a password for your notebook server with a single com-
mand. jupyter notebook password will prompt you for your password and record the hashed password in your
jupyter_notebook_config.json.
This can be used to reset a lost password; or if you believe your credentials have been leaked and desire to change your
password. Changing your password will invalidate all logged-in sessions after a server restart.
You can prepare a hashed password manually, using the function notebook.auth.security.passwd():
Caution: passwd() when called with no arguments will prompt you to enter and verify your password
such as in the above code snippet. Although the function can also be passed a string as an argument such as
passwd('mypassword'), please do not pass a string as an argument inside an IPython session, as it will be saved
in your input history.
You can then add the hashed password to your jupyter_notebook_config.py. The default location for this file
jupyter_notebook_config.py is in your Jupyter folder in your home directory, ~/.jupyter, e.g.:
c.NotebookApp.password = u'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'
Automatic password setup will store the hash in jupyter_notebook_config.json while this method stores the
hash in jupyter_notebook_config.py. The .json configuration options take precedence over the .py one, thus
the manual password may not take effect if the Json file has a password set.
When using a password, it is a good idea to also use SSL with a web certificate, so that your hashed password is not
sent unencrypted by your browser.
Important: Web security is rapidly changing and evolving. We provide this document as a convenience to the user,
and recommend that the user keep current on changes that may impact security, such as new releases of OpenSSL.
The Open Web Application Security Project (OWASP) website is a good resource on general security issues and web
practices.
You can start the notebook to communicate via a secure protocol mode by setting the certfile option to your self-
signed certificate, i.e. mycert.pem, with the command:
Tip: A self-signed certificate can be generated with openssl. For example, the following command will create a
certificate valid for 365 days with both the key and certificate data written to the same file:
$ openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout mykey.key -out mycert.pem
When starting the notebook server, your browser may warn that your self-signed certificate is insecure or unrecognized.
If you wish to have a fully compliant self-signed certificate that will not raise warnings, it is possible (but rather involved)
to create one, as explained in detail in this tutorial. Alternatively, you may use Let’s Encrypt to acquire a free SSL
certificate and follow the steps in Using Let’s Encrypt to set up a public server.
If you want to access your notebook server remotely via a web browser, you can do so by running a public notebook
server. For optimal security when running a public notebook server, you should first secure the server with a password
and SSL/HTTPS as described in Securing a notebook server.
Start by creating a certificate file and a hashed password, as explained in Securing a notebook server.
If you don’t already have one, create a config file for the notebook using the following command line:
In the ~/.jupyter directory, edit the notebook config file, jupyter_notebook_config.py. By default, the notebook
config file has all fields commented out. The minimum set of configuration options that you should uncomment and
edit in jupyter_notebook_config.py is the following:
You can then start the notebook using the jupyter notebook command.
Let’s Encrypt provides free SSL/TLS certificates. You can also set up a public server using a Let’s Encrypt certificate.
Running a public notebook server will be similar when using a Let’s Encrypt certificate with a few configuration
changes. Here are the steps:
1. Create a Let’s Encrypt certificate.
2. Use Preparing a hashed password to create one.
3. If you don’t already have config file for the notebook, create one using the following command:
4. In the ~/.jupyter directory, edit the notebook config file, jupyter_notebook_config.py. By default, the
notebook config file has all fields commented out. The minimum set of configuration options that you should to
uncomment and edit in jupyter_notebook_config.py is the following:
You can then start the notebook using the jupyter notebook command.
Important: Use ‘https’. Keep in mind that when you enable SSL support, you must access the notebook server over
https://, not over plain http://. The startup message from the server prints a reminder in the console, but it is easy
to overlook this detail and think the server is for some reason non-responsive.
When using SSL, always access the notebook server with ‘https://’.
You may now access the public server by pointing your browser to https://your.host.com:9999 where your.
host.com is your public server’s domain.
To function correctly, the firewall on the computer running the jupyter notebook server must be configured to allow
connections from client machines on the access port c.NotebookApp.port set in jupyter_notebook_config.py
to allow connections to the web interface. The firewall must also allow connections from 127.0.0.1 (localhost) on
ports from 49152 to 65535. These ports are used by the server to communicate with the notebook kernels. The kernel
communication ports are chosen randomly by ZeroMQ, and may require multiple connections per kernel, so a large
range of ports must be accessible.
The notebook dashboard, which is the landing page with an overview of the notebooks in your working directory, is
typically found and accessed at the default URL http://localhost:8888/.
If you prefer to customize the URL prefix for the notebook dashboard, you can do so through modifying
jupyter_notebook_config.py. For example, if you prefer that the notebook dashboard be located with a sub-
directory that contains other ipython files, e.g. http://localhost:8888/ipython/, you can do so with configura-
tion options like the following (see above for instructions about modifying jupyter_notebook_config.py):
c.NotebookApp.base_url = '/ipython/'
Sometimes you may want to embed the notebook somewhere on your website, e.g. in an IFrame. To do
this, you may need to override the Content-Security-Policy to allow embedding. Assuming your website is at
https://mywebsite.example.com, you can embed the notebook on your website with the following configuration set-
ting in jupyter_notebook_config.py:
c.NotebookApp.tornado_settings = {
'headers': {
'Content-Security-Policy': "frame-ancestors https://mywebsite.example.com 'self'
˓→"
}
}
When embedding the notebook in a website using an iframe, consider putting the notebook in single-tab mode. Since
the notebook opens some links in new tabs by default, single-tab mode keeps the notebook from opening additional
tabs. Adding the following to ~/.jupyter/custom/custom.js will enable single-tab mode:
define(['base/js/namespace'], function(Jupyter){
Jupyter._target = '_self';
});
You are now able to redirect the management of your kernels to a Gateway Server (i.e., Jupyter Kernel Gateway or
Jupyter Enterprise Gateway) simply by specifying a Gateway url via the following command-line option:
the environment:
JUPYTER_GATEWAY_URL=http://my-gateway-server:8888
or in jupyter_notebook_config.py:
c.GatewayClient.url = http://my-gateway-server:8888
When provided, all kernel specifications will be retrieved from the specified Gateway server and all kernels will be
managed by that server. This option enables the ability to target kernel processes against managed clusters while
allowing for the notebook’s management to remain local to the Notebook server.
9.6.1 Proxies
When behind a proxy, especially if your system or browser is set to autodetect the proxy, the notebook web application
might fail to connect to the server’s websockets, and present you with a warning at startup. In this case, you need to
configure your system not to use the proxy for the server’s address.
For example, in Firefox, go to the Preferences panel, Advanced section, Network tab, click ‘Settings. . . ’, and add the
address of the notebook server to the ‘No proxy for’ field.
Certain security guidelines recommend that servers use a Content-Security-Policy (CSP) header to prevent cross-site
scripting vulnerabilities, specifically limiting to default-src: https: when possible. This directive causes two
problems with Jupyter. First, it disables execution of inline javascript code, which is used extensively by Jupyter. Sec-
ond, it limits communication to the https scheme, and prevents WebSockets from working because they communicate
via the wss scheme (or ws for insecure communication). Jupyter uses WebSockets for interacting with kernels, so when
you visit a server with such a CSP, your browser will block attempts to use wss, which will cause you to see “Connection
failed” messages from jupyter notebooks, or simply no response from jupyter terminals. By looking in your browser’s
javascript console, you can see any error messages that will explain what is failing.
To avoid these problem, you need to add 'unsafe-inline' and connect-src https: wss: to your CSP header,
at least for pages served by jupyter. (That is, you can leave your CSP unchanged for other parts of your website.) Note
that multiple CSP headers are allowed, but successive CSP headers can only restrict the policy; they cannot loosen it.
For example, if your server sends both of these headers
Content-Security-Policy “default-src https: ‘unsafe-inline’” Content-Security-Policy “connect-src https:
wss:”
the first policy will already eliminate wss connections, so the second has no effect. Therefore, you can’t simply add the
second header; you have to actually modify your CSP header to look more like this:
Content-Security-Policy “default-src https: ‘unsafe-inline’; connect-src https: wss:”
Using jupyter notebook as a Docker CMD results in kernels repeatedly crashing, likely due to a lack of PID reaping.
To avoid this, use the tini init as your Dockerfile ENTRYPOINT :
# Add Tini. Tini operates as a process subreaper for jupyter. This prevents
# kernel crashes.
ENV TINI_VERSION v0.6.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /usr/bin/tini
RUN chmod +x /usr/bin/tini
ENTRYPOINT ["/usr/bin/tini", "--"]
EXPOSE 8888
CMD ["jupyter", "notebook", "--port=8888", "--no-browser", "--ip=0.0.0.0"]
TEN
Since access to the Jupyter notebook server means access to running arbitrary code, it is important to restrict access to
the notebook server. For this reason, notebook 4.3 introduces token-based authentication that is on by default.
Note: If you enable a password for your notebook server, token authentication is not enabled by default, and the
behavior of the notebook server is unchanged from versions earlier than 4.3.
When token authentication is enabled, the notebook uses a token to authenticate requests. This token can be provided
to login to the notebook server in three ways:
• in the Authorization header, e.g.:
Authorization: token abcdef...
• In the password field of the login form that will be shown to you if you are not logged in.
When you start a notebook server with token authentication enabled (default), a token is generated to use for authenti-
cation. This token is logged to the terminal, so that you can copy/paste the URL into your browser:
[I 11:59:16.597 NotebookApp] The Jupyter Notebook is running at:
http://localhost:8888/?token=c8de56fa4deed24899803e93c227592aef6538f93025fe01
If the notebook server is going to open your browser automatically (the default, unless --no-browser has been passed),
an additional token is generated for launching the browser. This additional token can be used only once, and is used to
set a cookie for your browser once it connects. After your browser has made its first request with this one-time-token,
the token is discarded and a cookie is set in your browser.
At any later time, you can see the tokens and URLs for all of your running servers with jupyter notebook list:
$ jupyter notebook list
Currently running servers:
http://localhost:8888/?token=abc... :: /home/you/notebooks
https://0.0.0.0:9999/?token=123... :: /tmp/public
http://localhost:8889/ :: /tmp/has-password
For servers with token-authentication enabled, the URL in the above listing will include the token, so you can copy
and paste that URL into your browser to login. If a server has no token (e.g. it has a password or has authentication
disabled), the URL will not include the token argument. Once you have visited this URL, a cookie will be set in your
browser and you won’t need to use the token again, unless you switch browsers, clear your cookies, or start a notebook
server on a new port.
135
Jupyter Notebook Documentation, Release 6.4.5
If a generated token doesn’t work well for you, you can set a password for your notebook. jupyter notebook
password will prompt you for a password, and store the hashed password in your jupyter_notebook_config.
json.
New in version 5.0: jupyter notebook password command is added.
It is possible to disable authentication altogether by setting the token and password to empty strings, but this is NOT
RECOMMENDED, unless authentication or access restrictions are handled at a different layer in your web application:
c.NotebookApp.token = ''
c.NotebookApp.password = ''
ELEVEN
As Jupyter notebooks become more popular for sharing and collaboration, the potential for malicious people to attempt
to exploit the notebook for their nefarious purposes increases. IPython 2.0 introduced a security model to prevent
execution of untrusted code without explicit user input.
The whole point of Jupyter is arbitrary code execution. We have no desire to limit what can be done with a notebook,
which would negatively impact its utility.
Unlike other programs, a Jupyter notebook document includes output. Unlike other documents, that output exists in a
context that can execute code (via Javascript).
The security problem we need to solve is that no code should execute just because a user has opened a notebook that
they did not write. Like any other program, once a user decides to execute code in a notebook, it is considered trusted,
and should be allowed to do anything.
When a notebook is executed and saved, a signature is computed from a digest of the notebook’s contents plus a secret
key. This is stored in a database, writable only by the current user. By default, this is located at:
~/.local/share/jupyter/nbsignatures.db # Linux
~/Library/Jupyter/nbsignatures.db # OS X
%APPDATA%/jupyter/nbsignatures.db # Windows
137
Jupyter Notebook Documentation, Release 6.4.5
Each signature represents a series of outputs which were produced by code the current user executed, and are therefore
trusted.
When you open a notebook, the server computes its signature, and checks if it’s in the database. If a match is found,
HTML and Javascript output in the notebook will be trusted at load, otherwise it will be untrusted.
Any output generated during an interactive session is trusted.
A notebook’s trust is updated when the notebook is saved. If there are any untrusted outputs still in the notebook, the
notebook will not be trusted, and no signature will be stored. If all untrusted outputs have been removed (either via
Clear Output or re-execution), then the notebook will become trusted.
While trust is updated per output, this is only for the duration of a single session. A newly loaded notebook file is either
trusted or not in its entirety.
Sometimes re-executing a notebook to generate trusted output is not an option, either because dependencies are un-
available, or it would take a long time. Users can explicitly trust a notebook in two ways:
• At the command-line, with:
If you find a security vulnerability in Jupyter, either a failure of the code to properly implement the model described
here, or a failure of the model itself, please report it to [email protected].
If you prefer to encrypt your security reports, you can use this PGP public key.
Some use cases that work in Jupyter 1.0 became less convenient in 2.0 as a result of the security changes. We do our
best to minimize these annoyances, but security is always at odds with convenience.
While never officially supported, it had become common practice to put hidden Javascript or CSS styling in Markdown
cells, so that they would not be visible on the page. Since Markdown cells are now sanitized (by Google Caja), all
Javascript (including click event handlers, etc.) and CSS will be stripped.
We plan to provide a mechanism for notebook themes, but in the meantime styling the notebook can only be done via
either custom.css or CSS in HTML output. The latter only have an effect if the notebook is trusted, because otherwise
the output will be sanitized just like Markdown.
11.5.2 Collaboration
When collaborating on a notebook, people probably want to see the outputs produced by their colleagues’ most recent
executions. Since each collaborator’s key will differ, this will result in each share starting in an untrusted state. There
are three basic approaches to this:
• re-run notebooks when you get them (not always viable)
• explicitly trust notebooks via jupyter trust or the notebook menu (annoying, but easy)
• share a notebook signatures database, and use configuration dedicated to the collaboration while working on the
project.
To share a signatures database among users, you can configure:
c.NotebookNotary.data_dir = "/path/to/signature_dir"
to specify a non-default path to the SQLite database (of notebook hashes, essentially). We are aware that SQLite doesn’t
work well on NFS and we are working out better ways to do this.
TWELVE
12.1 Overview
The Jupyter Notebook client and server application are both deeply customizable. Their behavior can be extended by
creating, respectively:
• nbextension: a notebook extension
– a single JS file, or directory of JavaScript, Cascading StyleSheets, etc. that contain at minimum a JavaScript
module packaged as an AMD modules that exports a function load_ipython_extension
• server extension: an importable Python module
– that implements load_jupyter_server_extension
• bundler extension: an importable Python module with generated File -> Download as / Deploy as menu item
trigger
– that implements bundle
Since it is rare to have a server extension that does not have any frontend components (an nbextension), for convenience
and consistency, all these client and server extensions with their assets can be packaged and versioned together as a
Python package with a few simple commands, or as of Notebook 5.3, handled automatically by your package manager
of choice. This makes installing the package of extensions easier and less error-prone for the user.
There are several ways that you may get a Python package containing Jupyter Extensions. Commonly, you will use a
package manager for your system:
141
Jupyter Notebook Documentation, Release 6.4.5
The simplest case would be to enable a server extension which has no frontend components.
A pip user that wants their configuration stored in their home directory would type the following command:
Alternatively, a virtualenv or conda user can pass --sys-prefix which keeps their environment isolated and
reproducible. For example:
If a package also has an nbextension with frontend assets that must be available (but not neccessarily enabled by default),
install these assets with the following command:
If a package has assets that should be loaded every time a Jupyter app (e.g. lab, notebook, dashboard, terminal) is
loaded in the browser, the following command can be used to enable the nbextension:
After running one or more extension installation steps, you can list what is presently known about nbextensions, server
extensions, or bundler extensions. The following commands will list which extensions are available, whether they are
enabled, and other extension details:
Of course, in addition to the files listed, there are number of other files one needs to build a proper package.
Here are some good resources: - The Hitchhiker’s Guide to Packaging - Repository Structure and Python
by Kenneth Reitz
How you distribute them, too, is important: - Packaging and Distributing Projects - conda: Building
packages
Here is an example of a python module which contains a server extension directly on itself. It has this directory
structure:
- setup.py
- MANIFEST.in
- my_module/
- __init__.py
This example shows that the server extension and its load_jupyter_server_extension function are defined in the
__init__.py file.
my_module/__init__.py
def _jupyter_server_extension_paths():
return [{
"module": "my_module"
}]
def load_jupyter_server_extension(nbapp):
nbapp.log.info("my module enabled!")
Here is another server extension, with a front-end module. It assumes this directory structure:
- setup.py
- MANIFEST.in
- my_fancy_module/
- __init__.py
- static/
index.js
This example again shows that the server extension and its load_jupyter_server_extension function are defined
in the __init__.py file. This time, there is also a function _jupyter_nbextension_paths for the nbextension.
my_fancy_module/__init__.py
def _jupyter_server_extension_paths():
return [{
"module": "my_fancy_module"
}]
def load_jupyter_server_extension(nbapp):
nbapp.log.info("my module enabled!")
The user can install and enable the extensions with the following set of commands:
jupyter-config/
jupyter_notebook_config.d/
my_fancy_module.json
nbconfig/
notebook.d/
my_fancy_module.json
jupyter-config/jupyter_notebook_config.d/my_fancy_module.json
{
"NotebookApp": {
"nbserver_extensions": {
"my_fancy_module": true
}
}
}
jupyter-config/nbconfig/notebook.d/my_fancy_module.json
{
"load_extensions": {
"my_fancy_module/index": true
}
}
setup.py
import setuptools
setuptools.setup(
name="MyFancyModule",
...
include_package_data=True,
data_files=[
# like `jupyter nbextension install --sys-prefix`
("share/jupyter/nbextensions/my_fancy_module", [
"my_fancy_module/static/index.js",
]),
# like `jupyter nbextension enable --sys-prefix`
("etc/jupyter/nbconfig/notebook.d", [
"jupyter-config/nbconfig/notebook.d/my_fancy_module.json"
]),
# like `jupyter serverextension enable --sys-prefix`
("etc/jupyter/jupyter_notebook_config.d", [
"jupyter-config/jupyter_notebook_config.d/my_fancy_module.json"
])
],
...
zip_safe=False
)
MANIFEST.in
As most package managers will only modify their environment, the eventual configuration will be as if the user had
typed:
If a user manually disables an extension, that configuration will override the bundled package configuration.
Note this can still fail in certain situations with pip, requiring manual use of install and enable commands.
Non-python-specific package managers (e.g. conda, apt) may choose not to implement the above behavior at the
setup.py level, having more ways to put data files in various places at build time.
Here is a bundler extension that adds a Download as -> Notebook Tarball (tar.gz) option to the notebook File menu. It
assumes this directory structure:
- setup.py
- MANIFEST.in
- my_tarball_bundler/
- __init__.py
This example shows that the bundler extension and its bundle function are defined in the __init__.py file.
my_tarball_bundler/__init__.py
import tarfile
import io
import os
import nbformat
def _jupyter_bundlerextension_paths():
"""Declare bundler extensions provided by this package."""
return [{
# unique bundler name
"name": "tarball_bundler",
# module containing bundle function
"module_name": "my_tarball_bundler",
# human-readable menu item label
"label" : "Notebook Tarball (tar.gz)",
# group under 'deploy' or 'download' menu
"group" : "download",
}]
Parameters
----------
handler : tornado.web.RequestHandler
Handler that serviced the bundle request
model : dict
Notebook model from the configured ContentManager
"""
notebook_filename = model['name']
notebook_content = nbformat.writes(model['content']).encode('utf-8')
notebook_name = os.path.splitext(notebook_filename)[0]
(continues on next page)
info = tarfile.TarInfo(notebook_filename)
info.size = len(notebook_content)
See Extending the Notebook for more documentation about writing nbextensions, server extensions, and bundler ex-
tensions.
THIRTEEN
Certain subsystems of the notebook server are designed to be extended or overridden by users. These documents explain
these systems, and show how to override the notebook’s defaults with your own custom behavior.
The Jupyter Notebook web application provides a graphical interface for creating, opening, renaming, and deleting files
in a virtual filesystem.
The ContentsManager class defines an abstract API for translating these interactions into operations on a particular
storage medium. The default implementation, FileContentsManager, uses the local filesystem of the server for
storage and straightforwardly serializes notebooks into JSON. Users can override these behaviors by supplying custom
subclasses of ContentsManager.
This section describes the interface implemented by ContentsManager subclasses. We refer to this interface as the
Contents API.
Filesystem Entities
ContentsManager methods represent virtual filesystem entities as dictionaries, which we refer to as models.
Models may contain the following entries:
Certain model fields vary in structure depending on the type field of the model. There are three model types: notebook,
file, and directory.
• notebook models
– The format field is always "json".
149
Jupyter Notebook Documentation, Release 6.4.5
Note: In certain circumstances, we don’t need the full content of an entity to complete a Contents API request. In
such cases, we omit the content, and format keys from the model. The default values for the mimetype field will
might also not be evaluated, in which case it will be set as None. This reduced reply most commonly occurs when
listing a directory, in which circumstance we represent files within the directory as content-less models to avoid having
to recursively traverse and serialize the entire filesystem.
Sample Models
API Paths
ContentsManager methods represent the locations of filesystem resources as API-style paths. Such paths are inter-
preted as relative to the root directory of the notebook server. For compatibility across systems, the following guarantees
are made:
• Paths are always unicode, not bytes.
• Paths are not URL-escaped.
• Paths are always forward-slash (/) delimited, even on Windows.
• Leading and trailing slashes are stripped. For example, /foo/bar/buzz/ becomes foo/bar/buzz.
• The empty string ("") represents the root directory.
The default ContentsManager is designed for users running the notebook as an application on a personal computer. It
stores notebooks as .ipynb files on the local filesystem, and it maps files and directories in the Notebook UI to files and
directories on disk. It is possible to override how notebooks are stored by implementing your own custom subclass of
ContentsManager. For example, if you deploy the notebook in a context where you don’t trust or don’t have access to
the filesystem of the notebook server, it’s possible to write your own ContentsManager that stores notebooks and files
in a database.
Required Methods
A minimal complete implementation of a custom ContentsManager must implement the following methods:
You may be required to specify a Checkpoints object, as the default one, FileCheckpoints, could be incompatible
Chunked Saving
The contents API allows for “chunked” saving of files, i.e. saving/transmitting in partial pieces:
• This can only be used when the type of the model is file.
• The model should be as otherwise expected for save(), with an added field chunk.
• The value of chunk should be an integer starting at 1, and incrementing for each subsequent chunk, except for
the final chunk, which should be indicated with a value of -1.
• The model returned from using save() with chunk should be treated as unreliable for all chunks except the final
one.
• Any interaction with a file being saved in a chunked manner is unreliable until the final chunk has been saved.
This includes directory listings.
No-op example
Here is an example of a no-op checkpoints object - note the mixin comes first. The docstrings indicate what each
method should do or return for a more complete implementation.
13.1.4 Testing
notebook.services.contents.tests includes several test suites written against the abstract Contents API. This
means that an excellent way to test a new ContentsManager subclass is to subclass our tests to make them use your
ContentsManager.
You can configure functions that are run whenever a file is saved. There are two hooks available:
• ContentsManager.pre_save_hook runs on the API path and model with content. This can be used for things
like stripping output that people don’t like adding to VCS noise.
• FileContentsManager.post_save_hook runs on the filesystem path and model without content. This could
be used to commit changes after every save, for instance.
They are both called with keyword arguments:
13.2.1 Examples
c.FileContentsManager.pre_save_hook = scrub_output_pre_save
A post-save hook to make a script equivalent whenever the notebook is saved (replacing the --script option in older
versions of the notebook):
import io
import os
from notebook.utils import to_api_path
_script_exporter = None
if model['type'] != 'notebook':
return
global _script_exporter
if _script_exporter is None:
_script_exporter = ScriptExporter(parent=contents_manager)
log = contents_manager.log
c.FileContentsManager.post_save_hook = script_post_save
This could be a simple call to jupyter nbconvert --to script, but spawning the subprocess every time is quite
slow.
The notebook webserver can be interacted with using a well defined RESTful API. You can define custom RESTful
API handlers in addition to the ones provided by the notebook. As described below, to define a custom handler you
need to first write a notebook server extension. Then, in the extension, you can register the custom handler.
The notebook webserver is written in Python, hence your server extension should be written in Python too.
Server extensions, like IPython extensions, are Python modules that define a specially named load function,
load_jupyter_server_extension. This function is called when the extension is loaded.
def load_jupyter_server_extension(nb_server_app):
"""
Called when the extension is loaded.
Args:
nb_server_app (NotebookWebApplication): handle to the Notebook webserver␣
˓→instance.
"""
pass
To get the notebook server to load your custom extension, you’ll need to add it to the list of extensions to be loaded. You
can do this using the config system. NotebookApp.nbserver_extensions is a config variable which is a dictionary
of strings, each a Python module to be imported, mapping to True to enable or False to disable each extension.
Because this variable is notebook config, you can set it two different ways, using config files or via the command line.
For example, to get your extension to load via the command line add a double dash before the variable name, and put the
Python dictionary in double quotes. If your package is “mypackage” and module is “mymodule”, this would look like
jupyter notebook --NotebookApp.nbserver_extensions="{'mypackage.mymodule':True}" . Basically
the string should be Python importable.
Alternatively, you can have your extension loaded regardless of the command line args by setting the variable in the
Jupyter config file. The default location of the Jupyter config file is ~/.jupyter/jupyter_notebook_config.py
(see Configuration Overview). Inside the config file, you can use Python to set the variable. For example, the following
config does the same as the previous command line example.
c = get_config()
c.NotebookApp.nbserver_extensions = {
'mypackage.mymodule': True,
}
Before continuing, it’s a good idea to verify that your extension is being loaded. Use a print statement to print something
unique. Launch the notebook server and you should see your statement printed to the console.
Once you’ve defined a server extension, you can register custom handlers because you have a handle to the Notebook
server app instance (nb_server_app above). However, you first need to define your custom handler. To declare a
custom handler, inherit from notebook.base.handlers.IPythonHandler. The example below[1] is a Hello World
handler:
class HelloWorldHandler(IPythonHandler):
def get(self):
self.finish('Hello, world!')
The Jupyter Notebook server use Tornado as its web framework. For more information on how to implement request
handlers, refer to the Tornado documentation on the matter.
After defining the handler, you need to register the handler with the Notebook server. See the following example:
web_app = nb_server_app.web_app
host_pattern = '.*$'
route_pattern = url_path_join(web_app.settings['base_url'], '/hello')
web_app.add_handlers(host_pattern, [(route_pattern, HelloWorldHandler)])
Putting this together with the extension code, the example looks like the following:
class HelloWorldHandler(IPythonHandler):
def get(self):
self.finish('Hello, world!')
def load_jupyter_server_extension(nb_server_app):
"""
Called when the extension is loaded.
Args:
nb_server_app (NotebookWebApplication): handle to the Notebook webserver␣
˓→instance.
"""
web_app = nb_server_app.web_app
host_pattern = '.*$'
route_pattern = url_path_join(web_app.settings['base_url'], '/hello')
web_app.add_handlers(host_pattern, [(route_pattern, HelloWorldHandler)])
Here is a quick rundown of what you need to know to pass extra parameters to the handler and enable authentication:
• extra arguments to the __init__ constructor are given in a dictionary after the handler class in add_handlers:
class HelloWorldHandler(IPythonHandler):
def load_jupyter_server_extension(nb_server_app):
...
web_app.add_handlers(host_pattern,
[
(route_pattern, HelloWorldHandler, {"extra": nb_server_app.extra})
])
All handler methods that require authentication _MUST_ be decorated with @tornado.web.authenticated:
class HelloWorldHandler(IPythonHandler):
...
@web.authenticated
def get(self, *args, **kwargs):
...
@web.authenticated
def post(self, *args, **kwargs):
...
References:
1. Peter Parente’s Mindtrove
This describes the basic steps to write a JavaScript extension for the Jupyter notebook front-end. This allows you to
customize the behaviour of the various pages like the dashboard, the notebook, or the text editor.
Note: The notebook front-end and Javascript API are not stable, and are subject to a lot of changes. Any extension
written for the current notebook is almost guaranteed to break in the next release.
A front-end extension is a JavaScript file that defines an AMD module which exposes at least a function called
load_ipython_extension, which takes no arguments. We will not get into the details of what each of these terms
consists of yet, but here is the minimal code needed for a working extension:
// file my_extension/main.js
define(function(){
function load_ipython_extension(){
console.info('this is my first extension');
}
return {
load_ipython_extension: load_ipython_extension
};
});
Note: Although for historical reasons the function is called load_ipython_extension, it does apply to the Jupyter
notebook in general, and will work regardless of the kernel in use.
If you are familiar with JavaScript, you can use this template to require any Jupyter module and modify its configuration,
or do anything else in client-side Javascript. Your extension will be loaded at the right time during the notebook page
initialisation for you to set up a listener for the various events that the page can trigger.
You might want access to the current instances of the various Jupyter notebook components on the page, as opposed
to the classes defined in the modules. The current instances are exposed by a module named base/js/namespace. If
you plan on accessing instances on the page, you should require this module rather than accessing the global variable
Jupyter, which will be removed in future. The following example demonstrates how to access the current notebook
instance:
// file my_extension/main.js
define([
'base/js/namespace'
], function(
Jupyter
) {
function load_ipython_extension() {
console.log(
'This is the current notebook application instance:',
(continues on next page)
return {
load_ipython_extension: load_ipython_extension
};
});
One of the abilities of extensions is to modify key bindings, although once again this is an API which is not guaranteed
to be stable. However, custom key bindings are frequently requested, and are helpful to increase accessibility, so in the
following we show how to access them.
Here is an example of an extension that will unbind the shortcut 0,0 in command mode, which normally restarts the
kernel, and bind 0,0,0 in its place:
// file my_extension/main.js
define([
'base/js/namespace'
], function(
Jupyter
) {
function load_ipython_extension() {
Jupyter.keyboard_manager.command_shortcuts.remove_shortcut('0,0');
Jupyter.keyboard_manager.command_shortcuts.add_shortcut('0,0,0', 'jupyter-
˓→notebook:restart-kernel');
return {
load_ipython_extension: load_ipython_extension
};
});
Note: The standard keybindings might not work correctly on non-US keyboards. Unfortunately, this is a limitation of
browser implementations and the status of keyboard event handling on the web in general. We appreciate your feedback
if you have issues binding keys, or have any ideas to help improve the situation.
You can see that I have used the action name jupyter-notebook:restart-kernel to bind the new shortcut. There
is no API yet to access the list of all available actions, though the following in the JavaScript console of your browser
on a notebook page should give you an idea of what is available:
Object.keys(require('base/js/namespace').actions._actions);
In this example, we changed a keyboard shortcut in command mode; you can also customize keyboard shortcuts in
edit mode. However, most of the keyboard shortcuts in edit mode are handled by CodeMirror, which supports custom
key bindings via a completely different API.
As part of your front-end extension, you may wish to define actions, which can be attached to toolbar buttons, or called
from the command palette. Here is an example of an extension that defines an (not very useful!) action to show an
alert, and adds a toolbar button using the full action name:
// file my_extension/main.js
define([
'base/js/namespace'
], function(
Jupyter
) {
function load_ipython_extension() {
var action = {
icon: 'fa-comment-o', // a font-awesome class used on buttons, etc
help : 'Show an alert',
help_index : 'zz',
handler : handler
};
var prefix = 'my_extension';
var action_name = 'show-alert';
return {
load_ipython_extension: load_ipython_extension
};
});
Every action needs a name, which, when joined with its prefix to make the full action name, should be unique. Built-in
actions, like the jupyter-notebook:restart-kernel we bound in the earlier Modifying key bindings example, use
the prefix jupyter-notebook. For actions defined in an extension, it makes sense to use the extension name as the
prefix. For the action name, the following guidelines should be considered:
• First pick a noun and a verb for the action. For example, if the action is “restart kernel,” the verb is “restart” and
the noun is “kernel”.
• Omit terms like “selected” and “active” by default, so “delete-cell”, rather than “delete-selected-cell”. Only
provide a scope like “-all-” if it is other than the default “selected” or “active” scope.
• If an action has a secondary action, separate the secondary action with “-and-”, so “restart-kernel-and-clear-
output”.
• Use above/below or previous/next to indicate spatial and sequential relationships.
• Don’t ever use before/after as they have a temporal connotation that is confusing when used in a spatial context.
• For dialogs, use a verb that indicates what the dialog will accomplish, such as “confirm-restart-kernel”.
The default installation is system-wide. You can use --user to do a per-user installation, or --sys-prefix to install to
Python’s prefix (e.g. in a virtual or conda environment). Where my_extension is the directory containing the Javascript
files. This will copy it to a Jupyter data directory (the exact location is platform dependent - see jupyter_path).
For development, you can use the --symlink flag to symlink your extension rather than copying it, so there’s no need
to reinstall after changes.
To use your extension, you’ll also need to enable it, which tells the notebook interface to load it. You can do that with
another command:
The argument refers to the Javascript module containing your load_ipython_extension function, which is
my_extension/main.js in this example. The --section='common' argument will affect all pages, by default it
will be loaded on the notebook view only. There is a corresponding disable command to stop using an extension
without uninstalling it.
Changed in version 4.2: Added --sys-prefix argument
Warning: This feature serves as a stopgap for kernel developers who need specific JavaScript injected onto the
page. The availability and API are subject to change at anytime.
It is possible to load some JavaScript on the page on a per kernel basis. Be aware that doing so will make the browser
page reload without warning as soon as the user switches the kernel without notice.
If you, a kernel developer, need a particular piece of JavaScript to be loaded on a “per kernel” basis, such as:
• if you are developing a CodeMirror mode for your language
• if you need to enable some specific debugging options
your kernelspecs are allowed to contain a kernel.js file that defines an AMD module. The AMD module should
define an onload function that will be called when the kernelspec loads, such as:
• when you load a notebook that uses your kernelspec
• change the active kernelspec of a notebook to your kernelspec.
Note that adding a kernel.js to your kernelspec will add an unexpected side effect to changing a kernel in the notebook.
As it is impossible to “unload” JavaScript, any attempt to change the kernelspec again will save the current notebook
and reload the page without confirmations.
Here is an example of kernel.js:
define(function(){
return {onload: function(){
console.info('Kernel specific javascript loaded');
}}
});
Note: Declarative Custom Keymaps is a provisional feature with unstable API which is not guaranteed to be kept in
future versions of the notebook, and can be removed or changed without warnings.
The notebook shortcuts that are defined by jupyter both in edit mode and command mode are configurable in the
frontend configuration file ~/.jupyter/nbconfig/notebook.json. The modification of keyboard shortcuts suffers
from several limitations, mainly that your Browser and OS might prevent certain shortcuts from working correctly. If
this is the case, there is unfortunately not much that can be done. The second issue can arise with keyboards that have
a layout different than US English. Again, even if we are aware of the issue, there is not much that can be done.
Shortcuts are also limited by the underlying library that handles code and text editing: CodeMirror. If some keyboard
shortcuts are conflicting, the method described below might not work to create new keyboard shortcuts, especially in
the edit mode of the notebook.
The 4 sections of interest in ~/.jupyter/nbconfig/notebook.json are the following:
• keys.command.unbind
• keys.edit.unbind
• keys.command.bind
• keys.edit.bind
The first two sections describe which default keyboard shortcuts not to register at notebook startup time. These are
mostly useful if you need to unbind a default keyboard shortcut before binding it to a new command.
The first two sections apply respectively to the command and edit mode of the notebook. They take a list of shortcuts
to unbind.
For example, to unbind the shortcut to split a cell at the position of the cursor (Ctrl-Shift-Minus) use the following:
// file ~/.jupyter/nbconfig/notebook.json
{
"keys": {
"edit": {
"unbind": [
"Ctrl-Shift-Minus"
]
},
},
}
The last two sections describe which new keyboard shortcuts to register at notebook startup time and which actions
they trigger.
The last two sections apply respectively to the command and edit mode of the notebook. They take a dictionary with
shortcuts as keys and commands name as value.
For example, to bind the shortcut G,G,G (Press G three time in a row) in command mode to the command that restarts
the kernel and runs all cells, use the following:
// file ~/.jupyter/nbconfig/notebook.json
{
"keys": {
"command": {
"bind": {
"G,G,G":"jupyter-notebook:restart-kernel-and-run-all-cells"
}
}
},
}
The name of the available commands can be find by hovering over the right end of a row in the command palette.
The notebook server supports the writing of bundler extensions that transform, package, and download/deploy notebook
files. As a developer, you need only write a single Python function to implement a bundler. The notebook server
automatically generates a File -> Download as or File -> Deploy as menu item in the notebook front-end to trigger
your bundler.
Here are some examples of what you can implement using bundler extensions:
• Convert a notebook file to a HTML document and publish it as a post on a blog site
• Create a snapshot of the current notebook environment and bundle that definition plus notebook into a zip down-
load
• Deploy a notebook as a standalone, interactive dashboard
To implement a bundler extension, you must do all of the following:
• Declare bundler extension metadata in your Python package
• Write a bundle function that responds to bundle requests
• Instruct your users on how to enable/disable your bundler extension
The following sections describe these steps in detail.
You must provide information about the bundler extension(s) your package provides by implementing a
_jupyter_bundlerextensions_paths function. This function can reside anywhere in your package so long as it can be
imported when enabling the bundler extension. (See Enabling/disabling bundler extensions.)
# in mypackage.hello_bundler
def _jupyter_bundlerextension_paths():
"""Example "hello world" bundler extension"""
(continues on next page)
}]
Note that the return value is a list. By returning multiple dictionaries in the list, you allow users to enable/disable sets
of bundlers all at once.
At runtime, a menu item with the given label appears either in the File -> Deploy as or File -> Download as menu
depending on the group value in your metadata. When a user clicks the menu item, a new browser tab opens and
notebook server invokes a bundle function in the module_name specified in the metadata.
You must implement a bundle function that matches the signature of the following example:
# in mypackage.hello_bundler
Parameters
----------
handler : tornado.web.RequestHandler
Handler that serviced the bundle request
model : dict
Notebook model from the configured ContentManager
"""
handler.finish('I bundled {}!'.format(model['path']))
Your bundle function is free to do whatever it wants with the request and respond in any manner. For example, it may
read additional query parameters from the request, issue a redirect to another site, run a local process (e.g., nbconvert),
make a HTTP request to another service, etc.
The caller of the bundle function is @tornado.gen.coroutine decorated and wraps its call with
torando.gen.maybe_future. This behavior means you may handle the web request synchronously, as in the ex-
ample above, or asynchronously using @tornado.gen.coroutine and yield, as in the example below.
@gen.coroutine
def bundle(handler, model):
# simulate a long running IO op (e.g., deploying to a remote host)
(continues on next page)
# now respond
handler.finish('I spent 10 seconds bundling {}!'.format(model['path']))
You should prefer the second, asynchronous approach when your bundle operation is long-running and would otherwise
block the notebook server main loop if handled synchronously.
For more details about the data flow from menu item click to bundle function invocation, see Bundler invocation details.
The notebook server includes a command line interface (CLI) for enabling and disabling bundler extensions.
You should document the basic commands for enabling and disabling your bundler. One possible command for enabling
the hello_bundler example is the following:
The above updates the notebook configuration file in the current conda/virtualenv environment (–sys-prefix) with the
metadata returned by the mypackage.hellow_bundler._jupyter_bundlerextension_paths function.
The corresponding command to later disable the bundler extension is the following:
For more help using the bundlerextension subcommand, run the following.
The output describes options for listing enabled bundlers, configuring bundlers for single users, configuring bundlers
system-wide, etc.
The hello_bundler example in this documentation is simplistic in the name of brevity. For more meaningful examples,
see notebook/bundler/zip_bundler.py and notebook/bundler/tarball_bundler.py. You can enable them to try them like
so:
Support for bundler extensions comes from Python modules in notebook/bundler and JavaScript in note-
book/static/notebook/js/menubar.js. The flow of data between the various components proceeds roughly as follows:
1. User opens a notebook document
2. Notebook front-end JavaScript loads notebook configuration
3. Bundler front-end JS creates menu items for all bundler extensions in the config
4. User clicks a bundler menu item
FOURTEEN
If you’re reading this section, you’re probably interested in contributing to Jupyter. Welcome and thanks for your
interest in contributing!
Please take a look at the Contributor documentation, familiarize yourself with using the Jupyter Notebook, and intro-
duce yourself on the mailing list and share what area of the project you are interested in working on.
For general documentation about contributing to Jupyter projects, see the Project Jupyter Contributor Documentation.
Building the Notebook from its GitHub source code requires some tools to create and minify JavaScript components
and the CSS, specifically Node.js and Node’s package manager, npm. It should be node version 6.0.
If you use conda, you can get them with:
Installation on Linux may vary, but be aware that the nodejs or npm packages included in the system package repository
may be too old to work properly.
You can also use the installer from the Node.js website.
167
Jupyter Notebook Documentation, Release 6.4.5
Once you have installed the dependencies mentioned above, use the following steps:
If you are using a system-wide Python installation and you only want to install the notebook for you, you can add
--user to the install commands.
Once you have done this, you can launch the master branch of Jupyter notebook from any directory in your system
with:
jupyter notebook
14.2.3 Verification
While running the notebook, select one of your notebook files (the file will have the extension .ipynb). In the top tab
you will click on “Help” and then click on “About”. In the pop window you will see information about the version of
Jupyter that you are running. You will see “The version of the notebook server is:”. If you are working in development
mode, you will see that your version of Jupyter notebook will include the word “dev”. If it does not include the word
“dev”, you are currently not working in development mode and should follow the steps below to uninstall and reinstall
Jupyter.
If you do not see that your Jupyter Notebook is not running on dev mode, it’s possible that you are running other
instances of Jupyter Notebook. You can try the following steps:
1. Uninstall all instances of the notebook package. These include any installations you made using pip or conda.
2. Run python3 -m pip install -e . in the notebook repository to install the notebook from there.
3. Run npm run build to make sure the Javascript and CSS are updated and compiled.
4. Launch with python3 -m notebook --port 8989, and check that the browser is pointing to localhost:
8989 (rather than the default 8888). You don’t necessarily have to launch with port 8989, as long as you use a
port that is neither the default nor in use, then it should be fine.
5. Verify the installation with the steps in the previous section.
There is a build step for the JavaScript and CSS in the notebook. To make sure that you are working with up-to-date
code, you will need to run this command whenever there are changes to JavaScript or LESS sources:
IMPORTANT: Don’t forget to run npm run build after switching branches. When switching between branches of
different versions (e.g. 4.x and master), run pip install -e .. If you have tried the above and still find that the
notebook is not reflecting the current source code, try cleaning the repo with git clean -xfd and reinstalling with
pip install -e ..
Development Tip
When doing development, you can use this command to automatically rebuild JavaScript and LESS sources as they are
modified:
Git Hooks
If you want to automatically update dependencies and recompile JavaScript and CSS after checking out a new commit,
you can install post-checkout and post-merge hooks which will do it for you:
git-hooks/install-hooks.sh
Install dependencies:
pytest
To run the JavaScript tests, you will need to have PhantomJS and CasperJS installed:
where [group] is an optional argument that is a path relative to notebook/tests/. For example, to run all tests in
notebook/tests/notebook:
To build the documentation you’ll need Sphinx, pandoc and a few other packages.
To install (and activate) a conda environment named notebook_docs containing all the necessary packages (except
pandoc), use:
If you want to install the necessary packages with pip, use the following instead:
Once you have installed the required packages, you can build the docs with:
cd docs
make html
After that, the generated HTML files will be available at build/html/index.html. You may view the docs in your
browser.
You can automatically check if all hyperlinks are still valid:
make linkcheck
FIFTEEN
DEVELOPER FAQ
171
Jupyter Notebook Documentation, Release 6.4.5
SIXTEEN
MY NOTEBOOK
173
Jupyter Notebook Documentation, Release 6.4.5
SEVENTEEN
OTHER NOTEBOOK
175