##// END OF EJS Templates
Implement a couple of suggestions from @jhamrick
Thomas Kluyver -
Show More
@@ -1,89 +1,96 b''
1 How IPython Works
1 How IPython works
2 =================
2 =================
3
3
4 Terminal IPython
4 Terminal IPython
5 ----------------
5 ----------------
6
6
7 When you type ``ipython``, you get the original IPython interface, running in
7 When you type ``ipython``, you get the original IPython interface, running in
8 the terminal. It does something like this::
8 the terminal. It does something like this::
9
9
10 while True:
10 while True:
11 code = input(">>> ")
11 code = input(">>> ")
12 exec(code)
12 exec(code)
13
13
14 Of course, it's much more complicated, because it has to deal with multi-line
14 Of course, it's much more complicated, because it has to deal with multi-line
15 code, tab completion using :mod:`readline`, magic commands, and so on. But the
15 code, tab completion using :mod:`readline`, magic commands, and so on. But the
16 model is like that: prompt the user for some code, and when they've entered it,
16 model is like that: prompt the user for some code, and when they've entered it,
17 exec it in the same process.
17 exec it in the same process.
18
18
19 The IPython Kernel
19 The IPython Kernel
20 ------------------
20 ------------------
21
21
22 All the other interfaces—the Notebook, the Qt console, ``ipython console`` in
22 All the other interfaces—the Notebook, the Qt console, ``ipython console`` in
23 the terminal, and third party interfaces—use the IPython Kernel. This is a
23 the terminal, and third party interfaces—use the IPython Kernel. This is a
24 separate process which is responsible for running user code, and things like
24 separate process which is responsible for running user code, and things like
25 computing possible completions. Frontends communicate with it using JSON
25 computing possible completions. Frontends communicate with it using JSON
26 messages sent over ZeroMQ sockets; the protocol they use is described in
26 messages sent over `ZeroMQ <http://zeromq.org/>`_ sockets; the protocol they use is described in
27 :doc:`messaging`.
27 :doc:`messaging`.
28
28
29 The core execution machinery for the kernel is shared with terminal IPython:
29 The core execution machinery for the kernel is shared with terminal IPython:
30
30
31 .. image:: figs/ipy_kernel_and_terminal.png
31 .. image:: figs/ipy_kernel_and_terminal.png
32
32
33 A kernel process can be connected to more than one frontend simultaneously. In
33 A kernel process can be connected to more than one frontend simultaneously. In
34 this case, the different frontends will have access to the same variables.
34 this case, the different frontends will have access to the same variables.
35
35
36 .. TODO: Diagram illustrating this?
36 .. TODO: Diagram illustrating this?
37
37
38 This design was intended to allow easy development of different frontends based
38 This design was intended to allow easy development of different frontends based
39 on the same kernel, but it also made it possible to support new languages in the
39 on the same kernel, but it also made it possible to support new languages in the
40 same frontends, by developing kernels in those languages, and we are refining
40 same frontends, by developing kernels in those languages, and we are refining
41 IPython to make that more practical.
41 IPython to make that more practical.
42
42
43 Today, there are two ways to develop a kernel for another language. Wrapper
43 Today, there are two ways to develop a kernel for another language. Wrapper
44 kernels reuse the communications machinery from IPython, and implement only the
44 kernels reuse the communications machinery from IPython, and implement only the
45 core execution part. Native kernels implement execution and communications in
45 core execution part. Native kernels implement execution and communications in
46 the target language:
46 the target language:
47
47
48 .. image:: figs/other_kernels.png
48 .. image:: figs/other_kernels.png
49
49
50 Wrapper kernels are easier to write quickly for languages that have good Python
51 wrappers, like `Oct2Py <http://blink1073.github.io/oct2py/>`_ for Octave, or
52 languages where it's impractical to implement the communications machinery, like
53 `bash_kernel <https://pypi.python.org/pypi/bash_kernel>`_. Native kernels are
54 likely to be better maintained by the community using them, like
55 `IJulia <https://github.com/JuliaLang/IJulia.jl>`_ or `IHaskell <https://github.com/gibiansky/IHaskell>`_.
56
50 .. seealso::
57 .. seealso::
51
58
52 :doc:`kernels`
59 :doc:`kernels`
53
60
54 :doc:`wrapperkernels`
61 :doc:`wrapperkernels`
55
62
56 Notebooks
63 Notebooks
57 ---------
64 ---------
58
65
59 The Notebook frontend does something extra. In addition to running your code, it
66 The Notebook frontend does something extra. In addition to running your code, it
60 stores code and output, together with markdown notes, in an editable document
67 stores code and output, together with markdown notes, in an editable document
61 called a notebook. When you save it, this is sent from your browser to the
68 called a notebook. When you save it, this is sent from your browser to the
62 notebook server, which saves it on disk as a JSON file with a ``.ipynb``
69 notebook server, which saves it on disk as a JSON file with a ``.ipynb``
63 extension.
70 extension.
64
71
65 .. image:: figs/notebook_components.png
72 .. image:: figs/notebook_components.png
66
73
67 The notebook server, not the kernel, is responsible for saving and loading
74 The notebook server, not the kernel, is responsible for saving and loading
68 notebooks, so you can edit notebooks even if you don't have the kernel for that
75 notebooks, so you can edit notebooks even if you don't have the kernel for that
69 language—you just won't be able to run code. The kernel doesn't know anything
76 language—you just won't be able to run code. The kernel doesn't know anything
70 about the notebook document: it just gets sent cells of code to execute when the
77 about the notebook document: it just gets sent cells of code to execute when the
71 user runs them.
78 user runs them.
72
79
73 Exporting to other formats
80 Exporting to other formats
74 ``````````````````````````
81 ``````````````````````````
75
82
76 The Nbconvert tool in IPython converts notebook files to other formats, such as
83 The Nbconvert tool in IPython converts notebook files to other formats, such as
77 HTML, LaTeX, or reStructuredText. This conversion goes through a series of steps:
84 HTML, LaTeX, or reStructuredText. This conversion goes through a series of steps:
78
85
79 .. image:: figs/nbconvert.png
86 .. image:: figs/nbconvert.png
80
87
81 1. Preprocessors modify the notebook in memory. E.g. ExecutePreprocessor runs
88 1. Preprocessors modify the notebook in memory. E.g. ExecutePreprocessor runs
82 the code in the notebook and updates the output.
89 the code in the notebook and updates the output.
83 2. An exporter converts the notebook to another file format. Most of the
90 2. An exporter converts the notebook to another file format. Most of the
84 exporters use templates for this.
91 exporters use templates for this.
85 3. Postprocessors work on the file produced by exporting.
92 3. Postprocessors work on the file produced by exporting.
86
93
87 The `nbviewer <http://nbviewer.ipython.org/>`_ website uses nbconvert with the
94 The `nbviewer <http://nbviewer.ipython.org/>`_ website uses nbconvert with the
88 HTML exporter. When you give it a URL, it fetches the notebook from that URL,
95 HTML exporter. When you give it a URL, it fetches the notebook from that URL,
89 converts it to HTML, and serves that HTML to you.
96 converts it to HTML, and serves that HTML to you.
General Comments 0
You need to be logged in to leave comments. Login now