##// END OF EJS Templates
move doc files to .rst so they render on github
move doc files to .rst so they render on github

File last commit:

r11729:5cc34183
r11729:5cc34183
Show More
htmlnotebook.rst
923 lines | 37.1 KiB | text/x-rst | RstLexer
Brian E. Granger
Adding initial documentation on the notebook.
r4524 .. _htmlnotebook:
David P. Sanders
Rearranged htmlnotebook.txt
r11538 The IPython Notebook
====================
David P. Sanders
Cleaned up reST formatting errors by comparison with the sphinx-rendered version. Minor rewording throughout for clarity.
r11601
David P. Sanders
Hard word wrap at 80 chars
r11603 The IPython Notebook is part of the IPython package, which aims to provide a
powerful, interactive approach to scientific computation.
The IPython Notebook extends the previous text-console-based approach, and the
later Qt console, in a qualitatively new diretion, providing a web-based
application suitable for capturing the whole scientific computation process.
David P. Sanders
Features
r11577
MinRK
update tornado dependency to 2.1...
r4856 .. seealso::
:ref:`Installation requirements <installnotebook>` for the Notebook.
David P. Sanders
Features
r11577
David P. Sanders
Finished nbconvert section
r11590 Basic structure
---------------
David P. Sanders
Features
r11577
David P. Sanders
Moved connecting to kernel section to how to's
r11554 The IPython Notebook combines two components:
David P. Sanders
Added key distinction between Notebook app and notebook documents via capitalization. Added info on different cell types and sketch of plotting
r11552
David P. Sanders
Cleaned up reST formatting errors by comparison with the sphinx-rendered version. Minor rewording throughout for clarity.
r11601 * **The IPython Notebook web application**:
David P. Sanders
Added key distinction between Notebook app and notebook documents via capitalization. Added info on different cell types and sketch of plotting
r11552
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 The *IPython Notebook web app* is a browser-based tool for interactive
authoring of literate computations, in which explanatory text, mathematics,
computations and rich media output may be combined. Input and output are
stored in persistent cells that may be edited in-place.
David P. Sanders
Added key distinction between Notebook app and notebook documents via capitalization. Added info on different cell types and sketch of plotting
r11552
David P. Sanders
Rewrote introduction. Introduced concept of *notebook space* and discussion of why the same word 'notebook' is used both for the notebook space and the corresponding notebook document
r11576 * **Notebook documents**:
Brian E. Granger
Adding initial documentation on the notebook.
r4524
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 *Notebook documents*, or *notebooks*, are plain text documents which record
all inputs and outputs of the computations, interspersed with text,
mathematics and HTML 5 representations of objects, in a literate style.
David P. Sanders
Hard word wrap at 80 chars
r11603
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 Since the similarity in names can lead to some confusion, in this documentation
David P. Sanders
Hard word wrap at 80 chars
r11603 we will use capitalization of the word "notebook" to distinguish the
*N*otebook app and *n*otebook documents, thinking of the Notebook app as being
a proper noun. We will also always refer to the "Notebook app" when we are
referring to the browser-based interface, and usually to "notebook documents",
instead of "notebooks", for added precision.
We refer to the current state of the computational process taking place in the
Notebook app, i.e. the (numbered) sequence of input and output cells, as the
*notebook space*. Notebook documents provide an *exact*, *one-to-one* record
of all the content in the notebook space, as a plain text file in JSON format.
The Notebook app automatically saves, at certain intervals, the contents of
the notebook space to a notebook document stored on disk, with the same name
as the title of the notebook space, and the file extension ``.ipynb``. For
this reason, there is no confusion about using the same word "notebook" for
both the notebook space and the corresonding notebook document, since they are
really one and the same concept (we could say that they are "isomorphic").
David P. Sanders
Rearranged htmlnotebook.txt
r11538
David P. Sanders
Proofreading finished up to the end of keyboard shortcuts
r11591 Main features of the IPython Notebook web app
---------------------------------------------
The main features of the IPython Notebook app include:
David P. Sanders
Rearranged htmlnotebook.txt
r11538
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 * In-browser editing for code, with automatic syntax highlighting and indentation and tab completion/introspection.
* Literate combination of code with rich text using the Markdown_ markup language.
* Mathematics is easily included within the Markdown using LaTeX notation, and rendered natively by MathJax_.
* Displays rich data representations (e.g. HTML / LaTeX / SVG) as the result of computations.
* Publication-quality figures in a range of formats (SVG / PNG), rendered by the matplotlib_ library, may be included inline and exported.
.. _MathJax: http://www.mathjax.org/
.. _matplotlib: http://matplotlib.org/
.. _Markdown: http://daringfireball.net/projects/markdown/syntax
David P. Sanders
Rearranged htmlnotebook.txt
r11538
Brian E. Granger
Adding initial documentation on the notebook.
r4524
David P. Sanders
Rearranged htmlnotebook.txt
r11538 Notebook documents
------------------
Fernando Perez
Add introductory docs about the notebook.
r4671
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 Notebook document files are just standard, ASCII-coded text files with the extension ``.ipynb``, stored in the working directory on your computer. Since the contents of the files are just plain text, they can be easily version-controlled and shared with colleagues.
Fernando Perez
Add introductory docs about the notebook.
r4671
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 Internally, notebook document files use the JSON_ format, allowing them to
store a *complete*, *reproducible*, *one-to-one* copy of the state of the computational state as it is inside the Notebook app.
David P. Sanders
Proofreading finished up to the end of keyboard shortcuts
r11591 All computations carried out, and the corresponding results obtained, can be
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 combined in a literate way, interleaving executable code with rich text, mathematics, and HTML 5 representations of objects.
.. _JSON: http://en.wikipedia.org/wiki/JSON
David P. Sanders
Editing of main features
r11570
Notebooks may easily be exported to a range of static formats, including
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 HTML (for example, for blog posts), PDF and slide shows, via the newly-included `nbconvert script`_ functionality.
Furthermore, any ``.ipynb`` notebook document with a publicly-available URL can be shared via the `IPython Notebook Viewer`_ service. This service loads the notebook document from the URL which will
provide 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 IPython themselves.
Brian E. Granger
Adding initial documentation on the notebook.
r4524
David P. Sanders
Minor formatting modifications (mainly where there was one backtick instead of two)
r11602 See the :ref:`installation documentation <install_index>` for directions on
Brian E. Granger
Adding initial documentation on the notebook.
r4524 how to install the notebook and its dependencies.
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 .. _`Ipython Notebook Viewer`: http://nbviewer.ipython.org
Fernando Perez
Add introductory docs about the notebook.
r4671 .. 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
David P. Sanders
Hard word wrap at 80 chars
r11603 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``
Brian E. Granger
Going back to using uuid.uuid4() for notebook ids....
r4674 option.
Fernando Perez
Add introductory docs about the notebook.
r4671
David P. Sanders
nbconvert
r11568 Starting up the IPython Notebook web app
----------------------------------------
Brian E. Granger
Adding initial documentation on the notebook.
r4524
David P. Sanders
Cleaned up reST formatting errors by comparison with the sphinx-rendered version. Minor rewording throughout for clarity.
r11601 You can start running the Notebook web app using the following command::
Fernando Perez
Add introductory docs about the notebook.
r4671
David P. Sanders
Rearranged htmlnotebook.txt
r11538 $ ipython notebook
Fernando Perez
Add introductory docs about the notebook.
r4671
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 (Here, and in the sequel, the initial ``$`` represents the shell prompt, indicating that the command is to be run from the command line in a shell.)
David P. Sanders
Hard word wrap at 80 chars
r11603 The landing page of the notebook server application, the *dashboard*, shows
the notebooks currently available in the *working directory* (the directory
from which the notebook was started).
David P. Sanders
Rearranged htmlnotebook.txt
r11538 You can create new notebooks from the dashboard with the ``New Notebook``
button, or open existing ones by clicking on their name.
David P. Sanders
Hard word wrap at 80 chars
r11603 You can also drag and drop ``.ipynb`` notebooks and standard ``.py`` Python
source code files into the notebook list area.
Fernando Perez
Add introductory docs about the notebook.
r4671
David P. Sanders
Hard word wrap at 80 chars
r11603 ``.py`` files will be imported into the IPython Notebook as a notebook with
the same name, but an ``.ipynb`` extension, located in the working directory.
The notebook created will have just one cell, which will contain all the
code in the ``.py`` file. You can later manually partition this into
individual cells using the ``Edit | Split Cell`` menu option, or the
:kbd:`Ctrl-m -` keyboard shortcut.
Fernando Perez
Add introductory docs about the notebook.
r4671
David P. Sanders
Hard word wrap at 80 chars
r11603 .. Alternatively, prior to importing the ``.py``, you can manually add ``# <
nbformat>2</nbformat>`` at the start of the file, and then add separators for
text and code cells, to get a cleaner import with the file already broken into
individual cells.
David P. Sanders
Proofreading finished up to the end of keyboard shortcuts
r11591
David P. Sanders
Hard word wrap at 80 chars
r11603 When you open or create a new notebook, your browser tab will reflect the name
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 of that notebook, prefixed by the "IPy" icon denoting that the tab corresponds to the IPython Notebook.
David P. Sanders
Hard word wrap at 80 chars
r11603 The URL is currently not meant to be human-readable and is not persistent
across invocations of the notebook server; however, this will change in a
future version of IPython.
Fernando Perez
Add introductory docs about the notebook.
r4671
David P. Sanders
Rearranged htmlnotebook.txt
r11538 The IPython Notebook web app is based on a server-client structure.
David P. Sanders
Hard word wrap at 80 chars
r11603 This server uses a two-process kernel architecture based on ZeroMQ, as well as
Tornado for serving HTTP requests. Other clients may connect to the same
underlying IPython kernel; see below.
David P. Sanders
Rearranged htmlnotebook.txt
r11538
David P. Sanders
Clarified that 'notebook' also refers to the state of the computation inside the Notebook, but that this is the same as the content of the .ipynb file
r11555
David P. Sanders
Deleted section on printing, which is no longer valid. Renamed 'exporting' to 'saving' and moved to Basic workflow. Renamed 'basic concepts' to 'user interface'.
r11563 Notebook user interface
-----------------------
David P. Sanders
Clarified that 'notebook' also refers to the state of the computation inside the Notebook, but that this is the same as the content of the .ipynb file
r11555
David P. Sanders
Hard word wrap at 80 chars
r11603 When you open a new notebook document in the Notebook, you will be presented
with the title associated to the notebook space/document, a *menu bar*, a
*toolbar* and an empty *input cell*.
David P. Sanders
Clarified that 'notebook' also refers to the state of the computation inside the Notebook, but that this is the same as the content of the .ipynb file
r11555
Notebook title
David P. Sanders
Types of input cell
r11557 ~~~~~~~~~~~~~~
David P. Sanders
Hard word wrap at 80 chars
r11603 The title of the notebook document that is currently being edited is displayed
at the top of the page, next to the ``IP[y]: Notebook`` logo. This title may
be edited directly by clicking on it. The title is reflected in the name of
the ``.ipynb`` notebook document file that is saved.
David P. Sanders
Clarified that 'notebook' also refers to the state of the computation inside the Notebook, but that this is the same as the content of the .ipynb file
r11555
Menu bar
David P. Sanders
Types of input cell
r11557 ~~~~~~~~
David P. Sanders
Hard word wrap at 80 chars
r11603 The menu bar presents different options that may be used to manipulate the way
the Notebook functions.
David P. Sanders
Clarified that 'notebook' also refers to the state of the computation inside the Notebook, but that this is the same as the content of the .ipynb file
r11555
Toolbar
David P. Sanders
Types of input cell
r11557 ~~~~~~~
David P. Sanders
Hard word wrap at 80 chars
r11603 The tool bar gives a quick way of accessing the most-used operations within
the Notebook, by clicking on an icon.
David P. Sanders
Clarified that 'notebook' also refers to the state of the computation inside the Notebook, but that this is the same as the content of the .ipynb file
r11555
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 Creating a new notebook document
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
A new notebook space/document 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 working 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.
David P. Sanders
Clarified that 'notebook' also refers to the state of the computation inside the Notebook, but that this is the same as the content of the .ipynb file
r11555
David P. Sanders
Added input cells and basic workflow sections
r11556 Input cells
-----------
David P. Sanders
Proofreading finished up to the end of keyboard shortcuts
r11591 Input cells are at the core of the functionality of the IPython Notebook.
David P. Sanders
Hard word wrap at 80 chars
r11603 They are regions in the document in which you can enter different types of
text and commands. To *execute* or *run* the *current cell*, i.e. the cell
under the cursor, you can use the :kbd:`Shift-Enter` key combination.
This tells the Notebook app to perform the relevant operation for each type of
cell (see below), and then to display the resulting output.
David P. Sanders
Clarified that 'notebook' also refers to the state of the computation inside the Notebook, but that this is the same as the content of the .ipynb file
r11555
David P. Sanders
Hard word wrap at 80 chars
r11603 The notebook consists of a sequence of input cells, labelled ``In[n]``, which
may be executed in a non-linear way, and outputs ``Out[n]``, where ``n`` is a
number which denotes the order in which the cells were executed over the
history of the computational process. The contents of all of these cells are
accessible as Python variables with the same names, forming a complete record
of the history of the computation.
David P. Sanders
Clarified that 'notebook' also refers to the state of the computation inside the Notebook, but that this is the same as the content of the .ipynb file
r11555
David P. Sanders
Added input cells and basic workflow sections
r11556
Basic workflow
--------------
David P. Sanders
Hard word wrap at 80 chars
r11603 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
David P. Sanders
Moved connecting to kernel section to how to's
r11554 times until you obtain the desired results, rather than having to
David P. Sanders
Hard word wrap at 80 chars
r11603 rerun separate scripts with the ``%run`` magic command. (Magic commands do,
however, also work in the notebook; see below).
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 computation into scripts that must be executed together, as was
previously necessary, especially if parts of them take a long time to run
The only significant limitation that the Notebook currently has, compared to
the Qt console, is that it cannot run any code that expects input from the
kernel (such as scripts that call :func:`raw_input`). Very importantly, this
means that the ``%debug`` magic does *not* currently work in the notebook!
This limitation will be overcome in the future, but in the meantime, there is
a simple solution for debugging: you can attach a Qt console to your existing
notebook kernel, and run ``%debug`` from the Qt console.
If your notebook is running on a local computer (i.e. if you are accessing it
via your localhost address at ``127.0.0.1``), then you can just type
``%qtconsole`` in the notebook and a Qt console will open up, connected to
that same kernel.
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 At certain moments, it may be necessary to interrupt a calculation which is
taking too long to complete. This may be done with the ``Kernel | Interrupt``
menu option, or the :kbd:``Ctrl-i`` keyboard shortcut.
Similarly, it may be necessary or desirable to restart the whole computational
process, with the ``Kernel | Restart`` menu option or :kbd:``Ctrl-.`` shortcut.
This gives an equivalent state to loading the notebook document afresh.
David P. Sanders
Deleted section on printing, which is no longer valid. Renamed 'exporting' to 'saving' and moved to Basic workflow. Renamed 'basic concepts' to 'user interface'.
r11563
.. warning::
David P. Sanders
nbconvert
r11568 While in simple cases you can "roundtrip" a notebook to Python, edit the
David P. Sanders
Hard word wrap at 80 chars
r11603 Python file, and then import it back without loss of main content, this is
in general *not guaranteed to work*. First, there is extra metadata
David P. Sanders
Deleted section on printing, which is no longer valid. Renamed 'exporting' to 'saving' and moved to Basic workflow. Renamed 'basic concepts' to 'user interface'.
r11563 saved in the notebook that may not be saved to the ``.py`` format. And as
the notebook format evolves in complexity, there will be attributes of the
notebook that will not survive a roundtrip through the Python form. You
should think of the Python format as a way to output a script version of a
notebook and the import capabilities as a way to load existing code to get a
notebook started. But the Python version is *not* an alternate notebook
format.
David P. Sanders
nbconvert
r11568 Keyboard shortcuts
------------------
David P. Sanders
Hard word wrap at 80 chars
r11603 All actions in the notebook can be achieved with the mouse, but keyboard
shortcuts are also available for the most common ones, so that productive use
of the notebook can be achieved with minimal mouse usage. The main shortcuts
to remember are the following:
David P. Sanders
Deleted section on printing, which is no longer valid. Renamed 'exporting' to 'saving' and moved to Basic workflow. Renamed 'basic concepts' to 'user interface'.
r11563
David P. Sanders
nbconvert
r11568 * :kbd:`Shift-Enter`:
David P. Sanders
Hard word wrap at 80 chars
r11603
Execute the current cell, show output (if any), and jump to the next cell
below. If :kbd:`Shift-Enter` is invoked on the last input cell, a new code
cell will also be created. Note that in the notebook, typing :kbd:`Enter`
on its own *never* forces execution, but rather just inserts a new line in
the current input cell. In the Notebook it is thus always necessary to use
:kbd:`Shift-Enter` to execute the cell (or use the ``Cell | Run`` menu
item).
David P. Sanders
Proofreading finished up to the end of keyboard shortcuts
r11591
* :kbd:`Ctrl-Enter`:
David P. Sanders
Hard word wrap at 80 chars
r11603 Execute the current cell as if it were in "terminal mode", where any
output is shown, but the cursor *remains* in the current cell. This is
convenient for doing quick experiments in place, or for querying things
like filesystem content, without needing to create additional cells that
you may not want to be saved in the notebook.
David P. Sanders
Deleted section on printing, which is no longer valid. Renamed 'exporting' to 'saving' and moved to Basic workflow. Renamed 'basic concepts' to 'user interface'.
r11563
David P. Sanders
nbconvert
r11568 * :kbd:`Alt-Enter`:
David P. Sanders
Hard word wrap at 80 chars
r11603 Executes the current cell, shows the output, and inserts a *new* input
cell between the current cell and the adjacent cell (if one exists). This
is thus a shortcut for the sequence :kbd:`Shift-Enter`, :kbd:`Ctrl-m a`.
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 (:kbd:`Ctrl-m a` adds a new cell above the current one.)
David P. Sanders
nbconvert
r11568
* :kbd:`Ctrl-m`:
David P. Sanders
Cleaned up reST formatting errors by comparison with the sphinx-rendered version. Minor rewording throughout for clarity.
r11601 This is the prefix for *all* other shortcuts, which consist of :kbd:`Ctrl-m` followed by a single letter or character. For example, if you type :kbd:`Ctrl-m h` (that is, the sole letter :kbd:`h` after :kbd:`Ctrl-m`), IPython will show you all the available keyboard shortcuts.
David P. Sanders
nbconvert
r11568
David P. Sanders
Deleted section on printing, which is no longer valid. Renamed 'exporting' to 'saving' and moved to Basic workflow. Renamed 'basic concepts' to 'user interface'.
r11563
David P. Sanders
Cleaned up reST formatting errors by comparison with the sphinx-rendered version. Minor rewording throughout for clarity.
r11601 Input cell types
----------------
David P. Sanders
Hard word wrap at 80 chars
r11603 Each IPython input cell has a *cell type*, of which there is a restricted
number. The type of a cell may be set by using the cell type dropdown on the
toolbar, or via the following keyboard shortcuts:
David P. Sanders
Added key distinction between Notebook app and notebook documents via capitalization. Added info on different cell types and sketch of plotting
r11552
David P. Sanders
Magics
r11562 * **code**: :kbd:`Ctrl-m y`
* **markdown**: :kbd:`Ctrl-m m`
* **raw**: :kbd:`Ctrl-m t`
* **heading**: :kbd:`Ctrl-m 1` - :kbd:`Ctrl-m 6`
David P. Sanders
Added key distinction between Notebook app and notebook documents via capitalization. Added info on different cell types and sketch of plotting
r11552
David P. Sanders
Proofreading finished up to code cells
r11592 Upon initial creation, each input cell is by default a code cell.
David P. Sanders
Added key distinction between Notebook app and notebook documents via capitalization. Added info on different cell types and sketch of plotting
r11552
Code cells
David P. Sanders
Types of input cell
r11557 ~~~~~~~~~~
David P. Sanders
Hard word wrap at 80 chars
r11603 A *code input cell* allows you to edit code inline within the cell, with full
syntax highlighting and autocompletion/introspection. By default, the language
associated to a code cell is Python, but other languages, such as ``julia``
and ``R``, can be handled using magic commands (see below).
When a code cell is executed with :kbd:`Shift-Enter`, the code that it
contains is transparently exported and run in that language (with automatic
compiling, etc., if necessary). The result that is returned from this
computation is then displayed in the notebook space as the cell's
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 *output*. If this output is of a textual nature, it is placed into a
David P. Sanders
Hard word wrap at 80 chars
r11603 numbered *output cell*. However, many other possible forms of output are also
possible, including ``matplotlib`` figures and HTML tables (as used, for
example, in the ``pandas`` data analyis package). This is known as IPython's
*rich display* capability.
David P. Sanders
Added key distinction between Notebook app and notebook documents via capitalization. Added info on different cell types and sketch of plotting
r11552
David P. Sanders
Clarified that 'notebook' also refers to the state of the computation inside the Notebook, but that this is the same as the content of the .ipynb file
r11555
David P. Sanders
Types of input cell
r11557 Rich text using Markdown
~~~~~~~~~~~~~~~~~~~~~~~~
David P. Sanders
Hard word wrap at 80 chars
r11603 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 input 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.
When a Markdown input cell is executed, the Markdown code is converted into
the corresponding formatted rich text. This output then *replaces* the
original Markdown input cell, leaving just the visually-significant marked up
rich text. Markdown 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
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 ``$$...$$`` 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
.. _`large subset`: http://docs.mathjax.org/en/latest/tex.html
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 defined using standard methods,
such as ``\newcommand``, by placing them anywhere *between math delimiters* in a Markdown cell. These definitions are then available throughout the rest of the IPython session. (Note, however, that more care must be taken when using the `nbconvert script`_ to output to LaTeX).
David P. Sanders
Added key distinction between Notebook app and notebook documents via capitalization. Added info on different cell types and sketch of plotting
r11552
David P. Sanders
Cleaned up reST formatting errors by comparison with the sphinx-rendered version. Minor rewording throughout for clarity.
r11601 Raw input cells
~~~~~~~~~~~~~~~
David P. Sanders
Hard word wrap at 80 chars
r11603 *Raw* input cells provide a place in which you can put additional information
which you do not want to evaluated by the Notebook. This can be used, for
example, to include extra information that is needed when exporting to a
certain format. The output after evaluating a raw cell is just a verbatim copy
of the input.
David P. Sanders
Proofreading finished up to heading cells
r11594
Heading cells
David P. Sanders
Cleaned up reST formatting errors by comparison with the sphinx-rendered version. Minor rewording throughout for clarity.
r11601 ~~~~~~~~~~~~~
David P. Sanders
Hard word wrap at 80 chars
r11603 You can provide a conceptual structure for your computational document as a
whole using different levels of headings; there are 6 levels available, from
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 level 1 (top level) down to level 6 (paragraph). These can be used later for
David P. Sanders
Hard word wrap at 80 chars
r11603 constructing tables of contents, etc.
David P. Sanders
Proofreading finished up to heading cells
r11594
David P. Sanders
Hard word wrap at 80 chars
r11603 As with Markdown cells, a heading input cell is replaced by a rich text
rendering of the heading when the cell is executed.
David P. Sanders
Added key distinction between Notebook app and notebook documents via capitalization. Added info on different cell types and sketch of plotting
r11552
David P. Sanders
Added input cells and basic workflow sections
r11556 Magic commands
David P. Sanders
Cleaned up reST formatting errors by comparison with the sphinx-rendered version. Minor rewording throughout for clarity.
r11601 ~~~~~~~~~~~~~~
David P. Sanders
Proofreading finished up to plotting
r11595 Magic commands, or *magics*, are commands for controlling IPython itself.
David P. Sanders
Hard word wrap at 80 chars
r11603 They all begin with ``%`` and are entered into code input cells; the code
cells are executed as usual with :kbd:`Shift-Enter`.
David P. Sanders
Cleaned up reST formatting errors by comparison with the sphinx-rendered version. Minor rewording throughout for clarity.
r11601
David P. Sanders
Hard word wrap at 80 chars
r11603 The magic commands call special functions defined by IPython which manipulate
the computational state in certain ways.
David P. Sanders
Magic commands section
r11558
David P. Sanders
Proofreading finished up to plotting
r11595 There are two types of magics:
David P. Sanders
Magic commands section
r11558
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 - **line magics**:
David P. Sanders
Hard word wrap at 80 chars
r11603 These begin with a single ``%`` and take as arguments the rest of the
*same line* of the code cell. Any other lines of the code cell are
treated as if they were part of a standard code cell.
David P. Sanders
Proofreading finished up to plotting
r11595
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 - **cell magics**:
These begin with ``%%`` and operate on the *entire* remaining contents of
the code cell.
David P. Sanders
Magic commands section
r11558
David P. Sanders
Magics
r11562 Line magics
David P. Sanders
Cleaned up reST formatting errors by comparison with the sphinx-rendered version. Minor rewording throughout for clarity.
r11601 ~~~~~~~~~~~
David P. Sanders
Magics
r11562 Some of the available line magics are the following:
David P. Sanders
Plotting section
r11559
David P. Sanders
Proofreading finished up to plotting
r11595 * ``%load filename``:
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 Loads the contents of the file ``filename`` into a new code cell. This
can be a URL for a remote file.
* ``%timeit code``:
An easy way to time how long the single line of code ``code`` takes to run
David P. Sanders
Interrupting and restarting added in basic workflow
r11560
David P. Sanders
Proofreading finished up to plotting
r11595 * ``%config``:
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617
Configuration of the IPython Notebook
David P. Sanders
Magics
r11562
David P. Sanders
Proofreading finished up to plotting
r11595 * ``%lsmagic``:
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617
Provides a list of all available magic commands
David P. Sanders
Magics
r11562
Cell magics
David P. Sanders
Cleaned up reST formatting errors by comparison with the sphinx-rendered version. Minor rewording throughout for clarity.
r11601 ~~~~~~~~~~~
David P. Sanders
Proofreading finished up to plotting
r11595 * ``%%latex``:
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617
Renders the entire contents of the cell in LaTeX, without needing to use
explicit LaTeX delimiters.
David P. Sanders
Magics
r11562
David P. Sanders
Proofreading finished up to plotting
r11595 * ``%%bash``:
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617
The code cell is executed by sending it to be executed by ``bash``. The
output of the ``bash`` commands is captured and displayed in the notebook.
David P. Sanders
Deleted section on printing, which is no longer valid. Renamed 'exporting' to 'saving' and moved to Basic workflow. Renamed 'basic concepts' to 'user interface'.
r11563
David P. Sanders
Proofreading finished up to plotting
r11595 * ``%%file filename``:
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617
Writes the contents of the cell to the file ``filename``.
**Caution**: The file is over-written without warning!
David P. Sanders
Deleted section on printing, which is no longer valid. Renamed 'exporting' to 'saving' and moved to Basic workflow. Renamed 'basic concepts' to 'user interface'.
r11563
David P. Sanders
Proofreading finished up to plotting
r11595 * ``%%R``:
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617
Execute the contents of the cell using the R language.
* ``%%timeit``:
Version of ``%timeit`` which times the entire block of code in the current code cell.
David P. Sanders
Deleted section on printing, which is no longer valid. Renamed 'exporting' to 'saving' and moved to Basic workflow. Renamed 'basic concepts' to 'user interface'.
r11563
David P. Sanders
Proofreading finished up to plotting
r11595
David P. Sanders
Hard word wrap at 80 chars
r11603 Several of the cell magics provide functionality to manipulate the filesystem
of a remote server to which you otherwise do not have access.
David P. Sanders
Interrupting and restarting added in basic workflow
r11560
David P. Sanders
Plotting section
r11559
Plotting
--------
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 One major feature of the Notebook is the ability to interact with
plots that are the output of running code cells. IPython is designed to work
seamlessly with the ``matplotlib`` plotting library to provide this
functionality.
David P. Sanders
Plotting section
r11559
David P. Sanders
Proofreading finished up to plotting
r11595 To set this up, before any plotting is performed you must execute the
David P. Sanders
Hard word wrap at 80 chars
r11603 ``%matplotlib`` magic command. This performs the necessary behind-the-scenes
setup for IPython to work correctly hand in hand with ``matplotlib``; it does
*not*, however, actually execute any Python ``import`` commands, that is, no
names are added to the namespace.
David P. Sanders
Plotting section
r11559
David P. Sanders
Hard word wrap at 80 chars
r11603 For more agile *interactive* use of the notebook space, an alternative magic,
``%pylab``, is provided. This does the same work as the ``%matplotlib`` magic,
but *in addition* it automatically executes a standard sequence of ``import``
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 statements required to work with the ``%matplotlib`` library, importing the
following names into the namespace:
David P. Sanders
Proofreading finished up to plotting
r11595
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 ``numpy`` as ``np``; ``matplotlib.pyplot`` as ``plt``;
``matplotlib``, ``pylab`` and ``mlab`` from ``matplotlib``; and *all names*
from within ``numpy`` and ``pylab``.
David P. Sanders
Plotting section
r11559
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 However, the use of ``%pylab`` is discouraged, since names coming from
different packages may collide. In general, the use of ``from package import
*`` is discouraged. A better option is then::
%pylab --no-import-all
David P. Sanders
Proofreading finished up to plotting
r11595
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 which imports the names listed above, but does *not* perform this ``import *``
imports.
If the ``%matplotlib`` or ``%pylab` magics are called without an argument, the
output of a plotting command is displayed using the default ``matplotlib``
backend in a separate window. Alternatively, the backend can be explicitly
requested using, for example::
%matplotlib gtk
David P. Sanders
Proofreading finished up to plotting
r11595
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 A particularly interesting backend is the ``inline`` backend.
This is applicable only for the IPython Notebook and the IPython Qtconsole.
It can be invoked as follows::
%matplotlib inline
David P. Sanders
Cleaned up reST formatting errors by comparison with the sphinx-rendered version. Minor rewording throughout for clarity.
r11601
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 With this backend, output of plotting commands is displayed *inline* within
the notebook format, directly below the input cell that produced it. The resulting plots will then also be stored in the notebook document. This provides a key part of the functionality for reproducibility_ that the IPython Notebook provides.
David P. Sanders
Proofreading finished up to plotting
r11595
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 .. _reproducibility: https://en.wikipedia.org/wiki/Reproducibility
David P. Sanders
Plotting section
r11559
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 .. _`nbconvert script`:
David P. Sanders
nbconvert
r11568
Converting notebooks to other formats
-------------------------------------
David P. Sanders
Hard word wrap at 80 chars
r11603 Newly added in the 1.0 release of IPython is the ``nbconvert`` tool, which
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 allows you to convert an ``.ipynb`` notebook document file into various static
formats.
David P. Sanders
nbconvert
r11568
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 Currently, ``nbconvert`` is provided as a command line tool, run as a script using IPython. In the future, a direct export capability from within the IPython Notebook web app is planned.
The command-line syntax to run the ``nbconvert`` script is::
David P. Sanders
nbconvert
r11588
$ ipython nbconvert --format=FORMAT notebook.ipynb
David P. Sanders
Hard word wrap at 80 chars
r11603 This will convert the IPython document file ``notebook.ipynb`` into the output
format given by the ``FORMAT`` string.
David P. Sanders
nbconvert
r11588
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 The default output format is HTML, for which the ``--format`` modifier may be omitted::
David P. Sanders
nbconvert
r11588
David P. Sanders
Finished first pass of refactoring
r11569 $ ipython nbconvert notebook.ipynb
David P. Sanders
nbconvert
r11568
David P. Sanders
Proofreading finished up to connecting to existing kernel
r11596 The currently supported export formats are the following:
David P. Sanders
nbconvert
r11568
David P. Sanders
Finished nbconvert section
r11590 * HTML:
David P. Sanders
nbconvert
r11568
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 - **full_html**:
David P. Sanders
nbconvert
r11588 Standard HTML
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 - **simple_html**:
David P. Sanders
nbconvert
r11588 Simplified HTML
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 - **reveal**:
David P. Sanders
nbconvert
r11588 HTML slideshow presentation for use with the ``reveal.js`` package
David P. Sanders
nbconvert
r11568
David P. Sanders
Finished nbconvert section
r11590 * PDF:
David P. Sanders
nbconvert
r11568
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 - **sphinx_howto**:
The format for Sphinx_ HOWTOs; similar to an ``article`` in LaTeX
David P. Sanders
nbconvert
r11568
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 - **sphinx_manual**:
The format for Sphinx_ manuals; similar to a ``book`` in LaTeX
David P. Sanders
nbconvert
r11588
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 - **latex**:
David P. Sanders
Cleaned up reST formatting errors by comparison with the sphinx-rendered version. Minor rewording throughout for clarity.
r11601 An article formatted completely using LaTeX
David P. Sanders
nbconvert
r11568
David P. Sanders
Finished nbconvert section
r11590 * Markup:
David P. Sanders
Plotting section
r11559
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 - **rst**:
reStructuredText_ markup
- **markdown**:
Markdown_ markup
David P. Sanders
Finished nbconvert section
r11590
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 .. _Sphinx: http://sphinx-doc.org/
.. _reStructuredText: http://docutils.sourceforge.net/rst.html
David P. Sanders
Finished nbconvert section
r11590
* Python:
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 Comments out all the non-Python code to produce a ``.py`` Python
script with just the code content. Currently the output includes IPython magics, and so can be run with ``ipython``, after changing the extension of the script to ``.ipy``.
David P. Sanders
nbconvert
r11588
David Wolever
Update nbconvert docs
r11645 The files output file created by ``nbconvert`` will have the same base name as
the notebook and will be placed in the current working directory. Any
supporting files (graphics, etc) will be placed in a new directory with the
same base name as the notebook, suffixed with ``_files``::
$ ipython nbconvert notebook.ipynb
$ ls
notebook.ipynb notebook.html notebook_files/
David P. Sanders
Finished nbconvert section
r11590
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 Each of the options for PDF export produces as an intermediate step a LaTeX
``.tex`` file with the same basename as the notebook, as well as individual
David Wolever
Update nbconvert docs
r11645 files for each figure, and ``.text`` files with textual output from running
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 code cells.
David P. Sanders
Finished nbconvert section
r11590
David P. Sanders
Minor formatting modifications (mainly where there was one backtick instead of two)
r11602 To actually produce the final PDF file, run the following commands::
David P. Sanders
Finished nbconvert section
r11590
David Wolever
Update nbconvert docs
r11645 $ ipython nbconvert --format=latex notebook.ipynb
David P. Sanders
Finished nbconvert section
r11590 $ pdflatex notebook
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 This requires a local installation of LaTeX on your machine.
The output is a PDF file ``notebook.pdf``, also placed inside the ``nbconvert_build`` subdirectory.
David P. Sanders
Finished nbconvert section
r11590
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 Alternatively, the output may be sent to standard output with::
David P. Sanders
nbconvert
r11588
David Wolever
Update nbconvert docs
r11645 $ ipython nbconvert notebook.ipynb --stdout
David P. Sanders
nbconvert
r11588
David P. Sanders
Cleaned up reST formatting errors by comparison with the sphinx-rendered version. Minor rewording throughout for clarity.
r11601 Multiple notebooks can be specified from the command line::
David P. Sanders
nbconvert
r11588
David P. Sanders
Minor formatting modifications (mainly where there was one backtick instead of two)
r11602 $ ipython nbconvert notebook*.ipynb
$ ipython nbconvert notebook1.ipynb notebook2.ipynb
David P. Sanders
nbconvert
r11588
David P. Sanders
Proofreading finished up to connecting to existing kernel
r11596 or via a list in a configuration file, say ``mycfg.py``, containing the text::
David P. Sanders
Minor formatting modifications (mainly where there was one backtick instead of two)
r11602
c = get_config()
c.NbConvertApp.notebooks = ["notebook1.ipynb", "notebook2.ipynb"]
David P. Sanders
Finished nbconvert section
r11590
and using the command::
David P. Sanders
Minor formatting modifications (mainly where there was one backtick instead of two)
r11602 $ ipython nbconvert --config mycfg.py
David P. Sanders
nbconvert
r11588
David P. Sanders
Plotting section
r11559
David P. Sanders
Proofreading finished up to connecting to existing kernel
r11596 Configuring the IPython Notebook
--------------------------------
David P. Sanders
nbconvert
r11568 The IPython Notebook can be run with a variety of command line arguments.
David P. Sanders
Added key distinction between Notebook app and notebook documents via capitalization. Added info on different cell types and sketch of plotting
r11552 To see a list of available options enter::
drevicko
Update docs/source/interactive/htmlnotebook.txt...
r9544
drevicko
Update docs/source/interactive/htmlnotebook.txt...
r9560 $ ipython notebook --help
drevicko
Update docs/source/interactive/htmlnotebook.txt...
r9544
Defaults for these options can also be set by creating a file named
David P. Sanders
Hard word wrap at 80 chars
r11603 ``ipython_notebook_config.py`` in your IPython *profile folder*. The profile
folder is a subfolder of your IPython directory; to find out where it is
located, run::
David P. Sanders
Finished nbconvert section
r11590
$ ipython locate
David P. Sanders
Added key distinction between Notebook app and notebook documents via capitalization. Added info on different cell types and sketch of plotting
r11552
David P. Sanders
Hard word wrap at 80 chars
r11603 To create a new set of default configuration files, with lots of information
on available options, use::
drevicko
Update docs/source/interactive/htmlnotebook.txt...
r9560
$ ipython profile create
drevicko
Update docs/source/interactive/htmlnotebook.txt...
r9544
drevicko
Update docs/source/interactive/htmlnotebook.txt...
r9545 .. seealso:
:ref:`config_overview`, in particular :ref:`Profiles`.
David P. Sanders
Finished first pass of refactoring
r11569 Extracting standard Python files from notebooks
-----------------------------------------------
David P. Sanders
Hard word wrap at 80 chars
r11603 ``.ipynb`` notebook document files are plain text files which store a
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 representation in JSON format of the contents of a notebook space. As such,
they are not valid ``.py`` Python scripts, and so can be neither imported
directly with ``import`` in Python, nor run directly as a standard Python
script (though both of these are possible with simple workarounds).
Fernando Perez
Add introductory docs about the notebook.
r4671
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617
To extract the Python code from within a notebook document, the simplest method is to use the ``File | Download as | Python (.py)`` menu item; the resulting ``.py`` script will be downloaded to your browser's default download location.
David P. Sanders
Hard word wrap at 80 chars
r11603
An alternative is to pass an argument to the IPython Notebook, from the moment
when it is originally started, specifying that whenever it saves an ``.ipynb``
notebook document, it should, at the same time, save the corresponding
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 ``.py`` script. To do so, you can execute the following command::
David P. Sanders
nbconvert
r11568
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 $ ipython notebook --script
David P. Sanders
nbconvert
r11568
or you can set this option permanently in your configuration file with::
David P. Sanders
Minor formatting modifications (mainly where there was one backtick instead of two)
r11602
David P. Sanders
Cleaned up reST formatting errors by comparison with the sphinx-rendered version. Minor rewording throughout for clarity.
r11601 c = get_config()
c.NotebookManager.save_script=True
David P. Sanders
nbconvert
r11568
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 The result is that standard ``.py`` files are also now generated, which
David P. Sanders
Hard word wrap at 80 chars
r11603 can be ``%run``, imported from regular IPython sessions or other notebooks, or
executed at the command line, as usual. Since the raw code you have typed is
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 exported, you must avoid using syntax such as IPython magics and other IPython-
David P. Sanders
Hard word wrap at 80 chars
r11603 specific extensions to the language for the files to be able to be
David P. Sanders
Fixed up all formatting issues and links found in documentation review. Also minor editing for clarity. Ready to be merged.
r11617 successfully imported; or you can change the script's extension to ``.ipy`` and run it with::
$ ipython script.ipy
David P. Sanders
Hard word wrap at 80 chars
r11603
In normal Python practice, the standard way to differentiate importable code
in a Python script from the "executable" part of a script is to use the
following idiom at the start of the executable part of the code::
David P. Sanders
nbconvert
r11568
David P. Sanders
Proofreading finished up to connecting to existing kernel
r11596 if __name__ == '__main__'
David P. Sanders
nbconvert
r11568
David P. Sanders
Proofreading finished up to connecting to existing kernel
r11596 # rest of the code...
David P. Sanders
nbconvert
r11568 Since all cells in the notebook are run as top-level code, you will need to
similarly protect *all* cells that you do not want executed when other scripts
try to import your notebook. A convenient shortand for this is to define early
on::
script = __name__ == '__main__'
David P. Sanders
Proofreading finished up to connecting to existing kernel
r11596 Then in any cell that you need to protect, use::
David P. Sanders
nbconvert
r11568
if script:
# rest of the cell...
Fernando Perez
Add introductory docs about the notebook.
r4671
Fernando Perez
Document notebook format and quick howto for a public nb server....
r5494
.. _notebook_security:
MinRK
add password notes to htmlnotebook doc...
r5152 Security
David P. Sanders
Finished first pass of refactoring
r11569 --------
MinRK
add password notes to htmlnotebook doc...
r5152
David P. Sanders
Proofreading finished up to connecting to existing kernel
r11596 You can protect your Notebook server with a simple single password by
Thomas Kluyver
Update docs on notebook password....
r5445 setting the :attr:`NotebookApp.password` configurable. You can prepare a
hashed password using the function :func:`IPython.lib.security.passwd`:
MinRK
add password notes to htmlnotebook doc...
r5152
Thomas Kluyver
Update docs on notebook password....
r5445 .. sourcecode:: ipython
In [1]: from IPython.lib import passwd
In [2]: passwd()
Enter password:
Verify password:
Out[2]: 'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'
.. note::
MinRK
add password notes to htmlnotebook doc...
r5152
Thomas Kluyver
Update docs on notebook password....
r5445 :func:`~IPython.lib.security.passwd` can also take the password as a string
argument. **Do not** pass it as an argument inside an IPython session, as it
will be saved in your input history.
You can then add this to your :file:`ipython_notebook_config.py`, e.g.::
# Password to use for web authentication
David P. Sanders
Cleaned up reST formatting errors by comparison with the sphinx-rendered version. Minor rewording throughout for clarity.
r11601 c = get_config()
David P. Sanders
Hard word wrap at 80 chars
r11603 c.NotebookApp.password =
u'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'
MinRK
add password notes to htmlnotebook doc...
r5152
When using a password, it is a good idea to also use SSL, so that your password
Fernando Perez
Fix typo spotted by @takluyver.
r5516 is not sent unencrypted by your browser. You can start the notebook to
David P. Sanders
Hard word wrap at 80 chars
r11603 communicate via a secure protocol mode using a self-signed certificate with
the command::
MinRK
add password notes to htmlnotebook doc...
r5152
$ ipython notebook --certfile=mycert.pem
.. note::
David P. Sanders
Hard word wrap at 80 chars
r11603 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::
MinRK
add password notes to htmlnotebook doc...
r5152
David P. Sanders
Hard word wrap at 80 chars
r11603 $ openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.
pem -out mycert.pem
MinRK
add password notes to htmlnotebook doc...
r5152
Fernando Perez
Document notebook format and quick howto for a public nb server....
r5494 Your browser will warn you of a dangerous certificate because it is
self-signed. If you want to have a fully compliant certificate that will not
David P. Sanders
Proofreading finished up to connecting to existing kernel
r11596 raise warnings, it is possible (but rather involved) to obtain one,
Fernando Perez
Document notebook format and quick howto for a public nb server....
r5494 `as explained in detailed in this tutorial`__.
David P. Sanders
Hard word wrap at 80 chars
r11603 .. __: http://arstechnica.com/security/news/2009/12/how-to-get-set-with-a-
secure-sertificate-for-free.ars
Fernando Perez
Document notebook format and quick howto for a public nb server....
r5494
David P. Sanders
Proofreading finished up to connecting to existing kernel
r11596 Keep in mind that when you enable SSL support, you will need to access the
Fernando Perez
Document notebook format and quick howto for a public nb server....
r5494 notebook server over ``https://``, not over plain ``http://``. The startup
David P. Sanders
Proofreading finished up to connecting to existing kernel
r11596 message from the server prints this, but it is easy to overlook and think the
Fernando Perez
Document notebook format and quick howto for a public nb server....
r5494 server is for some reason non-responsive.
David P. Sanders
Moved connecting to kernel section to how to's
r11554 Connecting to an existing kernel
---------------------------------
The notebook server always prints to the terminal the full details of
David P. Sanders
Proofreading finished up to connecting to existing kernel
r11596 how to connect to each kernel, with messages such as the following::
David P. Sanders
Moved connecting to kernel section to how to's
r11554
[IPKernelApp] To connect another client to this kernel, use:
[IPKernelApp] --existing kernel-3bb93edd-6b5a-455c-99c8-3b658f45dde5.json
David P. Sanders
Proofreading finished up to connecting to existing kernel
r11596 This long string is the name of a JSON file that contains all the port and
David P. Sanders
Hard word wrap at 80 chars
r11603 validation information necessary to connect to the kernel. You can then, for
example, manually start a Qt console connected to the *same* kernel with::
David P. Sanders
Moved connecting to kernel section to how to's
r11554
David P. Sanders
Hard word wrap at 80 chars
r11603 $ ipython qtconsole --existing
kernel-3bb93edd-6b5a-455c-99c8-3b658f45dde5.json
David P. Sanders
Moved connecting to kernel section to how to's
r11554
David P. Sanders
Proofreading finished up to connecting to existing kernel
r11596 If you have only a single kernel running, simply typing::
David P. Sanders
Moved connecting to kernel section to how to's
r11554
David P. Sanders
Cleaned up reST formatting errors by comparison with the sphinx-rendered version. Minor rewording throughout for clarity.
r11601 $ ipython qtconsole --existing
David P. Sanders
Moved connecting to kernel section to how to's
r11554
David P. Sanders
Proofreading finished up to connecting to existing kernel
r11596 will automatically find it. (It will always find the most recently
started kernel if there is more than one.) You can also request this
David P. Sanders
Moved connecting to kernel section to how to's
r11554 connection data by typing ``%connect_info``; this will print the same
file information as well as the content of the JSON data structure it contains.
Brian Granger
Adding AzureNotebookManager docs.
r8185 Running a public notebook server
--------------------------------
Fernando Perez
Document notebook format and quick howto for a public nb server....
r5494
David P. Sanders
Finished proofreading\!
r11597 If you want to access your notebook server remotely via a web browser,
David P. Sanders
Proofreading finished up to connecting to existing kernel
r11596 you can do the following.
David P. Sanders
Hard word wrap at 80 chars
r11603 Start by creating a certificate file and a hashed password, as explained
above. Then create a custom profile for the notebook, with the following
command line, type::
Fernando Perez
Document notebook format and quick howto for a public nb server....
r5494
David P. Sanders
Cleaned up reST formatting errors by comparison with the sphinx-rendered version. Minor rewording throughout for clarity.
r11601 $ ipython profile create nbserver
Fernando Perez
Document notebook format and quick howto for a public nb server....
r5494
David P. Sanders
Hard word wrap at 80 chars
r11603 In the profile directory just created, edit the file
``ipython_notebook_config.py``. By default, the file has all fields
commented; the minimum set you need to uncomment and edit is the following::
Fernando Perez
Document notebook format and quick howto for a public nb server....
r5494
c = get_config()
# Kernel config
c.IPKernelApp.pylab = 'inline' # if you want plotting support always
# Notebook config
c.NotebookApp.certfile = u'/absolute/path/to/your/certificate/mycert.pem'
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False
David P. Sanders
Proofreading finished up to connecting to existing kernel
r11596 c.NotebookApp.password = u'sha1:bcd259ccf...[your hashed password here]'
# It is a good idea to put it on a known, fixed port
Fernando Perez
Document notebook format and quick howto for a public nb server....
r5494 c.NotebookApp.port = 9999
You can then start the notebook and access it later by pointing your browser to
Andrew Straw
minor doc improvement
r6007 ``https://your.host.com:9999`` with ``ipython notebook --profile=nbserver``.
Fernando Perez
Document notebook format and quick howto for a public nb server....
r5494
Andrew Straw
add some documentation for URL prefix options
r6005 Running with a different URL prefix
Brian Granger
Adding AzureNotebookManager docs.
r8185 -----------------------------------
Andrew Straw
add some documentation for URL prefix options
r6005
David P. Sanders
Finished proofreading\!
r11597 The notebook dashboard (the landing page with an overview
of the notebooks in your working directory) typically lives at the URL
David P. Sanders
Hard word wrap at 80 chars
r11603 ``http://localhost:8888/``. If you prefer that it lives, together with the
rest of the notebook, under a sub-directory,
David P. Sanders
Cleaned up reST formatting errors by comparison with the sphinx-rendered version. Minor rewording throughout for clarity.
r11601 e.g. ``http://localhost:8888/ipython/``, you can do so with
David P. Sanders
Finished proofreading\!
r11597 configuration options like the following (see above for instructions about
Andrew Straw
doc fixes for alternate URL prefix
r6013 modifying ``ipython_notebook_config.py``)::
Andrew Straw
add some documentation for URL prefix options
r6005
Andrew Straw
doc fixes for alternate URL prefix
r6013 c.NotebookApp.base_project_url = '/ipython/'
c.NotebookApp.base_kernel_url = '/ipython/'
c.NotebookApp.webapp_settings = {'static_url_prefix':'/ipython/static/'}
Andrew Straw
add some documentation for URL prefix options
r6005
Brian Granger
Adding AzureNotebookManager docs.
r8185 Using a different notebook store
--------------------------------
David P. Sanders
Hard word wrap at 80 chars
r11603 By default, the Notebook app stores the notebook documents that it saves as
files in the working directory of the Notebook app, also known as the
``notebook_dir``. This logic is implemented in the
:class:`FileNotebookManager` class. However, the server can be configured to
use a different notebook manager class, which can
David P. Sanders
Finished proofreading\!
r11597 store the notebooks in a different format.
David P. Sanders
Hard word wrap at 80 chars
r11603 Currently, we ship a :class:`AzureNotebookManager` class that stores notebooks
in Azure blob storage. This can be used by adding the following lines to your
Brian Granger
Adding AzureNotebookManager docs.
r8185 ``ipython_notebook_config.py`` file::
David P. Sanders
Hard word wrap at 80 chars
r11603 c.NotebookApp.notebook_manager_class =
'IPython.html.services.notebooks.azurenbmanager.AzureNotebookManager'
Brian Granger
Adding AzureNotebookManager docs.
r8185 c.AzureNotebookManager.account_name = u'paste_your_account_name_here'
c.AzureNotebookManager.account_key = u'paste_your_account_key_here'
c.AzureNotebookManager.container = u'notebooks'
David P. Sanders
Hard word wrap at 80 chars
r11603 In addition to providing your Azure Blob Storage account name and key, you
will have to provide a container name; you can use multiple containers to
organize your notebooks.
Brian Granger
Adding AzureNotebookManager docs.
r8185
Fernando Perez
Document notebook format and quick howto for a public nb server....
r5494 .. _notebook_format:
David P. Sanders
Cleaned up reST formatting errors by comparison with the sphinx-rendered version. Minor rewording throughout for clarity.
r11601 Notebook JSON file format
-------------------------
David P. Sanders
Finished proofreading\!
r11597 Notebook documents are JSON files with an ``.ipynb`` extension, formatted
Fernando Perez
Document notebook format and quick howto for a public nb server....
r5494 as legibly as possible with minimal extra indentation and cell content broken
across lines to make them reasonably friendly to use in version-control
David P. Sanders
Finished first pass of refactoring
r11569 workflows. You should be very careful if you ever manually edit this JSON
Fernando Perez
Document notebook format and quick howto for a public nb server....
r5494 data, as it is extremely easy to corrupt its internal structure and make the
file impossible to load. In general, you should consider the notebook as a
David P. Sanders
Hard word wrap at 80 chars
r11603 file meant only to be edited by the IPython Notebook app itself, not for
hand-editing.
Fernando Perez
Document notebook format and quick howto for a public nb server....
r5494
.. note::
David P. Sanders
Hard word wrap at 80 chars
r11603 Binary data such as figures are also saved directly in the JSON file.
This provides convenient single-file portability, but means that the
files can be large; a ``diff`` of binary data is also not very
meaningful. Since the binary blobs are encoded in a single line, they
affect only one line of the ``diff`` output, but they are typically very
long lines. You can use the ``Cell | All Output | Clear`` menu option to
remove all output from a notebook prior to committing it to version
control, if this is a concern.
David P. Sanders
Finished first pass of refactoring
r11569
The notebook server can also generate a pure Python version of your notebook,
David P. Sanders
Cleaned up reST formatting errors by comparison with the sphinx-rendered version. Minor rewording throughout for clarity.
r11601 using the ``File | Download as`` menu option. The resulting ``.py`` file will
contain all the code cells from your notebook verbatim, and all Markdown cells
prepended with a comment marker. The separation between code and Markdown
Fernando Perez
Document notebook format and quick howto for a public nb server....
r5494 cells is indicated with special comments and there is a header indicating the
David P. Sanders
Finished proofreading\!
r11597 format version. All output is removed when exporting to Python.
David P. Sanders
Hard word wrap at 80 chars
r11603 As an example, consider a simple notebook called ``simple.ipynb`` which
contains one Markdown cell, with the content ``The simplest notebook.``, one
code input cell with the content ``print "Hello, IPython!"``, and the
corresponding output.
David P. Sanders
Finished proofreading\!
r11597
David P. Sanders
Hard word wrap at 80 chars
r11603 The contents of the notebook document ``simple.ipynb`` is the following JSON
container::
David P. Sanders
Finished proofreading\!
r11597
{
"metadata": {
"name": "simple"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": "The simplest notebook."
},
{
"cell_type": "code",
"collapsed": false,
"input": "print \"Hello, IPython\"",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "Hello, IPython\n"
}
],
"prompt_number": 1
}
],
"metadata": {}
}
]
}
The corresponding Python script is::
# -*- coding: utf-8 -*-
# <nbformat>3.0</nbformat>
# <markdowncell>
# The simplest notebook.
# <codecell>
print "Hello, IPython"
Fernando Perez
Document notebook format and quick howto for a public nb server....
r5494
David P. Sanders
Hard word wrap at 80 chars
r11603 Note that indeed the output of the code cell, which is present in the JSON
container, has been removed in the ``.py`` script.
David P. Sanders
Cleaned up reST formatting errors by comparison with the sphinx-rendered version. Minor rewording throughout for clarity.
r11601
Fernando Perez
Document notebook format and quick howto for a public nb server....
r5494
Brian Granger
Adding AzureNotebookManager docs.
r8185 Known issues
David P. Sanders
Finished proofreading\!
r11597 ------------
Thomas Kluyver
Add note to docs about problems with proxy for HTML notebook....
r5481
When behind a proxy, especially if your system or browser is set to autodetect
David P. Sanders
Finished first pass of refactoring
r11569 the proxy, the Notebook app might fail to connect to the server's websockets,
Thomas Kluyver
Add note to docs about problems with proxy for HTML notebook....
r5481 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.
David P. Sanders
Finished proofreading\!
r11597 For example, in Firefox, go to the Preferences panel, Advanced section,
Thomas Kluyver
Add note to docs about problems with proxy for HTML notebook....
r5481 Network tab, click 'Settings...', and add the address of the notebook server
to the 'No proxy for' field.
Fernando Perez
Add introductory docs about the notebook.
r4671
Fernando Perez
Document notebook format and quick howto for a public nb server....
r5494
Thomas Kluyver
Formatting corrections to notebook docs.
r5444 .. _Markdown: http://daringfireball.net/projects/markdown/basics