From 20cd990c64386b1f2e433ab01f14c7e2a78178bb 2013-08-09 00:41:51 From: Paul Ivanov Date: 2013-08-09 00:41:51 Subject: [PATCH] major doc update for 1.0 release - added links to example notebooks on nbviewer - removde unnecessary file and parts of files - put old htmlnotebook.html redirect (for Notebook Help urls in 0.13.x) - moved working_remotely to public_server - re-arrangement of notebook connection stuff - more cross-referencing of documentation sections - made links to magic command explanation in tutorial - and many more changes... --- diff --git a/docs/source/_templates/htmlnotebook.html b/docs/source/_templates/htmlnotebook.html new file mode 100644 index 0000000..7133e91 --- /dev/null +++ b/docs/source/_templates/htmlnotebook.html @@ -0,0 +1,9 @@ + + + + Notebook page has move + + +

The notebook page has moved to this link.

+ + diff --git a/docs/source/conf.py b/docs/source/conf.py index dc90de7..0764a40 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -157,7 +157,9 @@ html_last_updated_fmt = '%b %d, %Y' # Additional templates that should be rendered to pages, maps page names to # template names. -#html_additional_pages = {} +html_additional_pages = { + 'interactive/htmlnotebook': 'htmlnotebook.html', +} # If false, no module index is generated. #html_use_modindex = True diff --git a/docs/source/install/install.rst b/docs/source/install/install.rst index a49da21..a6c9f5d 100644 --- a/docs/source/install/install.rst +++ b/docs/source/install/install.rst @@ -319,7 +319,7 @@ Dependencies for the IPython HTML notebook ========================================== The IPython notebook is a notebook-style web interface to IPython and can be -started withe command ``ipython notebook``. +started with the command ``ipython notebook``. pyzmq ----- diff --git a/docs/source/interactive/index.rst b/docs/source/interactive/index.rst index 43b8d8b..1fb9f7f 100644 --- a/docs/source/interactive/index.rst +++ b/docs/source/interactive/index.rst @@ -12,6 +12,6 @@ Using IPython for interactive work qtconsole notebook nbconvert - working_remotely + public_server diff --git a/docs/source/interactive/notebook.rst b/docs/source/interactive/notebook.rst index 9303b37..2a727b5 100644 --- a/docs/source/interactive/notebook.rst +++ b/docs/source/interactive/notebook.rst @@ -3,116 +3,116 @@ The IPython Notebook ==================== -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. +Introduction +------------ -.. seealso:: +The notebook extends the console-based approach to interactive computing in +a qualitatively new direction, providing a web-based application suitable for +capturing the whole computation process: developing, documenting, and +executing code, as well as communicating the results. The IPython notebook +combines two components: - :ref:`Installation requirements ` for the Notebook. +**A web application**: a browser-based tool for interactive authoring of +documents which combine explanatory text, mathematics, computations and their +rich media output. +**Notebook documents**: a representation of all content visible in the web +application, including inputs and outputs of the computations, explanatory +text, mathematics, images, and rich media representations of objects. -.. Basic structure -.. --------------- +.. seealso:: -Introduction ------------- + See the :ref:`installation documentation ` for directions + on how to install the notebook and its dependencies. -The IPython Notebook combines two components: -* **The IPython Notebook web application**: +Main features of the web application +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 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. +* In-browser editing for code, with automatic syntax highlighting, + indentation, and tab completion/introspection. -* **Notebook documents**: +* The ability to execute code from the browser, with the results of + computations attached to the code which generated them. - *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. +* Displaying the result of computation using rich media representations, such + as HTML, LaTeX, PNG, SVG, etc. For example, publication-quality figures + rendered by the matplotlib_ library, can be included inline. -Since the similarity in names can lead to some confusion, in this -documentation we will use capitalization of the word "notebook" to -distinguish the Notebook app and notebook 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. +* In-browser editing for rich text using the Markdown_ markup language, which + can provide commentary for the code, is not limited to plain text. -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 corresponding notebook document, since they are -really one and the same concept (we could say that they are "isomorphic"). +* The ability to easily include mathematical notation within markdown cells + using LaTeX, and rendered natively by MathJax_. -Main features of the IPython Notebook web app -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -The main features of the IPython Notebook app include: +.. _MathJax: http://www.mathjax.org/ -* 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. +Notebook documents +~~~~~~~~~~~~~~~~~~ +Notebook documents contains the inputs and outputs of a interactive session as +well as additional text that accompanies the code but is not meant for +execution. In this way, notebook files can serve as a complete computational +record of a session, interleaving executable code with explanatory text, +mathematics, and rich representations of resulting objects. These documents +are internally JSON_ files and are saved with the ``.ipynb`` extension. Since +JSON is a plain text format, they can be version-controlled and shared with +colleagues. + +.. _JSON: http://en.wikipedia.org/wiki/JSON -* Mathematics is easily included within the Markdown using LaTeX notation, and - rendered natively by MathJax_. +Notebooks may be exported to a range of static formats, including HTML (for +example, for blog posts), reStructeredText, LaTeX, PDF, and slide shows, via +the new :ref:`nbconvert ` command. -* Displays rich data representations (e.g. HTML / LaTeX / SVG) as the result - of computations. +Furthermore, any ``.ipynb`` notebook document available from a public +URL can be shared via the `IPython Notebook Viewer `_ (nbviewer_). +This service loads the notebook document from the URL and renders it as a +static web page. The results may thus be shared with a colleague, or as a +public blog post, without other users needing to install IPython themselves. +In effect, nbviewer_ is simply :ref:`nbconvert ` as a web service, +so you can do your own static conversions with nbconvert, without relying on +nbviewer. -* 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 +.. seealso:: + :ref:`Details on the notebook JSON file format ` + -Notebook documents -~~~~~~~~~~~~~~~~~~ +Starting the notebook server +---------------------------- -Notebook document files are simple JSON_ files with the -extension ``.ipynb``. -Since JSON is just plain text, they can be easily version-controlled and shared with colleagues. -The notebook stores a *complete*, *reproducible*, *one-to-one* copy of the state of the -computational state as it is inside the Notebook app. All computations -carried out, and the corresponding results obtained, can be combined in -a literate way, interleaving executable code with rich text, mathematics, -and rich representations of objects. +You can start running a notebook server from the command line using the +following command:: -.. _JSON: http://en.wikipedia.org/wiki/JSON + ipython notebook -Notebooks may easily be exported to a range of static formats, including -HTML (for example, for blog posts), PDF and slide shows, -via the new nbconvert_ command. +This will print some information about the notebook server in your console, +and open a web browser to the URL of the web application (by default, +``http://127.0.0.1:8888``). -Furthermore, any ``.ipynb`` notebook document available from a public -URL can be shared via the `IPython Notebook Viewer `_ service. -This service loads the notebook document from the URL and renders -it as a static web page. The results may thus be shared with a -colleague, or as a public blog post, without other users needing to install -IPython themselves. NbViewer is simply nbconvert_ as a simple webservice. +The landing page of the IPython notebook web application, the **dashboard**, +shows the notebooks currently available in the notebook directory (by default, +the directory from which the notebook server was started). -See the :ref:`installation documentation ` for directions on -how to install the notebook and its dependencies. +You can create new notebooks from the dashboard with the ``New Notebook`` +button, or open existing ones by clicking on their name. You can also drag +and drop ``.ipynb`` notebooks and standard ``.py`` Python source code files +into the notebook list area. -.. _nbconvert: ./nbconvert.html +When starting a notebook server from the command line, you can also open a +particular notebook directly, bypassing the dashboard, with ``ipython notebook +my_notebook.ipynb``. The ``.ipynb`` extension is assumed if no extension is +given. + +When you are inside an open notebook, the `File | Open...` menu option will +open the dashboard in a new browser tab, to allow you to open another notebook +from the notebook directory or to create a new notebook. -.. _nbviewer: http://nbviewer.ipython.org .. note:: @@ -121,145 +121,122 @@ how to install the notebook and its dependencies. notebook server starts on port 8888, and later notebook servers search for ports near that one. You can also manually specify the port with the ``--port`` option. - -Basic workflow in the IPython Notebook web app ----------------------------------------------- +Creating a new notebook document +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Starting up -~~~~~~~~~~~~ +A new notebook may be created at any time, either from the dashboard, or using +the `File | New` menu option from within an active notebook. The new notebook +is created within the same directory and will open in a new browser tab. It +will also be reflected as a new entry in the notebook list on the dashboard. -You can start running the Notebook web app using the following command:: - $ ipython notebook +Opening notebooks +~~~~~~~~~~~~~~~~~ +An open notebook has **exactly one** interactive session connected to an +:ref:`IPython kernel `, which will execute code sent by the user +and communicate back results. This kernel remains active if the web browser +window is closed, and reopening the same notebook from the dashboard will +reconnect the web application to the same kernel. In the dashboard, notebooks +with an active kernel have a ``Shutdown`` button next to them, whereas +notebooks without an active kernel have a ``Delete`` button in its place. -(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.) +Other clients may connect to the same underlying IPython kernel. +The notebook server always prints to the terminal the full details of +how to connect to each kernel, with messages such as the following:: -The landing page of the IPython Notebook application, the *dashboard*, shows -the notebooks currently available in the *notebook directory* (By default, the directory -from which the notebook was started). -You can create new notebooks from the dashboard with the ``New Notebook`` -button, or open existing ones by clicking on their name. -You can also drag and drop ``.ipynb`` notebooks and standard ``.py`` Python -source code files into the notebook list area. + [NotebookApp] Kernel started: 87f7d2c0-13e3-43df-8bb8-1bd37aaf3373 +This long string is the kernel's ID which is sufficient for getting the +information necessary to connect to the kernel. You can also request this +connection data by running the ``%connect_info`` :ref:`magic +`. This will print the same ID information as well as the +content of the JSON data structure it contains. -You can open an existing notebook directly, without having to go via the -dashboard, with:: +You can then, for example, manually start a Qt console connected to the *same* +kernel from the command line, by passing a portion of the ID:: - ipython notebook my_notebook + $ ipython qtconsole --existing 87f7d2c0 -The ``.ipynb`` extension is assumed if no extension is given. - -The `File | Open...` menu option will open the dashboard in a new browser tab, -to allow you to select a current notebook -from the notebook directory or to create a new notebook. +Without an ID, ``--existing`` will connect to the most recently +started kernel. This can also be done by running the ``%qtconsole`` +:ref:`magic ` in the notebook. +.. seealso:: + :ref:`ipythonzmq` Notebook user interface -~~~~~~~~~~~~~~~~~~~~~~~ - -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*. +----------------------- -Notebook title -^^^^^^^^^^^^^^ -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. +When you create a new notebook document, you will be presented with the +**notebook name**, a **menu bar**, a **toolbar** and an empty **code +cell**. -Menu bar -^^^^^^^^ -The menu bar presents different options that may be used to manipulate the way -the Notebook functions. +**notebook name**: The name of the notebook document is displayed at the top +of the page, next to the ``IP[y]: Notebook`` logo. This name reflects the name +of the ``.ipynb`` notebook document file. Clicking on the notebook name +brings up a dialog which allows you to rename it. Thus, renaming a notebook +from "Untitled0" to "My first notebook" in the browser, renames the +``Untitled0.ipynb`` file to ``My first notebook.ipynb``. -Toolbar -^^^^^^^ -The tool bar gives a quick way of accessing the most-used operations within -the Notebook, by clicking on an icon. +**menu bar**: The menu bar presents different options that may be used to +manipulate the way the notebook functions. +**toolbar**: The tool bar gives a quick way of performing the most-used +operations within the notebook, by clicking on an icon. -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 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. +**code cell**: the default type of cell, read on for an explanation of cells Structure of a notebook document -------------------------------- -Input cells -~~~~~~~~~~~ -Input cells are at the core of the functionality of the IPython Notebook. -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. - -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. - - - -Input cell types -~~~~~~~~~~~~~~~~ -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: - -* **code**: :kbd:`Ctrl-m y` -* **markdown**: :kbd:`Ctrl-m m` -* **raw**: :kbd:`Ctrl-m t` -* **heading**: :kbd:`Ctrl-m 1` - :kbd:`Ctrl-m 6` - -Upon initial creation, each input cell is by default a code cell. +The notebook consists of a sequence of cells. A cell is a multi-line +text input field, and its contents can be executed by using +:kbd:`Shift-Enter`, or by clicking either the "Play" button the toolbar, or +`Cell | Run` in the menu bar. The execution behavior of a cell is determined +the cell's type. There are four types of cells: **code cells**, **markdown +cells**, **raw cells** and **heading cells**. Every cell starts off +being a **code cell**, but its type can be changed by using a dropdown on the +toolbar (which will be "Code", initially), or via :ref:`keyboard shortcuts +`. Code cells -^^^^^^^^^^ -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 -*output*. If this output is of a textual nature, it is placed into a -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 +~~~~~~~~~~ +A *code cell* allows you to edit and write new code, with full syntax +highlighting and tab completion. By default, the language associated to a code +cell is Python, but other languages, such as ``Julia`` and ``R``, can be +handled using :ref:`cell magic commands `. + +When a code cell is executed, code that it contains is sent to the kernel +associated with the notebook. The results that are returned from this +computation are then displayed in the notebook as the cell's *output*. The +output is not limited to text, with many other possible forms of output are +also possible, including ``matplotlib`` figures and HTML tables (as used, for +example, in the ``pandas`` data analysis package). This is known as IPython's *rich display* capability. +.. seealso:: + + `Basic Output`_ example notebook + + `Rich Display System`_ example notebook Markdown cells -^^^^^^^^^^^^^^ +~~~~~~~~~~~~~~ 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 +called *Markdown cells*. The Markdown language provides a simple way to perform this text markup, that is, to specify which parts of the text should be emphasized (italics), bold, form lists, etc. -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. +When a Markdown cell is executed, the Markdown code is converted into +the corresponding formatted 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 @@ -276,17 +253,21 @@ Standard mathematics environments defined by LaTeX and AMS-LaTeX (the 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 -nbconvert_ to output to LaTeX). +the IPython session. + +.. seealso:: -Raw input cells -~~~~~~~~~~~~~~~ + `Markdown Cells`_ example notebook -*Raw* input cells provide a place in which you can write *output* directly. -Raw cells are not evaluated by the Notebook, and have no output. -When passed through nbconvert, Raw cells arrive in the destination format unmodified, -allowing you to type full latex into a raw cell, which will only be rendered -by latex after conversion by nbconvert. +Raw cells +~~~~~~~~~ + +*Raw* cells provide a place in which you can write *output* directly. +Raw cells are not evaluated by the notebook. +When passed through :ref:`nbconvert `, raw cells arrive in the +destination format unmodified. For example, this allows you to type full LaTeX +into a raw cell, which will only be rendered by LaTeX after conversion by +nbconvert. Heading cells ~~~~~~~~~~~~~ @@ -294,10 +275,9 @@ Heading cells You can provide a conceptual structure for your computational document as a whole using different levels of headings; there are 6 levels available, from level 1 (top level) down to level 6 (paragraph). These can be used later for -constructing tables of contents, etc. - -As with Markdown cells, a heading input cell is replaced by a rich text -rendering of the heading when the cell is executed. +constructing tables of contents, etc. As with Markdown cells, a heading +cell is replaced by a rich text rendering of the heading when the cell is +executed. Basic workflow @@ -306,42 +286,36 @@ Basic workflow The normal workflow in a notebook is, then, quite similar to a standard IPython session, with the difference that you can edit cells in-place multiple times until you obtain the desired results, rather than having to -rerun separate scripts with the ``%run`` magic command. (Magic commands do, -however, also work in the notebook; see below). +rerun separate scripts with the ``%run`` magic command. + Typically, you will work on a computational problem in pieces, organizing related ideas into cells and moving forward once previous parts work correctly. This is much more convenient for interactive exploration than breaking up a computation into scripts that must be executed together, as was -previously necessary, especially if parts of them take a long time to run +previously necessary, especially if parts of them take a long time to run. 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. +taking too long to complete. This may be done with the `Kernel | Interrupt` +menu option, or the :kbd:`Ctrl-m 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. +process, with the `Kernel | Restart` menu option or :kbd:`Ctrl-m .` +shortcut. -A notebook may be downloaded in either ``.ipynb`` or raw ``.py`` form from the -menu option ``File | Download as``. Choosing the ``.py`` option downloads a -Python ``.py`` script, in which all output has been removed and the content of -Markdown cells in comment areas. See ref:`below ` for more -details on the notebook format. +A notebook may be downloaded in either a ``.ipynb`` or ``.py`` file from the +menu option `File | Download as`. Choosing the ``.py`` option downloads a +Python ``.py`` script, in which all rich output has been removed and the +content of markdown cells have been inserted as comments. -.. warning:: +.. seealso:: - While in simple cases you can "roundtrip" a notebook to Python, edit the - 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 - 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. + `Running Code in the IPython Notebook`_ example notebook + + `Basic Output`_ example notebook + :ref:`a warning about doing "roundtrip" conversions `. + +.. _keyboard-shortcuts: Keyboard shortcuts ~~~~~~~~~~~~~~~~~~ @@ -351,10 +325,10 @@ to remember are the following: * :kbd:`Shift-Enter`: run cell 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 + below. If :kbd:`Shift-Enter` is invoked on the last 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. :kbd:`Shift-Enter` is equivalent to clicking the + the current cell. :kbd:`Shift-Enter` is equivalent to clicking the ``Cell | Run`` menu item. * :kbd:`Ctrl-Enter`: run cell in-place @@ -367,7 +341,7 @@ to remember are the following: to be saved in the notebook. * :kbd:`Alt-Enter`: run cell, insert below - Executes the current cell, shows the output, and inserts a *new* input + Executes the current cell, shows the output, and inserts a *new* cell between the current cell and the cell below (if one exists). This is thus a shortcut for the sequence :kbd:`Shift-Enter`, :kbd:`Ctrl-m a`. (:kbd:`Ctrl-m a` adds a new cell above the current one.) @@ -419,96 +393,19 @@ Ctrl-m h show keyboard shortcuts -Magic commands --------------- -Magic commands, or *magics*, are commands for controlling IPython itself. -They all begin with ``%`` and are entered into code input cells; the code -cells are executed as usual with :kbd:`Shift-Enter`. - -The magic commands call special functions defined by IPython which manipulate -the computational state in certain ways. - -There are two types of magics: - - - **line magics**: - - 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. - - - **cell magics**: - - These begin with ``%%`` and operate on the *entire* remaining contents - of the code cell. - -Line magics -~~~~~~~~~~~ -Some of the available line magics are the following: - - * ``%load filename``: - - 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 - - * ``%config``: - - Configuration of the IPython Notebook - - * ``%lsmagic``: - - Provides a list of all available magic commands - -Cell magics -~~~~~~~~~~~ - - * ``%%latex``: - - Renders the entire contents of the cell in LaTeX, without needing to use - explicit LaTeX delimiters. - - * ``%%bash``: - - 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. - - * ``%%file filename``: - - Writes the contents of the cell to the file ``filename``. - **Caution**: The file is over-written without warning! - - * ``%%R``: - - 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. - - - -Several of the cell magics provide functionality to manipulate the filesystem -of a remote server to which you otherwise do not have access. Plotting -------- -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. +One major feature of the notebook is the ability to display plots that are the +output of running code cells. IPython is designed to work seamlessly with the +matplotlib_ plotting library to provide this functionality. To set this up, before any plotting is performed you must execute the -``%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. +``%matplotlib`` :ref:`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. If the ``%matplotlib`` magic is called without an argument, the output of a plotting command is displayed using the default ``matplotlib`` @@ -517,25 +414,24 @@ requested using, for example:: %matplotlib gtk -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:: +A particularly interesting backend, provided by IPython, is the ``inline`` +backend. This is available only for the IPython Notebook and the +:ref:`IPython QtConsole `. It can be invoked as follows:: %matplotlib inline -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. +With this backend, the output of plotting commands is displayed *inline* +within the notebook, directly below the code cell that produced it. The +resulting plots will then also be stored in the notebook document. -.. _reproducibility: https://en.wikipedia.org/wiki/Reproducibility +.. seealso:: + `Plotting with Matplotlib`_ example notebook Configuring the IPython Notebook -------------------------------- -The IPython Notebook can be run with a variety of command line arguments. +The notebook server can be run with a variety of command line arguments. To see a list of available options enter:: $ ipython notebook --help @@ -555,12 +451,16 @@ on available options, use:: .. seealso:: :ref:`config_overview`, in particular :ref:`Profiles`. + + :ref:`notebook_security` + + :ref:`notebook_public_server` Importing ``.py`` files ----------------------- -``.py`` files will be imported into the IPython Notebook as a notebook with +``.py`` files will be imported as a notebook with the same basename, but an ``.ipynb`` extension, located in the notebook 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 @@ -569,18 +469,18 @@ individual cells using the ``Edit | Split Cell`` menu option, or the Note that ``.py`` scripts obtained from a notebook document using nbconvert_ maintain the structure of the notebook in comments. Reimporting such a -script back into the Notebook will preserve this structxure. +script back into a notebook will preserve this structure. +.. _note_about_roundtrip: .. warning:: - You can "roundtrip" a notebook to Python, by exporting the - notebook to a ``.py`` script, editing the script, and then importing it back - into the Notebook without loss of main content. However, - in general this is *not guaranteed* to work. First, there is extra metadata - saved in the notebook that may not be saved to the ``.py`` format. Second, - 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 + While in simple cases you can "roundtrip" a notebook to Python, edit the + 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 + 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 @@ -588,3 +488,5 @@ script back into the Notebook will preserve this structxure. .. seealso:: :ref:`notebook_format` + +.. include:: ../links.txt diff --git a/docs/source/interactive/working_remotely.rst b/docs/source/interactive/public_server.rst similarity index 77% rename from docs/source/interactive/working_remotely.rst rename to docs/source/interactive/public_server.rst index 5dcbcd2..2f692fd 100644 --- a/docs/source/interactive/working_remotely.rst +++ b/docs/source/interactive/public_server.rst @@ -1,13 +1,16 @@ .. _working_remotely.txt -Working remotely -================ +Running a notebook server +========================= -The IPython Notebook web app is based on a server-client structure. -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. +The :ref:`IPython notebook ` web-application is based on a +server-client structure. This server uses a :ref:`two-process kernel +architecture ` based on ZeroMQ_, as well as Tornado_ for serving +HTTP requests. By default, a notebook server runs on http://127.0.0.1:8888/ +and is accessible only from `localhost`. This document describes how you can +:ref:`secure a notebook server ` and how to :ref:`run it on +a public interface `. .. _ZeroMQ: http://zeromq.org @@ -16,10 +19,10 @@ underlying IPython kernel; see below. .. _notebook_security: -Security --------- +Notebook security +----------------- -You can protect your Notebook server with a simple single password by +You can protect your notebook server with a simple single password by setting the :attr:`NotebookApp.password` configurable. You can prepare a hashed password using the function :func:`IPython.lib.security.passwd`: @@ -65,8 +68,7 @@ self-signed. If you want to have a fully compliant certificate that will not raise warnings, it is possible (but rather involved) to obtain one, as explained in detail in `this tutorial`__. -.. __: http://arstechnica.com/security/news/2009/12/how-to-get-set-with-a- -secure-sertificate-for-free.ars +.. __: http://arstechnica.com/security/news/2009/12/how-to-get-set-with-a-secure-sertificate-for-free.ars Keep in mind that when you enable SSL support, you will need to access the notebook server over ``https://``, not over plain ``http://``. The startup @@ -74,32 +76,7 @@ message from the server prints this, but it is easy to overlook and think the server is for some reason non-responsive. -Connecting to an existing kernel ---------------------------------- - -The notebook server always prints to the terminal the full details of -how to connect to each kernel, with messages such as the following:: - - [IPKernelApp] To connect another client to this kernel, use: - [IPKernelApp] --existing kernel-3bb93edd-6b5a-455c-99c8-3b658f45dde5.json - -This long string is the name of a JSON file that contains all the port and -validation information necessary to connect to the kernel. You can then, for -example, manually start a Qt console connected to the *same* kernel with:: - - $ ipython qtconsole --existing - kernel-3bb93edd-6b5a-455c-99c8-3b658f45dde5.json - -If you have only a single kernel running, simply typing:: - - $ ipython qtconsole --existing - -will automatically find it. (It will always find the most recently -started kernel if there is more than one.) You can also request this -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. - +.. _notebook_public_server: Running a public notebook server -------------------------------- @@ -152,8 +129,8 @@ modifying ``ipython_notebook_config.py``):: Using a different notebook store -------------------------------- -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 +By default, the notebook server stores the notebook documents that it saves as +files in the working directory of the notebook server, 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 @@ -178,9 +155,9 @@ Known issues ------------ When behind a proxy, especially if your system or browser is set to autodetect -the proxy, the Notebook app might fail to connect to the server's websockets, -and present you with a warning at startup. In this case, you need to configure -your system not to use the proxy for the server's address. +the proxy, the notebook web application might fail to connect to the server's +websockets, and present you with a warning at startup. In this case, you need +to configure your system not to use the proxy for the server's address. For example, in Firefox, go to the Preferences panel, Advanced section, Network tab, click 'Settings...', and add the address of the notebook server diff --git a/docs/source/interactive/tutorial.rst b/docs/source/interactive/tutorial.rst index 011beae..974a637 100644 --- a/docs/source/interactive/tutorial.rst +++ b/docs/source/interactive/tutorial.rst @@ -8,12 +8,27 @@ You don't need to know anything beyond Python to start using IPython – just ty commands as you would at the standard Python prompt. But IPython can do much more than the standard prompt. Some key features are described here. For more information, check the :ref:`tips page `, or look at examples in the -`IPython cookbook `_. +`IPython cookbook `_. If you've never used Python before, you might want to look at `the official tutorial `_ or an alternative, `Dive into Python `_. +The four most helpful commands +=============================== + +The four most helpful commands, as well as their brief description, is shown +to you in a banner, every time you start IPython: + +========== ========================================================= +command description +========== ========================================================= +? Introduction and overview of IPython's features. +%quickref Quick reference. +help Python's own help system. +object? Details about 'object', use 'object??' for extra details. +========== ========================================================= + Tab completion ============== @@ -31,16 +46,19 @@ including docstrings, function definition lines (for call arguments) and constructor details for classes. To get specific information on an object, you can use the magic commands ``%pdoc``, ``%pdef``, ``%psource`` and ``%pfile`` +.. _magics_explained: + Magic functions =============== IPython has a set of predefined 'magic functions' that you can call with a command line style syntax. There are two kinds of magics, line-oriented and -cell-oriented. Line magics are prefixed with the ``%`` character and work much +cell-oriented. **Line magics** are prefixed with the ``%`` character and work much like OS command-line calls: they get as an argument the rest of the line, where -arguments are passed without parentheses or quotes. Cell magics are prefixed -with a double ``%%``, and they are functions that get as an argument not only -the rest of the line, but also the lines below it in a separate argument. +arguments are passed without parentheses or quotes. **Cell magics** are +prefixed with a double ``%%``, and they are functions that get as an argument +not only the rest of the line, but also the lines below it in a separate +argument. The following examples show how to call the builtin ``timeit`` magic, both in line and cell mode:: @@ -58,34 +76,41 @@ The builtin magics include: - Functions that work with code: ``%run``, ``%edit``, ``%save``, ``%macro``, ``%recall``, etc. - Functions which affect the shell: ``%colors``, ``%xmode``, ``%autoindent``, - etc. -- Other functions such as ``%reset``, ``%timeit`` or ``%paste``. + ``%automagic``, etc. +- Other functions such as ``%reset``, ``%timeit``, ``%%file``, ``%load``, or + ``%paste``. -You can always call them using the % prefix, and if you're calling a line magic -on a line by itself, you can omit even that (cell magics must always have the -``%%`` prefix):: +You can always call them using the ``%`` prefix, and if you're calling a line +magic on a line by itself, you can omit even that:: run thescript.py +You can toggle this behavior by running the ``%automagic`` magic. Cell magics +must always have the ``%%`` prefix. + A more detailed explanation of the magic system can be obtained by calling ``%magic``, and for more details on any magic function, call ``%somemagic?`` to read its docstring. To see all the available magic functions, call ``%lsmagic``. +.. seealso:: + + `Cell magics`_ example notebook + Running and Editing ------------------- -The %run magic command allows you to run any python script and load all of its -data directly into the interactive namespace. Since the file is re-read from -disk each time, changes you make to it are reflected immediately (unlike -imported modules, which have to be specifically reloaded). IPython also includes -:ref:`dreload `, a recursive reload function. +The ``%run`` magic command allows you to run any python script and load all of +its data directly into the interactive namespace. Since the file is re-read +from disk each time, changes you make to it are reflected immediately (unlike +imported modules, which have to be specifically reloaded). IPython also +includes :ref:`dreload `, a recursive reload function. -%run has special flags for timing the execution of your scripts (-t), or for -running them under the control of either Python's pdb debugger (-d) or +``%run`` has special flags for timing the execution of your scripts (-t), or +for running them under the control of either Python's pdb debugger (-d) or profiler (-p). -The %edit command gives a reasonable approximation of multiline editing, +The ``%edit`` command gives a reasonable approximation of multiline editing, by invoking your favorite editor on the spot. IPython will execute the code you type in there as if it were typed interactively. @@ -153,11 +178,12 @@ visited directories and allows you to go to any previously visited one. Configuration ============= -Much of IPython can be tweaked through configuration. To get started, use the -command ``ipython profile create`` to produce the default config files. These -will be placed in :file:`~/.ipython/profile_default` or -:file:`~/.config/ipython/profile_default`, and contain comments explaining what -the various options do. +Much of IPython can be tweaked through :ref:`configuration `. +To get started, use the command ``ipython profile create`` to produce the +default config files. These will be placed in +:file:`~/.ipython/profile_default` or +:file:`~/.config/ipython/profile_default`, and contain comments explaining +what the various options do. Profiles allow you to use IPython for different tasks, keeping separate config files and history for each one. More details in :ref:`the profiles section @@ -173,7 +199,4 @@ as the IPython shell is constructed, before any other code or scripts you have specified. The files will be run in order of their names, so you can control the ordering with prefixes, like ``10-myimports.py``. -.. note:: - - Automatic startup files are new in IPython 0.12. Use InteractiveShellApp.exec_files - in :file:`ipython_config.py` for similar behavior in 0.11. +.. include:: ../links.txt diff --git a/docs/source/links.txt b/docs/source/links.txt index f662383..1e8f6fe 100644 --- a/docs/source/links.txt +++ b/docs/source/links.txt @@ -23,6 +23,7 @@ .. _ipython_github_repo: http://github.com/ipython/ipython/ .. _ipython_downloads: http://ipython.org/download.html .. _ipython_pypi: http://pypi.python.org/pypi/ipython +.. _nbviewer: http://nbviewer.ipython.org .. _ZeroMQ: http://zeromq.org @@ -46,7 +47,7 @@ .. _numpy: http://numpy.scipy.org .. _scipy: http://www.scipy.org .. _scipy_conference: http://conference.scipy.org -.. _matplotlib: http://matplotlib.sourceforge.net +.. _matplotlib: http://matplotlib.org .. _pythonxy: http://www.pythonxy.com .. _ETS: http://code.enthought.com/projects/tool-suite.php .. _EPD: http://www.enthought.com/products/epd.php @@ -72,4 +73,29 @@ .. _indefero: http://www.indefero.net .. _git: http://git-scm.com .. _github: http://github.com -.. _MarkDown: http://daringfireball.net/projects/markdown/ +.. _Markdown: http://daringfireball.net/projects/markdown/syntax + +.. _Running Code in the IPython Notebook: notebook_p1_ +.. _notebook_p1: http://nbviewer.ipython.org/urls/raw.github.com/ipython/ipython/1.x/examples/notebooks/Part%25201%2520-%2520Running%2520Code.ipynb + +.. _Basic Output: notebook_p2_ +.. _notebook_p2: http://nbviewer.ipython.org/urls/raw.github.com/ipython/ipython/1.x/examples/notebooks/Part%202%20-%20Basic%20Output.ipynb + +.. _Plotting with Matplotlib: notebook_p3_ +.. _notebook_p3: http://nbviewer.ipython.org/urls/raw.github.com/ipython/ipython/1.x/examples/notebooks/Part%203%20-%20Plotting%20with%20Matplotlib.ipynb + +.. _Markdown Cells: notebook_p4 +.. _notebook_p4: http://nbviewer.ipython.org/urls/raw.github.com/ipython/ipython/1.x/examples/notebooks/Part%204%20-%20Markdown%20Cells.ipynb + +.. _Rich Display System: notebook_p5_ +.. _notebook_p5: http://nbviewer.ipython.org/urls/raw.github.com/ipython/ipython/1.x/examples/notebooks/Part%205%20-%20Rich%20Display%20System.ipynb + +.. _notebook_custom_display: http://nbviewer.ipython.org/urls/raw.github.com/ipython/ipython/1.x/examples/notebooks/Custom%20Display%20Logic.ipynb + +.. _Frontend/Kernel Model: notebook_two_proc_ +.. _notebook_two_proc: http://nbviewer.ipython.org/urls/raw.github.com/ipython/ipython/1.x/examples/notebooks/Frontend-Kernel%20Model.ipynb + +.. _Cell magics: notebook_cell_magics_ +.. _notebook_cell_magics: http://nbviewer.ipython.org/urls/raw.github.com/ipython/ipython/1.x/examples/notebooks/Cell%20Magics.ipynb + + diff --git a/docs/source/overview.rst b/docs/source/overview.rst index dbbfd5a..a4385bb 100644 --- a/docs/source/overview.rst +++ b/docs/source/overview.rst @@ -18,9 +18,9 @@ interactive and exploratory computing. To support this goal, IPython has three main components: * An enhanced interactive Python shell. -* A decoupled two-process communication model, which allows for multiple - clients to connect to a computation kernel, most notably the web-based - :ref:`notebook ` +* A decoupled :ref:`two-process communication model `, which + allows for multiple clients to connect to a computation kernel, most notably + the web-based :ref:`notebook ` * An architecture for interactive parallel computing. All of IPython is open source (released under the revised BSD license). @@ -197,7 +197,7 @@ Decoupled two-process model IPython has abstracted and extended the notion of a traditional *Read-Evaluate-Print Loop* (REPL) environment by decoupling the *evaluation* -into its own process. We call this process a kernel: it receives execution +into its own process. We call this process a **kernel**: it receives execution instructions from clients and communicates the results back to them. This decoupling allows us to have several clients connected to the same @@ -222,6 +222,10 @@ You can read more about using :ref:`ipython qtconsole `, and ` which documents the protocol for communication between kernels and clients. +.. seealso:: + + `Frontend/Kernel Model`_ example notebook + Interactive parallel computing ============================== @@ -283,3 +287,4 @@ IPython is known to work on the following operating systems: See :ref:`here ` for instructions on how to install IPython. +.. include:: links.txt