Debian Codegraph @

docs/source/development/how_ipython_works.rst

raw
1 How IPython works
2 =================
3
4 Terminal IPython
5 ----------------
6
7 When you type ``ipython``, you get the original IPython interface, running in
8 the terminal. It does something like this::
9
10 while True:
11 code = input(">>> ")
12 exec(code)
13
14 Of course, it's much more complex, because it has to deal with multi-line
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,
17 exec it in the same process. This model is often called a REPL, or
18 Read-Eval-Print-Loop.
19
20 The IPython Kernel
21 ------------------
22
23 All the other interfaces—the Notebook, the Qt console, ``ipython console`` in
24 the terminal, and third party interfaces—use the IPython Kernel. This is a
25 separate process which is responsible for running user code, and things like
26 computing possible completions. Frontends communicate with it using JSON
27 messages sent over `ZeroMQ <http://zeromq.org/>`_ sockets; the protocol they use is described in
28 :ref:`jupyterclient:messaging`.
29
30 The core execution machinery for the kernel is shared with terminal IPython:
31
32 .. image:: figs/ipy_kernel_and_terminal.png
33
34 A kernel process can be connected to more than one frontend simultaneously. In
35 this case, the different frontends will have access to the same variables.
36
37 .. TODO: Diagram illustrating this?
38
39 This design was intended to allow easy development of different frontends based
40 on the same kernel, but it also made it possible to support new languages in the
41 same frontends, by developing kernels in those languages, and we are refining
42 IPython to make that more practical.
43
44 Today, there are two ways to develop a kernel for another language. Wrapper
45 kernels reuse the communications machinery from IPython, and implement only the
46 core execution part. Native kernels implement execution and communications in
47 the target language:
48
49 .. image:: figs/other_kernels.png
50
51 Wrapper kernels are easier to write quickly for languages that have good Python
52 wrappers, like `octave_kernel <https://pypi.python.org/pypi/octave_kernel>`_, or
53 languages where it's impractical to implement the communications machinery, like
54 `bash_kernel <https://pypi.python.org/pypi/bash_kernel>`_. Native kernels are
55 likely to be better maintained by the community using them, like
56 `IJulia <https://github.com/JuliaLang/IJulia.jl>`_ or `IHaskell <https://github.com/gibiansky/IHaskell>`_.
57
58 .. seealso::
59
60 :ref:`jupyterclient:kernels`
61
62 :doc:`wrapperkernels`
63