Skip to content

Commit f93de51

Browse files
committed
Merge pull request ipython#27 from rgbkrk/on_ipython
Move the How IPython Works doc into a notebook
2 parents 39bb562 + 199008f commit f93de51

File tree

5 files changed

+123
-1
lines changed

5 files changed

+123
-1
lines changed

Index - Basic.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"* [Introduction to Interactive Javascript Widgets](examples/Interactive Widgets/Using Interact.ipynb)\n",
2424
"* [Customizing IPython - a condensed version](exercises/Customization/Condensed.ipynb)\n",
2525
"* [Running a Secure Public Notebook Server](examples/Notebook/Running%20the%20Notebook%20Server.ipynb#Securing-the-notebook-server)\n",
26-
"* [How Jupyter/IPython works](http://ipython.org/ipython-doc/stable/development/how_ipython_works.html) to run code in different languages."
26+
"* [How Jupyter/IPython works](examples/Notebook/Multiple%20Languages%2C%20Frontends.ipynb) to run code in different languages."
2727
]
2828
},
2929
{
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# How IPython works\n",
8+
"\n",
9+
"\n",
10+
"## Terminal IPython\n",
11+
"\n",
12+
"When you type `ipython`, you get the original IPython interface, running in\n",
13+
"the terminal. It does something like this:\n",
14+
"\n",
15+
"```\n",
16+
"while True:\n",
17+
" code = input(\">>> \")\n",
18+
" exec(code)\n",
19+
"```\n",
20+
"\n",
21+
"Of course, it's much more complex, because it has to deal with multi-line\n",
22+
"code, tab completion using `readline`, magic commands, and so on. But the\n",
23+
"model is like that: prompt the user for some code, and when they've entered it,\n",
24+
"exec it in the same process. This model is often called a REPL, or\n",
25+
"Read-Eval-Print-Loop."
26+
]
27+
},
28+
{
29+
"cell_type": "markdown",
30+
"metadata": {},
31+
"source": [
32+
"## The IPython Kernel\n",
33+
"\n",
34+
"All the other interfaces—the Notebook, the Qt console, `ipython console` in\n",
35+
"the terminal, and third party interfaces—use the IPython Kernel. This is a\n",
36+
"separate process which is responsible for running user code, and things like\n",
37+
"computing possible completions. Frontends communicate with it using JSON\n",
38+
"messages sent over [ZeroMQ](http://zeromq.org/) sockets; the protocol they use is described in\n",
39+
":doc:`messaging`.\n",
40+
"\n",
41+
"The core execution machinery for the kernel is shared with terminal IPython:\n",
42+
"\n",
43+
"![IPython kernel and terminal relationship](images/ipy_kernel_and_terminal.png)\n",
44+
"\n",
45+
"A kernel process can be connected to more than one frontend simultaneously. In\n",
46+
"this case, the different frontends will have access to the same variables.\n",
47+
"\n",
48+
"<!-- TODO: Diagram illustrating this? -->\n",
49+
"\n",
50+
"This design was intended to allow easy development of different frontends based\n",
51+
"on the same kernel, but it also made it possible to support new languages in the\n",
52+
"same frontends, by developing kernels in those languages, and we are refining\n",
53+
"IPython to make that more practical.\n",
54+
"\n",
55+
"Today, there are two ways to develop a kernel for another language. Wrapper\n",
56+
"kernels reuse the communications machinery from IPython, and implement only the\n",
57+
"core execution part. Native kernels implement execution and communications in\n",
58+
"the target language:\n",
59+
"\n",
60+
"![Other Kernels](images/other_kernels.png)\n",
61+
"\n",
62+
"Wrapper kernels are easier to write quickly for languages that have good Python\n",
63+
"wrappers, like [octave_kernel](https://pypi.python.org/pypi/octave_kernel), or\n",
64+
"languages where it's impractical to implement the communications machinery, like\n",
65+
"[bash_kernel](https://pypi.python.org/pypi/bash_kernel). Native kernels are\n",
66+
"likely to be better maintained by the community using them, like\n",
67+
"[IJulia](https://github.com/JuliaLang/IJulia.jl) or [IHaskell](https://github.com/gibiansky/IHaskell).\n",
68+
"\n",
69+
"<!-- TODO:\n",
70+
".. seealso::\n",
71+
"\n",
72+
" :doc:`kernels`\n",
73+
" \n",
74+
" :doc:`wrapperkernels`\n",
75+
" \n",
76+
" -->"
77+
]
78+
},
79+
{
80+
"cell_type": "markdown",
81+
"metadata": {},
82+
"source": [
83+
"## Notebooks\n",
84+
"\n",
85+
"The Notebook frontend does something extra. In addition to running your code, it\n",
86+
"stores code and output, together with markdown notes, in an editable document\n",
87+
"called a notebook. When you save it, this is sent from your browser to the\n",
88+
"notebook server, which saves it on disk as a JSON file with a ``.ipynb``\n",
89+
"extension.\n",
90+
"\n",
91+
"![Notebook components](images/notebook_components.png)\n",
92+
"\n",
93+
"The notebook server, not the kernel, is responsible for saving and loading\n",
94+
"notebooks, so you can edit notebooks even if you don't have the kernel for that\n",
95+
"language—you just won't be able to run code. The kernel doesn't know anything\n",
96+
"about the notebook document: it just gets sent cells of code to execute when the\n",
97+
"user runs them."
98+
]
99+
}
100+
],
101+
"metadata": {
102+
"kernelspec": {
103+
"display_name": "Python 3",
104+
"language": "python",
105+
"name": "python3"
106+
},
107+
"language_info": {
108+
"codemirror_mode": {
109+
"name": "ipython",
110+
"version": 3
111+
},
112+
"file_extension": ".py",
113+
"mimetype": "text/x-python",
114+
"name": "python",
115+
"nbconvert_exporter": "python",
116+
"pygments_lexer": "ipython3",
117+
"version": "3.4.3"
118+
}
119+
},
120+
"nbformat": 4,
121+
"nbformat_minor": 0
122+
}
27.6 KB
Loading
30.2 KB
Loading
40.2 KB
Loading

0 commit comments

Comments
 (0)