##// END OF EJS Templates
Proofreading finished up to the end of keyboard shortcuts
David P. Sanders -
Show More
@@ -1,632 +1,625 b''
1 .. _htmlnotebook:
1 .. _htmlnotebook:
2
2
3 The IPython Notebook
3 The IPython Notebook
4 ====================
4 ====================
5
5
6 The IPython Notebook is part of the IPython package, which aims to provide a powerful, interactive approach to scientific computation.
6 The IPython Notebook is part of the IPython package, which aims to provide a powerful, interactive approach to scientific computation.
7 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.
7 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.
8
8
9
9
10 .. seealso::
10 .. seealso::
11
11
12 :ref:`Installation requirements <installnotebook>` for the Notebook.
12 :ref:`Installation requirements <installnotebook>` for the Notebook.
13
13
14
14
15 Basic structure
15 Basic structure
16 ---------------
16 ---------------
17
17
18 The IPython Notebook combines two components:
18 The IPython Notebook combines two components:
19
19
20 * **The *IPython Notebook* web application**:
20 * **The *IPython Notebook* web application**:
21
21
22 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.
22 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.
23
23
24 * **Notebook documents**:
24 * **Notebook documents**:
25
25
26 *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.
26 *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.
27
27
28 Since the similarity in names can lead to some confusion, in the documentation we will always use the typographical distinction between the *N*otebook app and *n*otebook documents via the respective capitalization of the word "notebook". Here, we are 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, to increase clarity.
28 Since the similarity in names can lead to some confusion, in the documentation 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.
29
29
30 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
30 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
31 *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 name "notebook" for both the notebook space and the corresonding notebook document.
31 *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 ("isomorphic").
32
32
33 Features of the IPython Notebook web app
34 ----------------------------------------
35
33
36 Some of the main features of the IPython Notebook app include:
34 Main features of the IPython Notebook web app
35 ---------------------------------------------
36
37 The main features of the IPython Notebook app include:
37
38
38 * In-browser editing for code, with automatic syntax highlighting, tab completion and autoindentation.
39 * In-browser editing for code, with automatic syntax highlighting, tab completion and autoindentation.
39 * Literate combination of code with rich text using the Markdown markup language.
40 * Literate combination of code with rich text using the Markdown markup language.
40 * Mathematics is easily included within the Markdown using LaTeX notation, and rendered natively by MathJax.
41 * Mathematics is easily included within the Markdown using LaTeX notation, and rendered natively by MathJax.
41 * Displays rich data representations (e.g. HTML / LaTeX / SVG) as the result of computations.
42 * Displays rich data representations (e.g. HTML / LaTeX / SVG) as the result of computations.
42 * Publication-quality figures in a range of formats (SVG / PDF / PNG), rendered by the ``matplotlib`` library, may be included inline.
43 * Publication-quality figures in a range of formats (SVG / PNG), rendered by the ``matplotlib`` library, may be included inline and exported.
43
44 If you have ever used the Mathematica or SAGE notebooks (the latter is also
45 web-based__) you should feel right at home. In any case, you will be
46 able to learn how to use the IPython Notebook in just a few minutes.
47
48 .. __: http://sagenb.org
49
44
50
45
51 Notebook documents
46 Notebook documents
52 ------------------
47 ------------------
53
48
54 Notebook document files are just standard text files with the extension
49 Notebook document files are just standard text files with the extension
55 ``.ipynb``, stored in the working directory on your computer. This file can be easily put under version control and shared with colleagues.
50 ``.ipynb``, stored in the working directory on your computer. This file can be easily put under version control and shared with colleagues.
56
51
57 Despite the fact that the notebook documents are plain text files, they use
52 Despite the fact that the notebook documents are plain text files, they use
58 the JSON format in order to store a *complete*, *reproducible*, *one-to-one* copy of the state of the computational state as it is inside the Notebook app.
53 the JSON format in order to store a *complete*, *reproducible*, *one-to-one* copy of the state of the computational state as it is inside the Notebook app.
59 All computations carried out, and the corresponding results obtained, are combined in a literate way, mixing them with descriptive text, mathematics, and HTML 5 representations of objects.
54 All computations carried out, and the corresponding results obtained, can be
55 combined in a literate way, mixing them with descriptive text, mathematics,
56 and HTML 5 representations of objects.
60
57
61 Notebooks may easily be exported to a range of static formats, including
58 Notebooks may easily be exported to a range of static formats, including
62 HTML (for example, for blog posts), PDF and slide shows.
59 HTML (for example, for blog posts), PDF and slide shows.
63 Furthermore, any publicly available notebook may be shared via the
60 Furthermore, any publicly available notebook may be shared via the
64 `IPython Notebook Viewer <http://nbviewer.ipython.org>`_ service, which will
61 `IPython Notebook Viewer <http://nbviewer.ipython.org>`_ service, which will
65 provide it as a static web page. The results may thus be shared without having to install anything.
62 provide it as a static web page. The results may thus be shared without having to install anything.
66
63
67 See :ref:`our installation documentation <install_index>` for directions on
64 See :ref:`our installation documentation <install_index>` for directions on
68 how to install the notebook and its dependencies.
65 how to install the notebook and its dependencies.
69
66
70 .. note::
67 .. note::
71
68
72 You can start more than one notebook server at the same time, if you want to
69 You can start more than one notebook server at the same time, if you want to
73 work on notebooks in different directories. By default the first notebook
70 work on notebooks in different directories. By default the first notebook
74 server starts on port 8888, and later notebook servers search for ports near
71 server starts on port 8888, and later notebook servers search for ports near
75 that one. You can also manually specify the port with the ``--port``
72 that one. You can also manually specify the port with the ``--port``
76 option.
73 option.
77
74
78
75
79 Starting up the IPython Notebook web app
76 Starting up the IPython Notebook web app
80 ----------------------------------------
77 ----------------------------------------
81
78
82 The Notebook web app is started with the command::
79 The Notebook web app is started with the command::
83
80
84 $ ipython notebook
81 $ ipython notebook
85
82
86 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).
83 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).
87 You can create new notebooks from the dashboard with the ``New Notebook``
84 You can create new notebooks from the dashboard with the ``New Notebook``
88 button, or open existing ones by clicking on their name.
85 button, or open existing ones by clicking on their name.
89 You can also drag and drop ``.ipynb`` notebooks and standard ``.py`` Python source code files into the notebook list area.
86 You can also drag and drop ``.ipynb`` notebooks and standard ``.py`` Python source code files into the notebook list area.
90
87
91 ``.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 will consist of a single cell containing all the
88 ``.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 will consist of a single cell containing all the
92 code in the ``.py`` file, which you can later manually partition into individual cells.
89 code in the ``.py`` file, which you can later manually partition into individual cells.
93
90
94 .. 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.
91 .. 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.
92
93
94 When you open or create a new notebook, your browser tab will reflect the name of that notebook, prefixed with "IPy".
95 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.
95
96
96
97
97 The IPython Notebook web app is based on a server-client structure.
98 The IPython Notebook web app is based on a server-client structure.
98 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.
99 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.
99
100
100
101
101 When you open or create a new notebook, your browser tab will reflect the name of that notebook, prefixed with "IPy".
102 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.
103
102
104
103
105 Notebook user interface
104 Notebook user interface
106 -----------------------
105 -----------------------
107
106
108 When you finally start editing a notebook document in the Notebook, you will be presented with the title of the notebook, a *menu bar*, a *toolbar* and an empty *input cell*.
107 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*.
109
108
110 Notebook title
109 Notebook title
111 ~~~~~~~~~~~~~~
110 ~~~~~~~~~~~~~~
112 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.
111 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.
113
112
114 Menu bar
113 Menu bar
115 ~~~~~~~~
114 ~~~~~~~~
116 The menu bar presents different options that may be used to manipulate the way the Notebook functions.
115 The menu bar presents different options that may be used to manipulate the way the Notebook functions.
117
116
118 Toolbar
117 Toolbar
119 ~~~~~~~
118 ~~~~~~~
120 The tool bar gives handy icons for the most-used operations within the Notebook.
119 The tool bar gives a quick way of accessing the most-used operations within the Notebook, by clicking on an icon.
121
120
122
121
123 Input cells
122 Input cells
124 -----------
123 -----------
125 Input cells are the core of the functionality of the IPython Notebook.
124 Input cells are at the core of the functionality of the IPython Notebook.
126 They are regions in the document where you can enter different types of text and commands. These regions are then executed using :kbd:`Shift-Enter`, at which point the Notebook executes the current input cell, displays the resulting output beneath it, and adds a new input cell below.
125 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.
126 This tells the Notebook app to perform the relevant operation for each type of cell (see below), and then to display the resulting output.
127
127
128 The notebook consists of a sequence of input cells,
128 The notebook consists of a sequence of input cells, labelled ``In[n]``, which may be executed in a non-linear way, and outpus ``Out[n]``, where ``n`` is a number which denotes the order in which the cells were executed over the history of the computational process.
129 providing the means to direct the computational process.
130
129
131
130
132 Basic workflow
131 Basic workflow
133 --------------
132 --------------
134 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
133 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
135 times until you obtain the desired results, rather than having to
134 times until you obtain the desired results, rather than having to
136 rerun separate scripts with the ``%run`` magic command. (Magic commands do, however, also work in the notebook; see below). Typically, you'll work on a problem in pieces,
135 rerun separate scripts with the ``%run`` magic command. (Magic commands do, however, also work in the notebook; see below). Typically, you'll work on a problem in pieces,
137 organizing related pieces into cells and moving forward as previous
136 organizing related pieces into cells and moving forward as previous
138 parts work correctly. This is much more convenient for interactive exploration than breaking up a computation into scripts that must be
137 parts work correctly. This is much more convenient for interactive exploration than breaking up a computation into scripts that must be
139 executed together, especially if parts of them take a long time to run
138 executed together, especially if parts of them take a long time to run
140
139
141 The only significant limitation that the notebook currently has, compared to the Qt console, is that it cannot run any code that
140 The only significant limitation that the notebook currently has, compared to the Qt console, is that it cannot run any code that
142 expects input from the kernel (such as scripts that call
141 expects input from the kernel (such as scripts that call
143 :func:`raw_input`). Very importantly, this means that the ``%debug``
142 :func:`raw_input`). Very importantly, this means that the ``%debug``
144 magic does *not* currently work in the notebook! This limitation will
143 magic does *not* currently work in the notebook! This limitation will
145 be overcome in the future, but in the meantime, there is a way to debug problems in the notebook: you can attach a Qt console to your existing notebook kernel, and run ``%debug`` from the Qt console.
144 be overcome in the future, but in the meantime, there is a way to debug problems in the notebook: you can attach a Qt console to your existing notebook kernel, and run ``%debug`` from the Qt console.
146 If your notebook is running on a local
145 If your notebook is running on a local
147 computer (i.e. if you are accessing it via your localhost address at ``127.0.0.1``), you can just type ``%qtconsole`` in the notebook and a Qt console will open up, connected to that same kernel.
146 computer (i.e. if you are accessing it via your localhost address at ``127.0.0.1``), you can just type ``%qtconsole`` in the notebook and a Qt console will open up, connected to that same kernel.
148
147
149 At certain moments, it may be necessary to interrupt a particularly long calculation, or even to kill the entire computational process. This may be achieved by interrupting or restarting the kernel, respectively.
148 At certain moments, it may be necessary to interrupt a particularly long calculation, or even to kill the entire computational process. This may be achieved by interrupting or restarting the kernel, respectively.
150 After a restart, all relevant cells must be re-evaluated
149 After a restart, all relevant cells must be re-evaluated
151
150
152
151
153 A notebook may be downloaded in either ``.ipynb`` or raw ``.py`` form from the menu option ``File -> Download as``
152 A notebook may be downloaded in either ``.ipynb`` or raw ``.py`` form from the menu option ``File -> Download as``
154 Choosing the ``.py`` option removes all output and saves the text cells
153 Choosing the ``.py`` option removes all output and saves the text cells
155 in comment areas. See ref:`below <notebook_format>` for more details on the
154 in comment areas. See ref:`below <notebook_format>` for more details on the
156 notebook format.
155 notebook format.
157
156
158
157
159 .. warning::
158 .. warning::
160
159
161 While in simple cases you can "roundtrip" a notebook to Python, edit the
160 While in simple cases you can "roundtrip" a notebook to Python, edit the
162 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
161 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
163 saved in the notebook that may not be saved to the ``.py`` format. And as
162 saved in the notebook that may not be saved to the ``.py`` format. And as
164 the notebook format evolves in complexity, there will be attributes of the
163 the notebook format evolves in complexity, there will be attributes of the
165 notebook that will not survive a roundtrip through the Python form. You
164 notebook that will not survive a roundtrip through the Python form. You
166 should think of the Python format as a way to output a script version of a
165 should think of the Python format as a way to output a script version of a
167 notebook and the import capabilities as a way to load existing code to get a
166 notebook and the import capabilities as a way to load existing code to get a
168 notebook started. But the Python version is *not* an alternate notebook
167 notebook started. But the Python version is *not* an alternate notebook
169 format.
168 format.
170
169
171
170
172 Keyboard shortcuts
171 Keyboard shortcuts
173 ------------------
172 ------------------
174 All actions in the notebook can be achieved with the mouse, but we have also
173 All actions in the notebook can be achieved with the mouse, but
175 added keyboard shortcuts for the most common ones, so that productive use of
174 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:
176 the notebook can be achieved with minimal mouse intervention. The main
177 key bindings you need to remember are:
178
175
179 * :kbd:`Shift-Enter`:
176 * :kbd:`Shift-Enter`:
180 execute the current cell, show output (if any), and jump
177 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).
181 to the next cell below. If :kbd:`Shift-Enter`
178
182 was invoked on the last input line, a new code cell will also be created. Note that in the notebook, simply using :kbd:`Enter` *never* forces execution, it simply inserts a new line in the current cell. Therefore, in the notebook you must always use :kbd:`Shift-Enter` to get execution (or use the mouse and click on the ``Run Selected`` button).
179 * :kbd:`Ctrl-Enter`:
180 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.
183
181
184 * :kbd:`Alt-Enter`:
182 * :kbd:`Alt-Enter`:
185 this combination is similar to the previous one, with the
183 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`.
186 exception that, if the next cell below is not empty, a new code cell will be
187 added to the notebook, even if the cell execution happens not in the last cell. :kbd:`Alt-Enter`: is a shortcut for the sequence :kbd:`Shift-Enter`, :kbd:`Ctrl-m a`.
188
184
189 * :kbd:`Ctrl-Enter`:
185
190 execute the current cell in "terminal mode", where any
191 output is shown, but the cursor remains in the current cell. This is convenient to do quick in-place experiments, or query things like filesystem content, without creating additional cells that you may not want saved in your notebook.
192
186
193 * :kbd:`Ctrl-m`:
187 * :kbd:`Ctrl-m`:
194 this is the prefix for all other keybindings, which consist of an additional single letter or character. Type :kbd:`Ctrl-m h` (that is, the sole letter
188 This is the prefix for all of the other shortcuts, which consist of an additional single letter or character. 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.
195 :kbd:`h` after :kbd:`Ctrl-m`) and IPython will show you the remaining available keybindings.
196
189
197
190
198
191
199
192
200
193
201 Cell types
194 Cell types
202 ----------
195 ----------
203 Each IPython input cell has a *cell type*.
196 Each IPython input cell has a *cell type*.
204 There is a restricted number of possible cell types, which may be set by using the cell type dropdown on the toolbar, or via the following keyboard shortcuts:
197 There is a restricted number of possible cell types, which may be set by using the cell type dropdown on the toolbar, or via the following keyboard shortcuts:
205
198
206 * **code**: :kbd:`Ctrl-m y`
199 * **code**: :kbd:`Ctrl-m y`
207 * **markdown**: :kbd:`Ctrl-m m`
200 * **markdown**: :kbd:`Ctrl-m m`
208 * **raw**: :kbd:`Ctrl-m t`
201 * **raw**: :kbd:`Ctrl-m t`
209 * **heading**: :kbd:`Ctrl-m 1` - :kbd:`Ctrl-m 6`
202 * **heading**: :kbd:`Ctrl-m 1` - :kbd:`Ctrl-m 6`
210
203
211
204
212 Code cells
205 Code cells
213 ~~~~~~~~~~
206 ~~~~~~~~~~
214 Code cells contain code written in some computer language, which is Python by default. When the cell is executed with :kbd:`Shift-Enter`, this code is executed, and the result returned by Python (or the corresponding language) after running the code will be displayed as its output.
207 Code cells contain code written in some computer language, which is Python by default. When the cell is executed with :kbd:`Shift-Enter`, this code is executed, and the result returned by Python (or the corresponding language) after running the code will be displayed as its output.
215
208
216 Code may be edited inline in the cell, with full syntax highlighting.
209 Code may be edited inline in the cell, with full syntax highlighting.
217
210
218
211
219 Rich text using Markdown
212 Rich text using Markdown
220 ~~~~~~~~~~~~~~~~~~~~~~~~
213 ~~~~~~~~~~~~~~~~~~~~~~~~
221 The computational process may be documented in a literate way using rich text.
214 The computational process may be documented in a literate way using rich text.
222 For this purpose, the Notebook provides markdown cells. Text is entered using Markdown_ syntax, allowing for italics, bold, ordered and unordered lists, etc. This is rendered using Markdown syntax to a rich HTML representation when the cell is executed. In this case, the output *replaces* the input cell.
215 For this purpose, the Notebook provides markdown cells. Text is entered using Markdown_ syntax, allowing for italics, bold, ordered and unordered lists, etc. This is rendered using Markdown syntax to a rich HTML representation when the cell is executed. In this case, the output *replaces* the input cell.
223
216
224 Within markdown cells, mathematics can be included in a straightforward manner using LaTeX notation: ``$...$`` for inline math and ``$$...$$`` for displayed math. Standard LaTeX environments, such as ``\begin{equation}...\end{equation}``, also work. New commands may be defined using standard LaTeX commands, placed anywhere in a markdown cell.
217 Within markdown cells, mathematics can be included in a straightforward manner using LaTeX notation: ``$...$`` for inline math and ``$$...$$`` for displayed math. Standard LaTeX environments, such as ``\begin{equation}...\end{equation}``, also work. New commands may be defined using standard LaTeX commands, placed anywhere in a markdown cell.
225
218
226 Raw cells
219 Raw cells
227 ~~~~~~~~~
220 ~~~~~~~~~
228 Raw cells provide a place to put additional information which is not evaluated by the Notebook. This can be used, for example, for extra information to be used when the notebook is exported to a certain format.
221 Raw cells provide a place to put additional information which is not evaluated by the Notebook. This can be used, for example, for extra information to be used when the notebook is exported to a certain format.
229
222
230
223
231 Magic commands
224 Magic commands
232 --------------
225 --------------
233 Magic commands, or *magics*, are one-word commands beginning with the symbol ``%``, which send commands to IPython itself (as opposed to standard Python commands which are exported to be run in a Python interpreter).
226 Magic commands, or *magics*, are one-word commands beginning with the symbol ``%``, which send commands to IPython itself (as opposed to standard Python commands which are exported to be run in a Python interpreter).
234
227
235 Magics control different elements of the way that the IPython notebook operates. They are entered into standard code cells and executed as usual with :kbd:`Shift-Enter`.
228 Magics control different elements of the way that the IPython notebook operates. They are entered into standard code cells and executed as usual with :kbd:`Shift-Enter`.
236
229
237 There are two types of magics: *line magics*, which begin with a single ``%`` and operate on a single line of the code cell; and *cell magics*, which begin with ``%%`` and operate on the entire contents of the cell.
230 There are two types of magics: *line magics*, which begin with a single ``%`` and operate on a single line of the code cell; and *cell magics*, which begin with ``%%`` and operate on the entire contents of the cell.
238
231
239 Line magics
232 Line magics
240 ˜˜˜˜˜˜˜˜˜˜˜
233 ˜˜˜˜˜˜˜˜˜˜˜
241 Some of the available line magics are the following:
234 Some of the available line magics are the following:
242
235
243 * ``%load``:
236 * ``%load``:
244 Loads a file and places its content into a new code cell.
237 Loads a file and places its content into a new code cell.
245
238
246 * ``%timeit``:
239 * ``%timeit``:
247 A simple way to time how long a single line of code takes to run
240 A simple way to time how long a single line of code takes to run
248
241
249 * ``%config``:
242 * ``%config``:
250 Configuration of the IPython Notebook
243 Configuration of the IPython Notebook
251
244
252 * ``%lsmagic``:
245 * ``%lsmagic``:
253 Provides a list of all available magic commands
246 Provides a list of all available magic commands
254
247
255 Cell magics
248 Cell magics
256 ˜˜˜˜˜˜˜˜˜˜˜
249 ˜˜˜˜˜˜˜˜˜˜˜
257
250
258 * ``%%bash``:
251 * ``%%bash``:
259 Send the contents of the code cell to be executed by ``bash``
252 Send the contents of the code cell to be executed by ``bash``
260
253
261 * ``%%file``:
254 * ``%%file``:
262 Writes a file with with contents of the cell. *Caution*: The file is ovewritten without asking.
255 Writes a file with with contents of the cell. *Caution*: The file is ovewritten without asking.
263
256
264 * ``%%R``:
257 * ``%%R``:
265 Execute the contents of the cell using the R language.
258 Execute the contents of the cell using the R language.
266
259
267 * ``%%cython``:
260 * ``%%cython``:
268 Execute the contents of the cell using ``Cython``.
261 Execute the contents of the cell using ``Cython``.
269
262
270
263
271
264
272 Plotting
265 Plotting
273 --------
266 --------
274 One major feature of the Notebook is the ability to capture the result of plots as inline output. IPython is designed to work seamlessly together with
267 One major feature of the Notebook is the ability to capture the result of plots as inline output. IPython is designed to work seamlessly together with
275 the ``%matplotlib`` plotting library. In order to set this up, the
268 the ``%matplotlib`` plotting library. In order to set this up, the
276 ``%matplotlib`` magic command must be run before any plotting takes place.
269 ``%matplotlib`` magic command must be run before any plotting takes place.
277
270
278 Note that ``%matplotlib`` only sets up IPython to work correctly with ``matplotlib``; it does not actually execute any ``import`` commands and does not add anything to the namespace.
271 Note that ``%matplotlib`` only sets up IPython to work correctly with ``matplotlib``; it does not actually execute any ``import`` commands and does not add anything to the namespace.
279
272
280 There is an alternative magic, ``%pylab``, which, in addition, also executes a sequence of standard ``import`` statements required for working with the
273 There is an alternative magic, ``%pylab``, which, in addition, also executes a sequence of standard ``import`` statements required for working with the
281 ``%matplotlib`` library. In particular, it automatically imports all names in the ``numpy`` and ``matplotlib`` packages to the namespace. A less invasive solution is ``%pylab --no-import-all``, which imports just the standard names
274 ``%matplotlib`` library. In particular, it automatically imports all names in the ``numpy`` and ``matplotlib`` packages to the namespace. A less invasive solution is ``%pylab --no-import-all``, which imports just the standard names
282 ``np`` for the ``numpy`` module and ``plt`` for the ``matplotlib.pyplot`` module.
275 ``np`` for the ``numpy`` module and ``plt`` for the ``matplotlib.pyplot`` module.
283
276
284 When the default ``%matplotlib`` or ``%pylab`` magics are used, the output of a plotting command is captured in a *separate* window. An alternative is to use::
277 When the default ``%matplotlib`` or ``%pylab`` magics are used, the output of a plotting command is captured in a *separate* window. An alternative is to use::
285 ``%matplotlib inline``
278 ``%matplotlib inline``
286 which captures the output inline within the notebook format. This has the benefit that the resulting plots will be stored in the notebook document.
279 which captures the output inline within the notebook format. This has the benefit that the resulting plots will be stored in the notebook document.
287
280
288
281
289 Converting notebooks to other formats
282 Converting notebooks to other formats
290 -------------------------------------
283 -------------------------------------
291 Newly added in the 1.0 release of IPython is the ``nbconvert`` tool, which allows you to convert an ``.ipynb`` notebook document file into another static format.
284 Newly added in the 1.0 release of IPython is the ``nbconvert`` tool, which allows you to convert an ``.ipynb`` notebook document file into another static format.
292
285
293 Currently, only a command line tool is provided; at present, this functionality is not available for direct exports from within the Notebook app. The syntax is::
286 Currently, only a command line tool is provided; at present, this functionality is not available for direct exports from within the Notebook app. The syntax is::
294
287
295 $ ipython nbconvert --format=FORMAT notebook.ipynb
288 $ ipython nbconvert --format=FORMAT notebook.ipynb
296
289
297 which will convert the IPython document file `notebook.ipynb` into the output format specified by the `FORMAT` string.
290 which will convert the IPython document file `notebook.ipynb` into the output format specified by the `FORMAT` string.
298
291
299 The default output format is HTML, for which the `--format`` modifier is not required::
292 The default output format is HTML, for which the `--format`` modifier is not required::
300
293
301 $ ipython nbconvert notebook.ipynb
294 $ ipython nbconvert notebook.ipynb
302
295
303 Otherwise, the following `FORMAT`
296 Otherwise, the following `FORMAT`
304
297
305 where ``FORMAT`` is the desired export format. The currently export format options available are the following:
298 where ``FORMAT`` is the desired export format. The currently export format options available are the following:
306
299
307 * HTML:
300 * HTML:
308
301
309 - ``full_html``:
302 - ``full_html``:
310 Standard HTML
303 Standard HTML
311
304
312 - ``simple_html``:
305 - ``simple_html``:
313 Simplified HTML
306 Simplified HTML
314
307
315 - ``reveal``:
308 - ``reveal``:
316 HTML slideshow presentation for use with the ``reveal.js`` package
309 HTML slideshow presentation for use with the ``reveal.js`` package
317
310
318 * PDF:
311 * PDF:
319
312
320 - ``sphinx_howto``:
313 - ``sphinx_howto``:
321 The format for Sphinx HOWTOs; similar to `article` in LaTeX
314 The format for Sphinx HOWTOs; similar to `article` in LaTeX
322
315
323 - ``sphinx_manual``:
316 - ``sphinx_manual``:
324 The format for Sphinx manuals; similar to `book` in LaTeX
317 The format for Sphinx manuals; similar to `book` in LaTeX
325
318
326 - ``latex``:
319 - ``latex``:
327 LaTeX article
320 LaTeX article
328
321
329 * Markup:
322 * Markup:
330
323
331 - ``rst``:
324 - ``rst``:
332 reStructuredText
325 reStructuredText
333
326
334 - ``markdown``:
327 - ``markdown``:
335 Markdown
328 Markdown
336
329
337 * Python:
330 * Python:
338
331
339 Produces a standard ``.py`` script, with the non-Python code commented out.
332 Produces a standard ``.py`` script, with the non-Python code commented out.
340
333
341 The output files are currently placed in a new subdirectory called
334 The output files are currently placed in a new subdirectory called
342 ``nbconvert_build``.
335 ``nbconvert_build``.
343
336
344 The PDF options produce a root LaTeX `.tex` file with the same name as the notebook, as well as individual files for each figure, and `.text` files with textual output from running code cells; all of these files are located together in the `nbconvert_build` subdirectory.
337 The PDF options produce a root LaTeX `.tex` file with the same name as the notebook, as well as individual files for each figure, and `.text` files with textual output from running code cells; all of these files are located together in the `nbconvert_build` subdirectory.
345
338
346 To actually produce the final PDF file, simply run::
339 To actually produce the final PDF file, simply run::
347
340
348 $ pdflatex notebook
341 $ pdflatex notebook
349
342
350 which produces `notebook.pdf`, also inside the `nbconvert_build` subdirectory.
343 which produces `notebook.pdf`, also inside the `nbconvert_build` subdirectory.
351
344
352 Alternatively, the output may be piped to standard output `stdout` with::
345 Alternatively, the output may be piped to standard output `stdout` with::
353
346
354 $ ipython nbconvert mynotebook.ipynb --stdout
347 $ ipython nbconvert mynotebook.ipynb --stdout
355
348
356 Multiple notebooks can be specified at the command line in a couple of
349 Multiple notebooks can be specified at the command line in a couple of
357 different ways::
350 different ways::
358
351
359 $ ipython nbconvert notebook*.ipynb
352 $ ipython nbconvert notebook*.ipynb
360 $ ipython nbconvert notebook1.ipynb notebook2.ipynb
353 $ ipython nbconvert notebook1.ipynb notebook2.ipynb
361
354
362 or via a list in a configuration file, containing::
355 or via a list in a configuration file, containing::
363
356
364 c.NbConvertApp.notebooks = ["notebook1.ipynb", "notebook2.ipynb"]
357 c.NbConvertApp.notebooks = ["notebook1.ipynb", "notebook2.ipynb"]
365
358
366 and using the command::
359 and using the command::
367
360
368 > ipython nbconvert --config mycfg.py
361 > ipython nbconvert --config mycfg.py
369
362
370
363
371 Configuration
364 Configuration
372 -------------
365 -------------
373 The IPython Notebook can be run with a variety of command line arguments.
366 The IPython Notebook can be run with a variety of command line arguments.
374 To see a list of available options enter::
367 To see a list of available options enter::
375
368
376 $ ipython notebook --help
369 $ ipython notebook --help
377
370
378 Defaults for these options can also be set by creating a file named
371 Defaults for these options can also be set by creating a file named
379 `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::
372 `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::
380
373
381 $ ipython locate
374 $ ipython locate
382
375
383 To create a new set of default configuration files, with lots of information on available options, use::
376 To create a new set of default configuration files, with lots of information on available options, use::
384
377
385 $ ipython profile create
378 $ ipython profile create
386
379
387 .. seealso:
380 .. seealso:
388
381
389 :ref:`config_overview`, in particular :ref:`Profiles`.
382 :ref:`config_overview`, in particular :ref:`Profiles`.
390
383
391
384
392 Extracting standard Python files from notebooks
385 Extracting standard Python files from notebooks
393 -----------------------------------------------
386 -----------------------------------------------
394
387
395 The native format of the notebook, a file with a ``.ipynb`` `extension, is a
388 The native format of the notebook, a file with a ``.ipynb`` `extension, is a
396 JSON container of all the input and output of the notebook, and therefore not
389 JSON container of all the input and output of the notebook, and therefore not
397 valid Python by itself. This means that by default, you cannot directly
390 valid Python by itself. This means that by default, you cannot directly
398 import a notebook from Python, nor execute it as a normal python script.
391 import a notebook from Python, nor execute it as a normal python script.
399
392
400 But if you want to be able to use notebooks also as regular Python files, you can start the notebook server with::
393 But if you want to be able to use notebooks also as regular Python files, you can start the notebook server with::
401
394
402 ipython notebook --script
395 ipython notebook --script
403
396
404 or you can set this option permanently in your configuration file with::
397 or you can set this option permanently in your configuration file with::
405
398
406 c.NotebookManager.save_script=True
399 c.NotebookManager.save_script=True
407
400
408 This will instruct the notebook server to save the ``.py`` export of each
401 This will instruct the notebook server to save the ``.py`` export of each
409 notebook, in addition to the ``.ipynb``, at every save. These are standard
402 notebook, in addition to the ``.ipynb``, at every save. These are standard
410 ``.py`` files, and so they can be ``%run``, imported from regular IPython
403 ``.py`` files, and so they can be ``%run``, imported from regular IPython
411 sessions or other notebooks, or executed at the command line. Since we export
404 sessions or other notebooks, or executed at the command line. Since we export
412 the raw code you have typed, for these files to be importable from other code,
405 the raw code you have typed, for these files to be importable from other code,
413 you will have to avoid using syntax such as ``%magic``s and other IPython-specific extensions to the language.
406 you will have to avoid using syntax such as ``%magic``s and other IPython-specific extensions to the language.
414
407
415 In regular practice, the standard way to differentiate importable code from the
408 In regular practice, the standard way to differentiate importable code from the
416 'executable' part of a script is to put at the bottom::
409 'executable' part of a script is to put at the bottom::
417
410
418 if __name__ == '__main__':
411 if __name__ == '__main__':
419 # rest of the code...
412 # rest of the code...
420
413
421 Since all cells in the notebook are run as top-level code, you will need to
414 Since all cells in the notebook are run as top-level code, you will need to
422 similarly protect *all* cells that you do not want executed when other scripts
415 similarly protect *all* cells that you do not want executed when other scripts
423 try to import your notebook. A convenient shortand for this is to define early
416 try to import your notebook. A convenient shortand for this is to define early
424 on::
417 on::
425
418
426 script = __name__ == '__main__'
419 script = __name__ == '__main__'
427
420
428 and then on any cell that you need to protect, use::
421 and then on any cell that you need to protect, use::
429
422
430 if script:
423 if script:
431 # rest of the cell...
424 # rest of the cell...
432
425
433
426
434 .. _notebook_security:
427 .. _notebook_security:
435
428
436 Security
429 Security
437 --------
430 --------
438
431
439 You can protect your Notebook server with a simple singlepassword by
432 You can protect your Notebook server with a simple singlepassword by
440 setting the :attr:`NotebookApp.password` configurable. You can prepare a
433 setting the :attr:`NotebookApp.password` configurable. You can prepare a
441 hashed password using the function :func:`IPython.lib.security.passwd`:
434 hashed password using the function :func:`IPython.lib.security.passwd`:
442
435
443 .. sourcecode:: ipython
436 .. sourcecode:: ipython
444
437
445 In [1]: from IPython.lib import passwd
438 In [1]: from IPython.lib import passwd
446 In [2]: passwd()
439 In [2]: passwd()
447 Enter password:
440 Enter password:
448 Verify password:
441 Verify password:
449 Out[2]: 'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'
442 Out[2]: 'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'
450
443
451 .. note::
444 .. note::
452
445
453 :func:`~IPython.lib.security.passwd` can also take the password as a string
446 :func:`~IPython.lib.security.passwd` can also take the password as a string
454 argument. **Do not** pass it as an argument inside an IPython session, as it
447 argument. **Do not** pass it as an argument inside an IPython session, as it
455 will be saved in your input history.
448 will be saved in your input history.
456
449
457 You can then add this to your :file:`ipython_notebook_config.py`, e.g.::
450 You can then add this to your :file:`ipython_notebook_config.py`, e.g.::
458
451
459 # Password to use for web authentication
452 # Password to use for web authentication
460 c.NotebookApp.password = u'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'
453 c.NotebookApp.password = u'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'
461
454
462 When using a password, it is a good idea to also use SSL, so that your password
455 When using a password, it is a good idea to also use SSL, so that your password
463 is not sent unencrypted by your browser. You can start the notebook to
456 is not sent unencrypted by your browser. You can start the notebook to
464 communicate via a secure protocol mode using a self-signed certificate with the command::
457 communicate via a secure protocol mode using a self-signed certificate with the command::
465
458
466 $ ipython notebook --certfile=mycert.pem
459 $ ipython notebook --certfile=mycert.pem
467
460
468 .. note::
461 .. note::
469
462
470 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::
463 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::
471
464
472 $ openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem
465 $ openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem
473
466
474 Your browser will warn you of a dangerous certificate because it is
467 Your browser will warn you of a dangerous certificate because it is
475 self-signed. If you want to have a fully compliant certificate that will not
468 self-signed. If you want to have a fully compliant certificate that will not
476 raise warnings, it is possible (but rather involved) to obtain one for free,
469 raise warnings, it is possible (but rather involved) to obtain one for free,
477 `as explained in detailed in this tutorial`__.
470 `as explained in detailed in this tutorial`__.
478
471
479 .. __: http://arstechnica.com/security/news/2009/12/how-to-get-set-with-a-secure-sertificate-for-free.ars
472 .. __: http://arstechnica.com/security/news/2009/12/how-to-get-set-with-a-secure-sertificate-for-free.ars
480
473
481 Keep in mind that when you enable SSL support, you'll need to access the
474 Keep in mind that when you enable SSL support, you'll need to access the
482 notebook server over ``https://``, not over plain ``http://``. The startup
475 notebook server over ``https://``, not over plain ``http://``. The startup
483 message from the server prints this, but it's easy to overlook and think the
476 message from the server prints this, but it's easy to overlook and think the
484 server is for some reason non-responsive.
477 server is for some reason non-responsive.
485
478
486
479
487 Connecting to an existing kernel
480 Connecting to an existing kernel
488 ---------------------------------
481 ---------------------------------
489
482
490 The notebook server always prints to the terminal the full details of
483 The notebook server always prints to the terminal the full details of
491 how to connect to each kernel, with lines like::
484 how to connect to each kernel, with lines like::
492
485
493 [IPKernelApp] To connect another client to this kernel, use:
486 [IPKernelApp] To connect another client to this kernel, use:
494 [IPKernelApp] --existing kernel-3bb93edd-6b5a-455c-99c8-3b658f45dde5.json
487 [IPKernelApp] --existing kernel-3bb93edd-6b5a-455c-99c8-3b658f45dde5.json
495
488
496 This is the name of a JSON file that contains all the port and
489 This is the name of a JSON file that contains all the port and
497 validation information necessary to connect to the kernel. You can
490 validation information necessary to connect to the kernel. You can
498 manually start a Qt console with::
491 manually start a Qt console with::
499
492
500 ipython qtconsole --existing kernel-3bb93edd-6b5a-455c-99c8-3b658f45dde5.json
493 ipython qtconsole --existing kernel-3bb93edd-6b5a-455c-99c8-3b658f45dde5.json
501
494
502 and if you only have a single kernel running, simply typing::
495 and if you only have a single kernel running, simply typing::
503
496
504 ipython qtconsole --existing
497 ipython qtconsole --existing
505
498
506 will automatically find it (it will always find the most recently
499 will automatically find it (it will always find the most recently
507 started kernel if there is more than one). You can also request this
500 started kernel if there is more than one). You can also request this
508 connection data by typing ``%connect_info``; this will print the same
501 connection data by typing ``%connect_info``; this will print the same
509 file information as well as the content of the JSON data structure it contains.
502 file information as well as the content of the JSON data structure it contains.
510
503
511
504
512 Running a public notebook server
505 Running a public notebook server
513 --------------------------------
506 --------------------------------
514
507
515 If you want to access your notebook server remotely with just a web browser,
508 If you want to access your notebook server remotely with just a web browser,
516 here is a quick set of instructions. Start by creating a certificate file and
509 here is a quick set of instructions. Start by creating a certificate file and
517 a hashed password as explained above. Then, create a custom profile for the
510 a hashed password as explained above. Then, create a custom profile for the
518 notebook. At the command line, type::
511 notebook. At the command line, type::
519
512
520 ipython profile create nbserver
513 ipython profile create nbserver
521
514
522 In the profile directory, edit the file ``ipython_notebook_config.py``. By
515 In the profile directory, edit the file ``ipython_notebook_config.py``. By
523 default the file has all fields commented, the minimum set you need to
516 default the file has all fields commented, the minimum set you need to
524 uncomment and edit is here::
517 uncomment and edit is here::
525
518
526 c = get_config()
519 c = get_config()
527
520
528 # Kernel config
521 # Kernel config
529 c.IPKernelApp.pylab = 'inline' # if you want plotting support always
522 c.IPKernelApp.pylab = 'inline' # if you want plotting support always
530
523
531 # Notebook config
524 # Notebook config
532 c.NotebookApp.certfile = u'/absolute/path/to/your/certificate/mycert.pem'
525 c.NotebookApp.certfile = u'/absolute/path/to/your/certificate/mycert.pem'
533 c.NotebookApp.ip = '*'
526 c.NotebookApp.ip = '*'
534 c.NotebookApp.open_browser = False
527 c.NotebookApp.open_browser = False
535 c.NotebookApp.password = u'sha1:bcd259ccf...your hashed password here'
528 c.NotebookApp.password = u'sha1:bcd259ccf...your hashed password here'
536 # It's a good idea to put it on a known, fixed port
529 # It's a good idea to put it on a known, fixed port
537 c.NotebookApp.port = 9999
530 c.NotebookApp.port = 9999
538
531
539 You can then start the notebook and access it later by pointing your browser to
532 You can then start the notebook and access it later by pointing your browser to
540 ``https://your.host.com:9999`` with ``ipython notebook --profile=nbserver``.
533 ``https://your.host.com:9999`` with ``ipython notebook --profile=nbserver``.
541
534
542 Running with a different URL prefix
535 Running with a different URL prefix
543 -----------------------------------
536 -----------------------------------
544
537
545 The notebook dashboard (i.e. the default landing page with an overview
538 The notebook dashboard (i.e. the default landing page with an overview
546 of all your notebooks) typically lives at a URL path of
539 of all your notebooks) typically lives at a URL path of
547 "http://localhost:8888/". If you want to have it, and the rest of the
540 "http://localhost:8888/". If you want to have it, and the rest of the
548 notebook, live under a sub-directory,
541 notebook, live under a sub-directory,
549 e.g. "http://localhost:8888/ipython/", you can do so with
542 e.g. "http://localhost:8888/ipython/", you can do so with
550 configuration options like these (see above for instructions about
543 configuration options like these (see above for instructions about
551 modifying ``ipython_notebook_config.py``)::
544 modifying ``ipython_notebook_config.py``)::
552
545
553 c.NotebookApp.base_project_url = '/ipython/'
546 c.NotebookApp.base_project_url = '/ipython/'
554 c.NotebookApp.base_kernel_url = '/ipython/'
547 c.NotebookApp.base_kernel_url = '/ipython/'
555 c.NotebookApp.webapp_settings = {'static_url_prefix':'/ipython/static/'}
548 c.NotebookApp.webapp_settings = {'static_url_prefix':'/ipython/static/'}
556
549
557 Using a different notebook store
550 Using a different notebook store
558 --------------------------------
551 --------------------------------
559
552
560 By default the notebook server stores notebooks as files in the working
553 By default the notebook server stores notebooks as files in the working
561 directory of the notebook server, also known as the ``notebook_dir``. This
554 directory of the notebook server, also known as the ``notebook_dir``. This
562 logic is implemented in the :class:`FileNotebookManager` class. However, the
555 logic is implemented in the :class:`FileNotebookManager` class. However, the
563 server can be configured to use a different notebook manager class, which can
556 server can be configured to use a different notebook manager class, which can
564 store the notebooks in a different format. Currently, we ship a
557 store the notebooks in a different format. Currently, we ship a
565 :class:`AzureNotebookManager` class that stores notebooks in Azure blob
558 :class:`AzureNotebookManager` class that stores notebooks in Azure blob
566 storage. This can be used by adding the following lines to your
559 storage. This can be used by adding the following lines to your
567 ``ipython_notebook_config.py`` file::
560 ``ipython_notebook_config.py`` file::
568
561
569 c.NotebookApp.notebook_manager_class = 'IPython.html.services.notebooks.azurenbmanager.AzureNotebookManager'
562 c.NotebookApp.notebook_manager_class = 'IPython.html.services.notebooks.azurenbmanager.AzureNotebookManager'
570 c.AzureNotebookManager.account_name = u'paste_your_account_name_here'
563 c.AzureNotebookManager.account_name = u'paste_your_account_name_here'
571 c.AzureNotebookManager.account_key = u'paste_your_account_key_here'
564 c.AzureNotebookManager.account_key = u'paste_your_account_key_here'
572 c.AzureNotebookManager.container = u'notebooks'
565 c.AzureNotebookManager.container = u'notebooks'
573
566
574 In addition to providing your Azure Blob Storage account name and key, you will
567 In addition to providing your Azure Blob Storage account name and key, you will
575 have to provide a container name; you can use multiple containers to organize
568 have to provide a container name; you can use multiple containers to organize
576 your Notebooks.
569 your Notebooks.
577
570
578 .. _notebook_format:
571 .. _notebook_format:
579
572
580 Notebook JSON format
573 Notebook JSON format
581 ====================
574 ====================
582
575
583 Notebooks are JSON files with an ``.ipynb`` extension, formatted
576 Notebooks are JSON files with an ``.ipynb`` extension, formatted
584 as legibly as possible with minimal extra indentation and cell content broken
577 as legibly as possible with minimal extra indentation and cell content broken
585 across lines to make them reasonably friendly to use in version-control
578 across lines to make them reasonably friendly to use in version-control
586 workflows. You should be very careful if you ever manually edit this JSON
579 workflows. You should be very careful if you ever manually edit this JSON
587 data, as it is extremely easy to corrupt its internal structure and make the
580 data, as it is extremely easy to corrupt its internal structure and make the
588 file impossible to load. In general, you should consider the notebook as a
581 file impossible to load. In general, you should consider the notebook as a
589 file meant only to be edited by the IPython Notebook app itself, not for hand-editing.
582 file meant only to be edited by the IPython Notebook app itself, not for hand-editing.
590
583
591 .. note::
584 .. note::
592
585
593 Binary data such as figures are directly saved in the JSON file. This
586 Binary data such as figures are directly saved in the JSON file. This
594 provides convenient single-file portability, but means that the files can
587 provides convenient single-file portability, but means that the files can
595 be large; ``diff``s of binary data also are not very meaningful. Since the
588 be large; ``diff``s of binary data also are not very meaningful. Since the
596 binary blobs are encoded in a single line, they affect only one line of
589 binary blobs are encoded in a single line, they affect only one line of
597 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.
590 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.
598
591
599 The notebook server can also generate a pure Python version of your notebook,
592 The notebook server can also generate a pure Python version of your notebook,
600 using the ``File -> Download as`` menu option. The resulting ``.py`` file will
593 using the ``File -> Download as`` menu option. The resulting ``.py`` file will
601 contain all the code cells from your notebook verbatim, and all text cells
594 contain all the code cells from your notebook verbatim, and all text cells
602 prepended with a comment marker. The separation between code and text
595 prepended with a comment marker. The separation between code and text
603 cells is indicated with special comments and there is a header indicating the
596 cells is indicated with special comments and there is a header indicating the
604 format version. All output is stripped out when exporting to Python.
597 format version. All output is stripped out when exporting to Python.
605
598
606 Here is an example of the Python output from a simple notebook with one text cell and one code input cell::
599 Here is an example of the Python output from a simple notebook with one text cell and one code input cell::
607
600
608 # <nbformat>2</nbformat>
601 # <nbformat>2</nbformat>
609
602
610 # <markdowncell>
603 # <markdowncell>
611
604
612 # A text cell
605 # A text cell
613
606
614 # <codecell>
607 # <codecell>
615
608
616 print "Hello, IPython!"
609 print "Hello, IPython!"
617
610
618
611
619 Known issues
612 Known issues
620 ============
613 ============
621
614
622 When behind a proxy, especially if your system or browser is set to autodetect
615 When behind a proxy, especially if your system or browser is set to autodetect
623 the proxy, the Notebook app might fail to connect to the server's websockets,
616 the proxy, the Notebook app might fail to connect to the server's websockets,
624 and present you with a warning at startup. In this case, you need to configure
617 and present you with a warning at startup. In this case, you need to configure
625 your system not to use the proxy for the server's address.
618 your system not to use the proxy for the server's address.
626
619
627 In Firefox, for example, go to the Preferences panel, Advanced section,
620 In Firefox, for example, go to the Preferences panel, Advanced section,
628 Network tab, click 'Settings...', and add the address of the notebook server
621 Network tab, click 'Settings...', and add the address of the notebook server
629 to the 'No proxy for' field.
622 to the 'No proxy for' field.
630
623
631
624
632 .. _Markdown: http://daringfireball.net/projects/markdown/basics
625 .. _Markdown: http://daringfireball.net/projects/markdown/basics
General Comments 0
You need to be logged in to leave comments. Login now