##// END OF EJS Templates
Massive reorganization of the IPython documentation. It is now ready to be hacked on by users. ...
Brian E Granger -
Show More

The requested changes are too big and content was truncated. Show full diff

@@ -0,0 +1,284 b''
1 .. _customization:
2
3 ========================
4 Customization of IPython
5 ========================
6
7 There are 2 ways to configure IPython - the old way of using ipythonrc
8 files (an INI-file like format), and the new way that involves editing
9 your ipy_user_conf.py. Both configuration systems work at the same
10 time, so you can set your options in both, but if you are hesitating
11 about which alternative to choose, we recommend the ipy_user_conf.py
12 approach, as it will give you more power and control in the long
13 run. However, there are few options such as pylab_import_all that can
14 only be specified in ipythonrc file or command line - the reason for
15 this is that they are needed before IPython has been started up, and
16 the IPApi object used in ipy_user_conf.py is not yet available at that
17 time. A hybrid approach of specifying a few options in ipythonrc and
18 doing the more advanced configuration in ipy_user_conf.py is also
19 possible.
20
21 The ipythonrc approach
22 ======================
23
24 As we've already mentioned, IPython reads a configuration file which can
25 be specified at the command line (-rcfile) or which by default is
26 assumed to be called ipythonrc. Such a file is looked for in the current
27 directory where IPython is started and then in your IPYTHONDIR, which
28 allows you to have local configuration files for specific projects. In
29 this section we will call these types of configuration files simply
30 rcfiles (short for resource configuration file).
31
32 The syntax of an rcfile is one of key-value pairs separated by
33 whitespace, one per line. Lines beginning with a # are ignored as
34 comments, but comments can not be put on lines with data (the parser is
35 fairly primitive). Note that these are not python files, and this is
36 deliberate, because it allows us to do some things which would be quite
37 tricky to implement if they were normal python files.
38
39 First, an rcfile can contain permanent default values for almost all
40 command line options (except things like -help or -Version). Sec
41 `command line options`_ contains a description of all command-line
42 options. However, values you explicitly specify at the command line
43 override the values defined in the rcfile.
44
45 Besides command line option values, the rcfile can specify values for
46 certain extra special options which are not available at the command
47 line. These options are briefly described below.
48
49 Each of these options may appear as many times as you need it in the file.
50
51 * include <file1> <file2> ...: you can name other rcfiles you want
52 to recursively load up to 15 levels (don't use the <> brackets in
53 your names!). This feature allows you to define a 'base' rcfile
54 with general options and special-purpose files which can be loaded
55 only when needed with particular configuration options. To make
56 this more convenient, IPython accepts the -profile <name> option
57 (abbreviates to -p <name>) which tells it to look for an rcfile
58 named ipythonrc-<name>.
59 * import_mod <mod1> <mod2> ...: import modules with 'import
60 <mod1>,<mod2>,...'
61 * import_some <mod> <f1> <f2> ...: import functions with 'from
62 <mod> import <f1>,<f2>,...'
63 * import_all <mod1> <mod2> ...: for each module listed import
64 functions with ``from <mod> import *``.
65 * execute <python code>: give any single-line python code to be
66 executed.
67 * execfile <filename>: execute the python file given with an
68 'execfile(filename)' command. Username expansion is performed on
69 the given names. So if you need any amount of extra fancy
70 customization that won't fit in any of the above 'canned' options,
71 you can just put it in a separate python file and execute it.
72 * alias <alias_def>: this is equivalent to calling
73 '%alias <alias_def>' at the IPython command line. This way, from
74 within IPython you can do common system tasks without having to
75 exit it or use the ! escape. IPython isn't meant to be a shell
76 replacement, but it is often very useful to be able to do things
77 with files while testing code. This gives you the flexibility to
78 have within IPython any aliases you may be used to under your
79 normal system shell.
80
81 ipy_user_conf.py
82 ================
83
84 There should be a simple template ipy_user_conf.py file in your
85 ~/.ipython directory. It is a plain python module that is imported
86 during IPython startup, so you can do pretty much what you want there
87 - import modules, configure extensions, change options, define magic
88 commands, put variables and functions in the IPython namespace,
89 etc. You use the IPython extension api object, acquired by
90 IPython.ipapi.get() and documented in the "IPython extension API"
91 chapter, to interact with IPython. A sample ipy_user_conf.py is listed
92 below for reference::
93
94 # Most of your config files and extensions will probably start
95 # with this import
96
97 import IPython.ipapi
98 ip = IPython.ipapi.get()
99
100 # You probably want to uncomment this if you did %upgrade -nolegacy
101 # import ipy_defaults
102
103 import os
104
105 def main():
106
107 #ip.dbg.debugmode = True
108 ip.dbg.debug_stack()
109
110 # uncomment if you want to get ipython -p sh behaviour
111 # without having to use command line switches
112 import ipy_profile_sh
113 import jobctrl
114
115 # Configure your favourite editor?
116 # Good idea e.g. for %edit os.path.isfile
117
118 #import ipy_editors
119
120 # Choose one of these:
121
122 #ipy_editors.scite()
123 #ipy_editors.scite('c:/opt/scite/scite.exe')
124 #ipy_editors.komodo()
125 #ipy_editors.idle()
126 # ... or many others, try 'ipy_editors??' after import to see them
127
128 # Or roll your own:
129 #ipy_editors.install_editor("c:/opt/jed +$line $file")
130
131
132 o = ip.options
133 # An example on how to set options
134 #o.autocall = 1
135 o.system_verbose = 0
136
137 #import_all("os sys")
138 #execf('~/_ipython/ns.py')
139
140
141 # -- prompt
142 # A different, more compact set of prompts from the default ones, that
143 # always show your current location in the filesystem:
144
145 #o.prompt_in1 = r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Normal\n\C_Green|\#>'
146 #o.prompt_in2 = r'.\D: '
147 #o.prompt_out = r'[\#] '
148
149 # Try one of these color settings if you can't read the text easily
150 # autoexec is a list of IPython commands to execute on startup
151 #o.autoexec.append('%colors LightBG')
152 #o.autoexec.append('%colors NoColor')
153 o.autoexec.append('%colors Linux')
154
155
156 # some config helper functions you can use
157 def import_all(modules):
158 """ Usage: import_all("os sys") """
159 for m in modules.split():
160 ip.ex("from %s import *" % m)
161
162 def execf(fname):
163 """ Execute a file in user namespace """
164 ip.ex('execfile("%s")' % os.path.expanduser(fname))
165
166 main()
167
168 .. _Prompts:
169
170 Fine-tuning your prompt
171 =======================
172
173 IPython's prompts can be customized using a syntax similar to that of
174 the bash shell. Many of bash's escapes are supported, as well as a few
175 additional ones. We list them below::
176
177 \#
178 the prompt/history count number. This escape is automatically
179 wrapped in the coloring codes for the currently active color scheme.
180 \N
181 the 'naked' prompt/history count number: this is just the number
182 itself, without any coloring applied to it. This lets you produce
183 numbered prompts with your own colors.
184 \D
185 the prompt/history count, with the actual digits replaced by dots.
186 Used mainly in continuation prompts (prompt_in2)
187 \w
188 the current working directory
189 \W
190 the basename of current working directory
191 \Xn
192 where $n=0\ldots5.$ The current working directory, with $HOME
193 replaced by ~, and filtered out to contain only $n$ path elements
194 \Yn
195 Similar to \Xn, but with the $n+1$ element included if it is ~ (this
196 is similar to the behavior of the %cn escapes in tcsh)
197 \u
198 the username of the current user
199 \$
200 if the effective UID is 0, a #, otherwise a $
201 \h
202 the hostname up to the first '.'
203 \H
204 the hostname
205 \n
206 a newline
207 \r
208 a carriage return
209 \v
210 IPython version string
211
212 In addition to these, ANSI color escapes can be insterted into the
213 prompts, as \C_ColorName. The list of valid color names is: Black, Blue,
214 Brown, Cyan, DarkGray, Green, LightBlue, LightCyan, LightGray,
215 LightGreen, LightPurple, LightRed, NoColor, Normal, Purple, Red, White,
216 Yellow.
217
218 Finally, IPython supports the evaluation of arbitrary expressions in
219 your prompt string. The prompt strings are evaluated through the syntax
220 of PEP 215, but basically you can use $x.y to expand the value of x.y,
221 and for more complicated expressions you can use braces: ${foo()+x} will
222 call function foo and add to it the value of x, before putting the
223 result into your prompt. For example, using
224 prompt_in1 '${commands.getoutput("uptime")}\nIn [\#]: '
225 will print the result of the uptime command on each prompt (assuming the
226 commands module has been imported in your ipythonrc file).
227
228
229 Prompt examples
230
231 The following options in an ipythonrc file will give you IPython's
232 default prompts::
233
234 prompt_in1 'In [\#]:'
235 prompt_in2 ' .\D.:'
236 prompt_out 'Out[\#]:'
237
238 which look like this::
239
240 In [1]: 1+2
241 Out[1]: 3
242
243 In [2]: for i in (1,2,3):
244 ...: print i,
245 ...:
246 1 2 3
247
248 These will give you a very colorful prompt with path information::
249
250 #prompt_in1 '\C_Red\u\C_Blue[\C_Cyan\Y1\C_Blue]\C_LightGreen\#>'
251 prompt_in2 ' ..\D>'
252 prompt_out '<\#>'
253
254 which look like this::
255
256 fperez[~/ipython]1> 1+2
257 <1> 3
258 fperez[~/ipython]2> for i in (1,2,3):
259 ...> print i,
260 ...>
261 1 2 3
262
263
264 .. _Profiles:
265
266 IPython profiles
267 ================
268
269 As we already mentioned, IPython supports the -profile command-line
270 option (see sec. `command line options`_). A profile is nothing more
271 than a particular configuration file like your basic ipythonrc one,
272 but with particular customizations for a specific purpose. When you
273 start IPython with 'ipython -profile <name>', it assumes that in your
274 IPYTHONDIR there is a file called ipythonrc-<name> or
275 ipy_profile_<name>.py, and loads it instead of the normal ipythonrc.
276
277 This system allows you to maintain multiple configurations which load
278 modules, set options, define functions, etc. suitable for different
279 tasks and activate them in a very simple manner. In order to avoid
280 having to repeat all of your basic options (common things that don't
281 change such as your color preferences, for example), any profile can
282 include another configuration file. The most common way to use profiles
283 is then to have each one include your basic ipythonrc file as a starting
284 point, and then add further customizations. No newline at end of file
@@ -0,0 +1,10 b''
1 ===============================
2 Configuration and customization
3 ===============================
4
5 .. toctree::
6 :maxdepth: 1
7
8 initial_config.txt
9 customization.txt
10 new_config.txt
@@ -0,0 +1,238 b''
1 .. _initial config:
2
3 =========================================
4 Initial configuration of your environment
5 =========================================
6
7 This section will help you set various things in your environment for
8 your IPython sessions to be as efficient as possible. All of IPython's
9 configuration information, along with several example files, is stored
10 in a directory named by default $HOME/.ipython. You can change this by
11 defining the environment variable IPYTHONDIR, or at runtime with the
12 command line option -ipythondir.
13
14 If all goes well, the first time you run IPython it should
15 automatically create a user copy of the config directory for you,
16 based on its builtin defaults. You can look at the files it creates to
17 learn more about configuring the system. The main file you will modify
18 to configure IPython's behavior is called ipythonrc (with a .ini
19 extension under Windows), included for reference in `ipythonrc`_
20 section. This file is very commented and has many variables you can
21 change to suit your taste, you can find more details in
22 Sec. customization_. Here we discuss the basic things you will want to
23 make sure things are working properly from the beginning.
24
25
26 .. _Accessing help:
27
28 Access to the Python help system
29 ================================
30
31 This is true for Python in general (not just for IPython): you should
32 have an environment variable called PYTHONDOCS pointing to the directory
33 where your HTML Python documentation lives. In my system it's
34 /usr/share/doc/python-docs-2.3.4/html, check your local details or ask
35 your systems administrator.
36
37 This is the directory which holds the HTML version of the Python
38 manuals. Unfortunately it seems that different Linux distributions
39 package these files differently, so you may have to look around a bit.
40 Below I show the contents of this directory on my system for reference::
41
42 [html]> ls
43 about.dat acks.html dist/ ext/ index.html lib/ modindex.html
44 stdabout.dat tut/ about.html api/ doc/ icons/ inst/ mac/ ref/ style.css
45
46 You should really make sure this variable is correctly set so that
47 Python's pydoc-based help system works. It is a powerful and convenient
48 system with full access to the Python manuals and all modules accessible
49 to you.
50
51 Under Windows it seems that pydoc finds the documentation automatically,
52 so no extra setup appears necessary.
53
54
55 Editor
56 ======
57
58 The %edit command (and its alias %ed) will invoke the editor set in your
59 environment as EDITOR. If this variable is not set, it will default to
60 vi under Linux/Unix and to notepad under Windows. You may want to set
61 this variable properly and to a lightweight editor which doesn't take
62 too long to start (that is, something other than a new instance of
63 Emacs). This way you can edit multi-line code quickly and with the power
64 of a real editor right inside IPython.
65
66 If you are a dedicated Emacs user, you should set up the Emacs server so
67 that new requests are handled by the original process. This means that
68 almost no time is spent in handling the request (assuming an Emacs
69 process is already running). For this to work, you need to set your
70 EDITOR environment variable to 'emacsclient'. The code below, supplied
71 by Francois Pinard, can then be used in your .emacs file to enable the
72 server::
73
74 (defvar server-buffer-clients)
75 (when (and (fboundp 'server-start) (string-equal (getenv "TERM") 'xterm))
76 (server-start)
77 (defun fp-kill-server-with-buffer-routine ()
78 (and server-buffer-clients (server-done)))
79 (add-hook 'kill-buffer-hook 'fp-kill-server-with-buffer-routine))
80
81 You can also set the value of this editor via the commmand-line option
82 '-editor' or in your ipythonrc file. This is useful if you wish to use
83 specifically for IPython an editor different from your typical default
84 (and for Windows users who tend to use fewer environment variables).
85
86
87 Color
88 =====
89
90 The default IPython configuration has most bells and whistles turned on
91 (they're pretty safe). But there's one that may cause problems on some
92 systems: the use of color on screen for displaying information. This is
93 very useful, since IPython can show prompts and exception tracebacks
94 with various colors, display syntax-highlighted source code, and in
95 general make it easier to visually parse information.
96
97 The following terminals seem to handle the color sequences fine:
98
99 * Linux main text console, KDE Konsole, Gnome Terminal, E-term,
100 rxvt, xterm.
101 * CDE terminal (tested under Solaris). This one boldfaces light colors.
102 * (X)Emacs buffers. See the emacs_ section for more details on
103 using IPython with (X)Emacs.
104 * A Windows (XP/2k) command prompt with pyreadline_.
105 * A Windows (XP/2k) CygWin shell. Although some users have reported
106 problems; it is not clear whether there is an issue for everyone
107 or only under specific configurations. If you have full color
108 support under cygwin, please post to the IPython mailing list so
109 this issue can be resolved for all users.
110
111 These have shown problems:
112
113 * Windows command prompt in WinXP/2k logged into a Linux machine via
114 telnet or ssh.
115 * Windows native command prompt in WinXP/2k, without Gary Bishop's
116 extensions. Once Gary's readline library is installed, the normal
117 WinXP/2k command prompt works perfectly.
118
119 Currently the following color schemes are available:
120
121 * NoColor: uses no color escapes at all (all escapes are empty '' ''
122 strings). This 'scheme' is thus fully safe to use in any terminal.
123 * Linux: works well in Linux console type environments: dark
124 background with light fonts. It uses bright colors for
125 information, so it is difficult to read if you have a light
126 colored background.
127 * LightBG: the basic colors are similar to those in the Linux scheme
128 but darker. It is easy to read in terminals with light backgrounds.
129
130 IPython uses colors for two main groups of things: prompts and
131 tracebacks which are directly printed to the terminal, and the object
132 introspection system which passes large sets of data through a pager.
133
134
135 Input/Output prompts and exception tracebacks
136 =============================================
137
138 You can test whether the colored prompts and tracebacks work on your
139 system interactively by typing '%colors Linux' at the prompt (use
140 '%colors LightBG' if your terminal has a light background). If the input
141 prompt shows garbage like::
142
143 [0;32mIn [[1;32m1[0;32m]: [0;00m
144
145 instead of (in color) something like::
146
147 In [1]:
148
149 this means that your terminal doesn't properly handle color escape
150 sequences. You can go to a 'no color' mode by typing '%colors NoColor'.
151
152 You can try using a different terminal emulator program (Emacs users,
153 see below). To permanently set your color preferences, edit the file
154 $HOME/.ipython/ipythonrc and set the colors option to the desired value.
155
156
157 Object details (types, docstrings, source code, etc.)
158 =====================================================
159
160 IPython has a set of special functions for studying the objects you
161 are working with, discussed in detail in Sec. `dynamic object
162 information`_. But this system relies on passing information which is
163 longer than your screen through a data pager, such as the common Unix
164 less and more programs. In order to be able to see this information in
165 color, your pager needs to be properly configured. I strongly
166 recommend using less instead of more, as it seems that more simply can
167 not understand colored text correctly.
168
169 In order to configure less as your default pager, do the following:
170
171 1. Set the environment PAGER variable to less.
172 2. Set the environment LESS variable to -r (plus any other options
173 you always want to pass to less by default). This tells less to
174 properly interpret control sequences, which is how color
175 information is given to your terminal.
176
177 For the csh or tcsh shells, add to your ~/.cshrc file the lines::
178
179 setenv PAGER less
180 setenv LESS -r
181
182 There is similar syntax for other Unix shells, look at your system
183 documentation for details.
184
185 If you are on a system which lacks proper data pagers (such as Windows),
186 IPython will use a very limited builtin pager.
187
188 .. _emacs:
189
190 (X)Emacs configuration
191 ======================
192
193 Thanks to the work of Alexander Schmolck and Prabhu Ramachandran,
194 currently (X)Emacs and IPython get along very well.
195
196 Important note: You will need to use a recent enough version of
197 python-mode.el, along with the file ipython.el. You can check that the
198 version you have of python-mode.el is new enough by either looking at
199 the revision number in the file itself, or asking for it in (X)Emacs via
200 M-x py-version. Versions 4.68 and newer contain the necessary fixes for
201 proper IPython support.
202
203 The file ipython.el is included with the IPython distribution, in the
204 documentation directory (where this manual resides in PDF and HTML
205 formats).
206
207 Once you put these files in your Emacs path, all you need in your .emacs
208 file is::
209
210 (require 'ipython)
211
212 This should give you full support for executing code snippets via
213 IPython, opening IPython as your Python shell via C-c !, etc.
214
215 If you happen to get garbage instead of colored prompts as described in
216 the previous section, you may need to set also in your .emacs file::
217
218 (setq ansi-color-for-comint-mode t)
219
220
221 Notes:
222
223 * There is one caveat you should be aware of: you must start the
224 IPython shell before attempting to execute any code regions via
225 ``C-c |``. Simply type C-c ! to start IPython before passing any code
226 regions to the interpreter, and you shouldn't experience any
227 problems.
228 This is due to a bug in Python itself, which has been fixed for
229 Python 2.3, but exists as of Python 2.2.2 (reported as SF bug [
230 737947 ]).
231 * The (X)Emacs support is maintained by Alexander Schmolck, so all
232 comments/requests should be directed to him through the IPython
233 mailing lists.
234 * This code is still somewhat experimental so it's a bit rough
235 around the edges (although in practice, it works quite well).
236 * Be aware that if you customize py-python-command previously, this
237 value will override what ipython.el does (because loading the
238 customization variables comes later). No newline at end of file
@@ -0,0 +1,27 b''
1 ========================
2 New configuration system
3 ========================
4
5 IPython has a configuration system. When running IPython for the first time,
6 reasonable defaults are used for the configuration. The configuration of IPython
7 can be changed in two ways:
8
9 * Configuration files
10 * Commands line options (which override the configuration files)
11
12 IPython has a separate configuration file for each subpackage. Thus, the main
13 configuration files are (in your ``~/.ipython`` directory):
14
15 * ``ipython1.core.ini``
16 * ``ipython1.kernel.ini``
17 * ``ipython1.notebook.ini``
18
19 To create these files for the first time, do the following::
20
21 from ipython1.kernel.config import config_manager as kernel_config
22 kernel_config.write_default_config_file()
23
24 But, you should only need to do this if you need to modify the defaults. If needed
25 repeat this process with the ``notebook`` and ``core`` configuration as well. If you
26 are running into problems with IPython, you might try deleting these configuration
27 files. No newline at end of file
@@ -0,0 +1,139 b''
1 .. _credits:
2
3 =======
4 Credits
5 =======
6
7 IPython is mainly developed by Fernando Pérez
8 <Fernando.Perez@colorado.edu>, but the project was born from mixing in
9 Fernando's code with the IPP project by Janko Hauser
10 <jhauser-AT-zscout.de> and LazyPython by Nathan Gray
11 <n8gray-AT-caltech.edu>. For all IPython-related requests, please
12 contact Fernando.
13
14 As of early 2006, the following developers have joined the core team:
15
16 * [Robert Kern] <rkern-AT-enthought.com>: co-mentored the 2005
17 Google Summer of Code project to develop python interactive
18 notebooks (XML documents) and graphical interface. This project
19 was awarded to the students Tzanko Matev <tsanko-AT-gmail.com> and
20 Toni Alatalo <antont-AT-an.org>
21 * [Brian Granger] <bgranger-AT-scu.edu>: extending IPython to allow
22 support for interactive parallel computing.
23 * [Ville Vainio] <vivainio-AT-gmail.com>: Ville is the new
24 maintainer for the main trunk of IPython after version 0.7.1.
25
26 The IPython project is also very grateful to:
27
28 Bill Bumgarner <bbum-AT-friday.com>: for providing the DPyGetOpt module
29 which gives very powerful and convenient handling of command-line
30 options (light years ahead of what Python 2.1.1's getopt module does).
31
32 Ka-Ping Yee <ping-AT-lfw.org>: for providing the Itpl module for
33 convenient and powerful string interpolation with a much nicer syntax
34 than formatting through the '%' operator.
35
36 Arnd Baecker <baecker-AT-physik.tu-dresden.de>: for his many very useful
37 suggestions and comments, and lots of help with testing and
38 documentation checking. Many of IPython's newer features are a result of
39 discussions with him (bugs are still my fault, not his).
40
41 Obviously Guido van Rossum and the whole Python development team, that
42 goes without saying.
43
44 IPython's website is generously hosted at http://ipython.scipy.orgby
45 Enthought (http://www.enthought.com). I am very grateful to them and all
46 of the SciPy team for their contribution.
47
48 Fernando would also like to thank Stephen Figgins <fig-AT-monitor.net>,
49 an O'Reilly Python editor. His Oct/11/2001 article about IPP and
50 LazyPython, was what got this project started. You can read it at:
51 http://www.onlamp.com/pub/a/python/2001/10/11/pythonnews.html.
52
53 And last but not least, all the kind IPython users who have emailed new
54 code, bug reports, fixes, comments and ideas. A brief list follows,
55 please let me know if I have ommitted your name by accident:
56
57 * [Jack Moffit] <jack-AT-xiph.org> Bug fixes, including the infamous
58 color problem. This bug alone caused many lost hours and
59 frustration, many thanks to him for the fix. I've always been a
60 fan of Ogg & friends, now I have one more reason to like these folks.
61 Jack is also contributing with Debian packaging and many other
62 things.
63 * [Alexander Schmolck] <a.schmolck-AT-gmx.net> Emacs work, bug
64 reports, bug fixes, ideas, lots more. The ipython.el mode for
65 (X)Emacs is Alex's code, providing full support for IPython under
66 (X)Emacs.
67 * [Andrea Riciputi] <andrea.riciputi-AT-libero.it> Mac OSX
68 information, Fink package management.
69 * [Gary Bishop] <gb-AT-cs.unc.edu> Bug reports, and patches to work
70 around the exception handling idiosyncracies of WxPython. Readline
71 and color support for Windows.
72 * [Jeffrey Collins] <Jeff.Collins-AT-vexcel.com> Bug reports. Much
73 improved readline support, including fixes for Python 2.3.
74 * [Dryice Liu] <dryice-AT-liu.com.cn> FreeBSD port.
75 * [Mike Heeter] <korora-AT-SDF.LONESTAR.ORG>
76 * [Christopher Hart] <hart-AT-caltech.edu> PDB integration.
77 * [Milan Zamazal] <pdm-AT-zamazal.org> Emacs info.
78 * [Philip Hisley] <compsys-AT-starpower.net>
79 * [Holger Krekel] <pyth-AT-devel.trillke.net> Tab completion, lots
80 more.
81 * [Robin Siebler] <robinsiebler-AT-starband.net>
82 * [Ralf Ahlbrink] <ralf_ahlbrink-AT-web.de>
83 * [Thorsten Kampe] <thorsten-AT-thorstenkampe.de>
84 * [Fredrik Kant] <fredrik.kant-AT-front.com> Windows setup.
85 * [Syver Enstad] <syver-en-AT-online.no> Windows setup.
86 * [Richard] <rxe-AT-renre-europe.com> Global embedding.
87 * [Hayden Callow] <h.callow-AT-elec.canterbury.ac.nz> Gnuplot.py 1.6
88 compatibility.
89 * [Leonardo Santagada] <retype-AT-terra.com.br> Fixes for Windows
90 installation.
91 * [Christopher Armstrong] <radix-AT-twistedmatrix.com> Bugfixes.
92 * [Francois Pinard] <pinard-AT-iro.umontreal.ca> Code and
93 documentation fixes.
94 * [Cory Dodt] <cdodt-AT-fcoe.k12.ca.us> Bug reports and Windows
95 ideas. Patches for Windows installer.
96 * [Olivier Aubert] <oaubert-AT-bat710.univ-lyon1.fr> New magics.
97 * [King C. Shu] <kingshu-AT-myrealbox.com> Autoindent patch.
98 * [Chris Drexler] <chris-AT-ac-drexler.de> Readline packages for
99 Win32/CygWin.
100 * [Gustavo Cordova Avila] <gcordova-AT-sismex.com> EvalDict code for
101 nice, lightweight string interpolation.
102 * [Kasper Souren] <Kasper.Souren-AT-ircam.fr> Bug reports, ideas.
103 * [Gever Tulley] <gever-AT-helium.com> Code contributions.
104 * [Ralf Schmitt] <ralf-AT-brainbot.com> Bug reports & fixes.
105 * [Oliver Sander] <osander-AT-gmx.de> Bug reports.
106 * [Rod Holland] <rhh-AT-structurelabs.com> Bug reports and fixes to
107 logging module.
108 * [Daniel 'Dang' Griffith] <pythondev-dang-AT-lazytwinacres.net>
109 Fixes, enhancement suggestions for system shell use.
110 * [Viktor Ransmayr] <viktor.ransmayr-AT-t-online.de> Tests and
111 reports on Windows installation issues. Contributed a true Windows
112 binary installer.
113 * [Mike Salib] <msalib-AT-mit.edu> Help fixing a subtle bug related
114 to traceback printing.
115 * [W.J. van der Laan] <gnufnork-AT-hetdigitalegat.nl> Bash-like
116 prompt specials.
117 * [Antoon Pardon] <Antoon.Pardon-AT-rece.vub.ac.be> Critical fix for
118 the multithreaded IPython.
119 * [John Hunter] <jdhunter-AT-nitace.bsd.uchicago.edu> Matplotlib
120 author, helped with all the development of support for matplotlib
121 in IPyhton, including making necessary changes to matplotlib itself.
122 * [Matthew Arnison] <maffew-AT-cat.org.au> Bug reports, '%run -d' idea.
123 * [Prabhu Ramachandran] <prabhu_r-AT-users.sourceforge.net> Help
124 with (X)Emacs support, threading patches, ideas...
125 * [Norbert Tretkowski] <tretkowski-AT-inittab.de> help with Debian
126 packaging and distribution.
127 * [George Sakkis] <gsakkis-AT-eden.rutgers.edu> New matcher for
128 tab-completing named arguments of user-defined functions.
129 * [Jörgen Stenarson] <jorgen.stenarson-AT-bostream.nu> Wildcard
130 support implementation for searching namespaces.
131 * [Vivian De Smedt] <vivian-AT-vdesmedt.com> Debugger enhancements,
132 so that when pdb is activated from within IPython, coloring, tab
133 completion and other features continue to work seamlessly.
134 * [Scott Tsai] <scottt958-AT-yahoo.com.tw> Support for automatic
135 editor invocation on syntax errors (see
136 http://www.scipy.net/roundup/ipython/issue36).
137 * [Alexander Belchenko] <bialix-AT-ukr.net> Improvements for win32
138 paging system.
139 * [Will Maier] <willmaier-AT-ml1.net> Official OpenBSD port. No newline at end of file
@@ -0,0 +1,252 b''
1 =====================
2 IPython extension API
3 =====================
4
5 IPython api (defined in IPython/ipapi.py) is the public api that
6 should be used for
7
8 * Configuration of user preferences (.ipython/ipy_user_conf.py)
9 * Creating new profiles (.ipython/ipy_profile_PROFILENAME.py)
10 * Writing extensions
11
12 Note that by using the extension api for configuration (editing
13 ipy_user_conf.py instead of ipythonrc), you get better validity checks
14 and get richer functionality - for example, you can import an
15 extension and call functions in it to configure it for your purposes.
16
17 For an example extension (the 'sh' profile), see
18 IPython/Extensions/ipy_profile_sh.py.
19
20 For the last word on what's available, see the source code of
21 IPython/ipapi.py.
22
23
24 Getting started
25 ===============
26
27 If you want to define an extension, create a normal python module that
28 can be imported. The module will access IPython functionality through
29 the 'ip' object defined below.
30
31 If you are creating a new profile (e.g. foobar), name the module as
32 'ipy_profile_foobar.py' and put it in your ~/.ipython directory. Then,
33 when you start ipython with the '-p foobar' argument, the module is
34 automatically imported on ipython startup.
35
36 If you are just doing some per-user configuration, you can either
37
38 * Put the commands directly into ipy_user_conf.py.
39
40 * Create a new module with your customization code and import *that*
41 module in ipy_user_conf.py. This is preferable to the first approach,
42 because now you can reuse and distribute your customization code.
43
44 Getting a handle to the api
45 ===========================
46
47 Put this in the start of your module::
48
49 #!python
50 import IPython.ipapi
51 ip = IPython.ipapi.get()
52
53 The 'ip' object will then be used for accessing IPython
54 functionality. 'ip' will mean this api object in all the following
55 code snippets. The same 'ip' that we just acquired is always
56 accessible in interactive IPython sessions by the name _ip - play with
57 it like this::
58
59 [~\_ipython]|81> a = 10
60 [~\_ipython]|82> _ip.e
61 _ip.ev _ip.ex _ip.expose_magic
62 [~\_ipython]|82> _ip.ev('a+13')
63 <82> 23
64
65 The _ip object is also used in some examples in this document - it can
66 be substituted by 'ip' in non-interactive use.
67
68 Changing options
69 ================
70
71 The ip object has 'options' attribute that can be used te get/set
72 configuration options (just as in the ipythonrc file)::
73
74 o = ip.options
75 o.autocall = 2
76 o.automagic = 1
77
78 Executing statements in IPython namespace with 'ex' and 'ev'
79 ============================================================
80
81 Often, you want to e.g. import some module or define something that
82 should be visible in IPython namespace. Use ``ip.ev`` to
83 *evaluate* (calculate the value of) expression and ``ip.ex`` to
84 '''execute''' a statement::
85
86 # path module will be visible to the interactive session
87 ip.ex("from path import path" )
88
89 # define a handy function 'up' that changes the working directory
90
91 ip.ex('import os')
92 ip.ex("def up(): os.chdir('..')")
93
94
95 # _i2 has the input history entry #2, print its value in uppercase.
96 print ip.ev('_i2.upper()')
97
98 Accessing the IPython namespace
99 ===============================
100
101 ip.user_ns attribute has a dictionary containing the IPython global
102 namespace (the namespace visible in the interactive session).
103
104 ::
105
106 [~\_ipython]|84> tauno = 555
107 [~\_ipython]|85> _ip.user_ns['tauno']
108 <85> 555
109
110 Defining new magic commands
111 ===========================
112
113 The following example defines a new magic command, %impall. What the
114 command does should be obvious::
115
116 def doimp(self, arg):
117 ip = self.api
118 ip.ex("import %s; reload(%s); from %s import *" % (
119 arg,arg,arg)
120 )
121
122 ip.expose_magic('impall', doimp)
123
124 Things to observe in this example:
125
126 * Define a function that implements the magic command using the
127 ipapi methods defined in this document
128 * The first argument of the function is 'self', i.e. the
129 interpreter object. It shouldn't be used directly. however.
130 The interpreter object is probably *not* going to remain stable
131 through IPython versions.
132 * Access the ipapi through 'self.api' instead of the global 'ip' object.
133 * All the text following the magic command on the command line is
134 contained in the second argument
135 * Expose the magic by ip.expose_magic()
136
137
138 Calling magic functions and system commands
139 ===========================================
140
141 Use ip.magic() to execute a magic function, and ip.system() to execute
142 a system command::
143
144 # go to a bookmark
145 ip.magic('%cd -b relfiles')
146
147 # execute 'ls -F' system command. Interchangeable with os.system('ls'), really.
148 ip.system('ls -F')
149
150 Launching IPython instance from normal python code
151 ==================================================
152
153 Use ipapi.launch_new_instance() with an argument that specifies the
154 namespace to use. This can be useful for trivially embedding IPython
155 into your program. Here's an example of normal python program test.py
156 ('''without''' an existing IPython session) that launches an IPython
157 interpreter and regains control when the interpreter is exited::
158
159 [ipython]|1> cat test.py
160 my_ns = dict(
161 kissa = 15,
162 koira = 16)
163 import IPython.ipapi
164 print "launching IPython instance"
165 IPython.ipapi.launch_new_instance(my_ns)
166 print "Exited IPython instance!"
167 print "New vals:",my_ns['kissa'], my_ns['koira']
168
169 And here's what it looks like when run (note how we don't start it
170 from an ipython session)::
171
172 Q:\ipython>python test.py
173 launching IPython instance
174 Py 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] IPy 0.7.3b3.r1975
175 [ipython]|1> kissa = 444
176 [ipython]|2> koira = 555
177 [ipython]|3> Exit
178 Exited IPython instance!
179 New vals: 444 555
180
181 Accessing unexposed functionality
182 =================================
183
184 There are still many features that are not exposed via the ipapi. If
185 you can't avoid using them, you can use the functionality in
186 InteractiveShell object (central IPython session class, defined in
187 iplib.py) through ip.IP.
188
189 For example::
190
191 [~]|7> _ip.IP.expand_aliases('np','myfile.py')
192 <7> 'c:/opt/Notepad++/notepad++.exe myfile.py'
193 [~]|8>
194
195 Still, it's preferable that if you encounter such a feature, contact
196 the IPython team and request that the functionality be exposed in a
197 future version of IPython. Things not in ipapi are more likely to
198 change over time.
199
200 Provided extensions
201 ===================
202
203 You can see the list of available extensions (and profiles) by doing
204 ``import ipy_<TAB>``. Some extensions don't have the ``ipy_`` prefix in
205 module name, so you may need to see the contents of IPython/Extensions
206 folder to see what's available.
207
208 You can see a brief documentation of an extension by looking at the
209 module docstring::
210
211 [c:p/ipython_main]|190> import ipy_fsops
212 [c:p/ipython_main]|191> ipy_fsops?
213
214 ...
215
216 Docstring:
217 File system operations
218
219 Contains: Simple variants of normal unix shell commands (icp, imv, irm,
220 imkdir, igrep).
221
222 You can also install your own extensions - the recommended way is to
223 just copy the module to ~/.ipython. Extensions are typically enabled
224 by just importing them (e.g. in ipy_user_conf.py), but some extensions
225 require additional steps, for example::
226
227 [c:p]|192> import ipy_traits_completer
228 [c:p]|193> ipy_traits_completer.activate()
229
230 Note that extensions, even if provided in the stock IPython
231 installation, are not guaranteed to have the same requirements as the
232 rest of IPython - an extension may require external libraries or a
233 newer version of Python than what IPython officially requires. An
234 extension may also be under a more restrictive license than IPython
235 (e.g. ipy_bzr is under GPL).
236
237 Just for reference, the list of bundled extensions at the time of
238 writing is below:
239
240 astyle.py clearcmd.py envpersist.py ext_rescapture.py ibrowse.py
241 igrid.py InterpreterExec.py InterpreterPasteInput.py ipipe.py
242 ipy_app_completers.py ipy_autoreload.py ipy_bzr.py ipy_completers.py
243 ipy_constants.py ipy_defaults.py ipy_editors.py ipy_exportdb.py
244 ipy_extutil.py ipy_fsops.py ipy_gnuglobal.py ipy_kitcfg.py
245 ipy_legacy.py ipy_leo.py ipy_p4.py ipy_profile_doctest.py
246 ipy_profile_none.py ipy_profile_scipy.py ipy_profile_sh.py
247 ipy_profile_zope.py ipy_pydb.py ipy_rehashdir.py ipy_render.py
248 ipy_server.py ipy_signals.py ipy_stock_completers.py
249 ipy_system_conf.py ipy_traits_completer.py ipy_vimserver.py
250 ipy_which.py ipy_workdir.py jobctrl.py ledit.py numeric_formats.py
251 PhysicalQInput.py PhysicalQInteractive.py pickleshare.py
252 pspersistence.py win32clip.py __init__.py No newline at end of file
This diff has been collapsed as it changes many lines, (3163 lines changed) Show them Hide them
@@ -0,0 +1,3163 b''
1 .. IPython documentation master file, created by sphinx-quickstart.py on Mon Mar 24 17:01:34 2008.
2 You can adapt this file completely to your liking, but it should at least
3 contain the root 'toctree' directive.
4
5 =================
6 IPython reference
7 =================
8
9 .. contents::
10
11 .. _Command line options:
12
13 Command-line usage
14 ==================
15
16 You start IPython with the command::
17
18 $ ipython [options] files
19
20 If invoked with no options, it executes all the files listed in sequence
21 and drops you into the interpreter while still acknowledging any options
22 you may have set in your ipythonrc file. This behavior is different from
23 standard Python, which when called as python -i will only execute one
24 file and ignore your configuration setup.
25
26 Please note that some of the configuration options are not available at
27 the command line, simply because they are not practical here. Look into
28 your ipythonrc configuration file for details on those. This file
29 typically installed in the $HOME/.ipython directory. For Windows users,
30 $HOME resolves to C:\\Documents and Settings\\YourUserName in most
31 instances. In the rest of this text, we will refer to this directory as
32 IPYTHONDIR.
33
34 .. _Threading options:
35
36
37 Special Threading Options
38 -------------------------
39
40 The following special options are ONLY valid at the beginning of the
41 command line, and not later. This is because they control the initial-
42 ization of ipython itself, before the normal option-handling mechanism
43 is active.
44
45 -gthread, -qthread, -q4thread, -wthread, -pylab:
46 Only one of these can be given, and it can only be given as
47 the first option passed to IPython (it will have no effect in
48 any other position). They provide threading support for the
49 GTK, Qt (versions 3 and 4) and WXPython toolkits, and for the
50 matplotlib library.
51
52 With any of the first four options, IPython starts running a
53 separate thread for the graphical toolkit's operation, so that
54 you can open and control graphical elements from within an
55 IPython command line, without blocking. All four provide
56 essentially the same functionality, respectively for GTK, Qt3,
57 Qt4 and WXWidgets (via their Python interfaces).
58
59 Note that with -wthread, you can additionally use the
60 -wxversion option to request a specific version of wx to be
61 used. This requires that you have the wxversion Python module
62 installed, which is part of recent wxPython distributions.
63
64 If -pylab is given, IPython loads special support for the mat
65 plotlib library (http://matplotlib.sourceforge.net), allowing
66 interactive usage of any of its backends as defined in the
67 user's ~/.matplotlib/matplotlibrc file. It automatically
68 activates GTK, Qt or WX threading for IPyhton if the choice of
69 matplotlib backend requires it. It also modifies the %run
70 command to correctly execute (without blocking) any
71 matplotlib-based script which calls show() at the end.
72
73 -tk
74 The -g/q/q4/wthread options, and -pylab (if matplotlib is
75 configured to use GTK, Qt3, Qt4 or WX), will normally block Tk
76 graphical interfaces. This means that when either GTK, Qt or WX
77 threading is active, any attempt to open a Tk GUI will result in a
78 dead window, and possibly cause the Python interpreter to crash.
79 An extra option, -tk, is available to address this issue. It can
80 only be given as a second option after any of the above (-gthread,
81 -wthread or -pylab).
82
83 If -tk is given, IPython will try to coordinate Tk threading
84 with GTK, Qt or WX. This is however potentially unreliable, and
85 you will have to test on your platform and Python configuration to
86 determine whether it works for you. Debian users have reported
87 success, apparently due to the fact that Debian builds all of Tcl,
88 Tk, Tkinter and Python with pthreads support. Under other Linux
89 environments (such as Fedora Core 2/3), this option has caused
90 random crashes and lockups of the Python interpreter. Under other
91 operating systems (Mac OSX and Windows), you'll need to try it to
92 find out, since currently no user reports are available.
93
94 There is unfortunately no way for IPython to determine at run time
95 whether -tk will work reliably or not, so you will need to do some
96 experiments before relying on it for regular work.
97
98
99
100 Regular Options
101 ---------------
102
103 After the above threading options have been given, regular options can
104 follow in any order. All options can be abbreviated to their shortest
105 non-ambiguous form and are case-sensitive. One or two dashes can be
106 used. Some options have an alternate short form, indicated after a ``|``.
107
108 Most options can also be set from your ipythonrc configuration file. See
109 the provided example for more details on what the options do. Options
110 given at the command line override the values set in the ipythonrc file.
111
112 All options with a [no] prepended can be specified in negated form
113 (-nooption instead of -option) to turn the feature off.
114
115 -help print a help message and exit.
116
117 -pylab
118 this can only be given as the first option passed to IPython
119 (it will have no effect in any other position). It adds
120 special support for the matplotlib library
121 (http://matplotlib.sourceforge.ne), allowing interactive usage
122 of any of its backends as defined in the user's .matplotlibrc
123 file. It automatically activates GTK or WX threading for
124 IPyhton if the choice of matplotlib backend requires it. It
125 also modifies the %run command to correctly execute (without
126 blocking) any matplotlib-based script which calls show() at
127 the end. See `Matplotlib support`_ for more details.
128
129 -autocall <val>
130 Make IPython automatically call any callable object even if you
131 didn't type explicit parentheses. For example, 'str 43' becomes
132 'str(43)' automatically. The value can be '0' to disable the feature,
133 '1' for smart autocall, where it is not applied if there are no more
134 arguments on the line, and '2' for full autocall, where all callable
135 objects are automatically called (even if no arguments are
136 present). The default is '1'.
137
138 -[no]autoindent
139 Turn automatic indentation on/off.
140
141 -[no]automagic
142 make magic commands automatic (without needing their first character
143 to be %). Type %magic at the IPython prompt for more information.
144
145 -[no]autoedit_syntax
146 When a syntax error occurs after editing a file, automatically
147 open the file to the trouble causing line for convenient
148 fixing.
149
150 -[no]banner Print the initial information banner (default on).
151
152 -c <command>
153 execute the given command string. This is similar to the -c
154 option in the normal Python interpreter.
155
156 -cache_size, cs <n>
157 size of the output cache (maximum number of entries to hold in
158 memory). The default is 1000, you can change it permanently in your
159 config file. Setting it to 0 completely disables the caching system,
160 and the minimum value accepted is 20 (if you provide a value less than
161 20, it is reset to 0 and a warning is issued) This limit is defined
162 because otherwise you'll spend more time re-flushing a too small cache
163 than working.
164
165 -classic, cl
166 Gives IPython a similar feel to the classic Python
167 prompt.
168
169 -colors <scheme>
170 Color scheme for prompts and exception reporting. Currently
171 implemented: NoColor, Linux and LightBG.
172
173 -[no]color_info
174 IPython can display information about objects via a set of functions,
175 and optionally can use colors for this, syntax highlighting source
176 code and various other elements. However, because this information is
177 passed through a pager (like 'less') and many pagers get confused with
178 color codes, this option is off by default. You can test it and turn
179 it on permanently in your ipythonrc file if it works for you. As a
180 reference, the 'less' pager supplied with Mandrake 8.2 works ok, but
181 that in RedHat 7.2 doesn't.
182
183 Test it and turn it on permanently if it works with your
184 system. The magic function %color_info allows you to toggle this
185 interactively for testing.
186
187 -[no]debug
188 Show information about the loading process. Very useful to pin down
189 problems with your configuration files or to get details about
190 session restores.
191
192 -[no]deep_reload:
193 IPython can use the deep_reload module which reloads changes in
194 modules recursively (it replaces the reload() function, so you don't
195 need to change anything to use it). deep_reload() forces a full
196 reload of modules whose code may have changed, which the default
197 reload() function does not.
198
199 When deep_reload is off, IPython will use the normal reload(),
200 but deep_reload will still be available as dreload(). This
201 feature is off by default [which means that you have both
202 normal reload() and dreload()].
203
204 -editor <name>
205 Which editor to use with the %edit command. By default,
206 IPython will honor your EDITOR environment variable (if not
207 set, vi is the Unix default and notepad the Windows one).
208 Since this editor is invoked on the fly by IPython and is
209 meant for editing small code snippets, you may want to use a
210 small, lightweight editor here (in case your default EDITOR is
211 something like Emacs).
212
213 -ipythondir <name>
214 name of your IPython configuration directory IPYTHONDIR. This
215 can also be specified through the environment variable
216 IPYTHONDIR.
217
218 -log, l
219 generate a log file of all input. The file is named
220 ipython_log.py in your current directory (which prevents logs
221 from multiple IPython sessions from trampling each other). You
222 can use this to later restore a session by loading your
223 logfile as a file to be executed with option -logplay (see
224 below).
225
226 -logfile, lf <name> specify the name of your logfile.
227
228 -logplay, lp <name>
229
230 you can replay a previous log. For restoring a session as close as
231 possible to the state you left it in, use this option (don't just run
232 the logfile). With -logplay, IPython will try to reconstruct the
233 previous working environment in full, not just execute the commands in
234 the logfile.
235
236 When a session is restored, logging is automatically turned on
237 again with the name of the logfile it was invoked with (it is
238 read from the log header). So once you've turned logging on for
239 a session, you can quit IPython and reload it as many times as
240 you want and it will continue to log its history and restore
241 from the beginning every time.
242
243 Caveats: there are limitations in this option. The history
244 variables _i*,_* and _dh don't get restored properly. In the
245 future we will try to implement full session saving by writing
246 and retrieving a 'snapshot' of the memory state of IPython. But
247 our first attempts failed because of inherent limitations of
248 Python's Pickle module, so this may have to wait.
249
250 -[no]messages
251 Print messages which IPython collects about its startup
252 process (default on).
253
254 -[no]pdb
255 Automatically call the pdb debugger after every uncaught
256 exception. If you are used to debugging using pdb, this puts
257 you automatically inside of it after any call (either in
258 IPython or in code called by it) which triggers an exception
259 which goes uncaught.
260
261 -pydb
262 Makes IPython use the third party "pydb" package as debugger,
263 instead of pdb. Requires that pydb is installed.
264
265 -[no]pprint
266 ipython can optionally use the pprint (pretty printer) module
267 for displaying results. pprint tends to give a nicer display
268 of nested data structures. If you like it, you can turn it on
269 permanently in your config file (default off).
270
271 -profile, p <name>
272
273 assume that your config file is ipythonrc-<name> or
274 ipy_profile_<name>.py (looks in current dir first, then in
275 IPYTHONDIR). This is a quick way to keep and load multiple
276 config files for different tasks, especially if you use the
277 include option of config files. You can keep a basic
278 IPYTHONDIR/ipythonrc file and then have other 'profiles' which
279 include this one and load extra things for particular
280 tasks. For example:
281
282 1. $HOME/.ipython/ipythonrc : load basic things you always want.
283 2. $HOME/.ipython/ipythonrc-math : load (1) and basic math-related modules.
284 3. $HOME/.ipython/ipythonrc-numeric : load (1) and Numeric and plotting modules.
285
286 Since it is possible to create an endless loop by having
287 circular file inclusions, IPython will stop if it reaches 15
288 recursive inclusions.
289
290 -prompt_in1, pi1 <string>
291 Specify the string used for input prompts. Note that if you
292 are using numbered prompts, the number is represented with a
293 '\#' in the string. Don't forget to quote strings with spaces
294 embedded in them. Default: 'In [\#]:'. Sec. Prompts_
295 discusses in detail all the available escapes to customize
296 your prompts.
297
298 -prompt_in2, pi2 <string>
299 Similar to the previous option, but used for the continuation
300 prompts. The special sequence '\D' is similar to '\#', but
301 with all digits replaced dots (so you can have your
302 continuation prompt aligned with your input prompt). Default:
303 ' .\D.:' (note three spaces at the start for alignment with
304 'In [\#]').
305
306 -prompt_out,po <string>
307 String used for output prompts, also uses numbers like
308 prompt_in1. Default: 'Out[\#]:'
309
310 -quick start in bare bones mode (no config file loaded).
311
312 -rcfile <name>
313 name of your IPython resource configuration file. Normally
314 IPython loads ipythonrc (from current directory) or
315 IPYTHONDIR/ipythonrc.
316
317 If the loading of your config file fails, IPython starts with
318 a bare bones configuration (no modules loaded at all).
319
320 -[no]readline
321 use the readline library, which is needed to support name
322 completion and command history, among other things. It is
323 enabled by default, but may cause problems for users of
324 X/Emacs in Python comint or shell buffers.
325
326 Note that X/Emacs 'eterm' buffers (opened with M-x term) support
327 IPython's readline and syntax coloring fine, only 'emacs' (M-x
328 shell and C-c !) buffers do not.
329
330 -screen_length, sl <n>
331 number of lines of your screen. This is used to control
332 printing of very long strings. Strings longer than this number
333 of lines will be sent through a pager instead of directly
334 printed.
335
336 The default value for this is 0, which means IPython will
337 auto-detect your screen size every time it needs to print certain
338 potentially long strings (this doesn't change the behavior of the
339 'print' keyword, it's only triggered internally). If for some
340 reason this isn't working well (it needs curses support), specify
341 it yourself. Otherwise don't change the default.
342
343 -separate_in, si <string>
344
345 separator before input prompts.
346 Default: '\n'
347
348 -separate_out, so <string>
349 separator before output prompts.
350 Default: nothing.
351
352 -separate_out2, so2
353 separator after output prompts.
354 Default: nothing.
355 For these three options, use the value 0 to specify no separator.
356
357 -nosep
358 shorthand for '-SeparateIn 0 -SeparateOut 0 -SeparateOut2
359 0'. Simply removes all input/output separators.
360
361 -upgrade
362 allows you to upgrade your IPYTHONDIR configuration when you
363 install a new version of IPython. Since new versions may
364 include new command line options or example files, this copies
365 updated ipythonrc-type files. However, it backs up (with a
366 .old extension) all files which it overwrites so that you can
367 merge back any customizations you might have in your personal
368 files. Note that you should probably use %upgrade instead,
369 it's a safer alternative.
370
371
372 -Version print version information and exit.
373
374 -wxversion <string>
375 Select a specific version of wxPython (used in conjunction
376 with -wthread). Requires the wxversion module, part of recent
377 wxPython distributions
378
379 -xmode <modename>
380
381 Mode for exception reporting.
382
383 Valid modes: Plain, Context and Verbose.
384
385 * Plain: similar to python's normal traceback printing.
386 * Context: prints 5 lines of context source code around each
387 line in the traceback.
388 * Verbose: similar to Context, but additionally prints the
389 variables currently visible where the exception happened
390 (shortening their strings if too long). This can potentially be
391 very slow, if you happen to have a huge data structure whose
392 string representation is complex to compute. Your computer may
393 appear to freeze for a while with cpu usage at 100%. If this
394 occurs, you can cancel the traceback with Ctrl-C (maybe hitting it
395 more than once).
396
397 Interactive use
398 ===============
399
400 Warning: IPython relies on the existence of a global variable called
401 _ip which controls the shell itself. If you redefine _ip to anything,
402 bizarre behavior will quickly occur.
403
404 Other than the above warning, IPython is meant to work as a drop-in
405 replacement for the standard interactive interpreter. As such, any code
406 which is valid python should execute normally under IPython (cases where
407 this is not true should be reported as bugs). It does, however, offer
408 many features which are not available at a standard python prompt. What
409 follows is a list of these.
410
411
412 Caution for Windows users
413 -------------------------
414
415 Windows, unfortunately, uses the '\' character as a path
416 separator. This is a terrible choice, because '\' also represents the
417 escape character in most modern programming languages, including
418 Python. For this reason, using '/' character is recommended if you
419 have problems with ``\``. However, in Windows commands '/' flags
420 options, so you can not use it for the root directory. This means that
421 paths beginning at the root must be typed in a contrived manner like:
422 ``%copy \opt/foo/bar.txt \tmp``
423
424 .. _magic:
425
426 Magic command system
427 --------------------
428
429 IPython will treat any line whose first character is a % as a special
430 call to a 'magic' function. These allow you to control the behavior of
431 IPython itself, plus a lot of system-type features. They are all
432 prefixed with a % character, but parameters are given without
433 parentheses or quotes.
434
435 Example: typing '%cd mydir' (without the quotes) changes you working
436 directory to 'mydir', if it exists.
437
438 If you have 'automagic' enabled (in your ipythonrc file, via the command
439 line option -automagic or with the %automagic function), you don't need
440 to type in the % explicitly. IPython will scan its internal list of
441 magic functions and call one if it exists. With automagic on you can
442 then just type 'cd mydir' to go to directory 'mydir'. The automagic
443 system has the lowest possible precedence in name searches, so defining
444 an identifier with the same name as an existing magic function will
445 shadow it for automagic use. You can still access the shadowed magic
446 function by explicitly using the % character at the beginning of the line.
447
448 An example (with automagic on) should clarify all this::
449
450 In [1]: cd ipython # %cd is called by automagic
451
452 /home/fperez/ipython
453
454 In [2]: cd=1 # now cd is just a variable
455
456 In [3]: cd .. # and doesn't work as a function anymore
457
458 ------------------------------
459
460 File "<console>", line 1
461
462 cd ..
463
464 ^
465
466 SyntaxError: invalid syntax
467
468 In [4]: %cd .. # but %cd always works
469
470 /home/fperez
471
472 In [5]: del cd # if you remove the cd variable
473
474 In [6]: cd ipython # automagic can work again
475
476 /home/fperez/ipython
477
478 You can define your own magic functions to extend the system. The
479 following example defines a new magic command, %impall::
480
481 import IPython.ipapi
482
483 ip = IPython.ipapi.get()
484
485 def doimp(self, arg):
486
487 ip = self.api
488
489 ip.ex("import %s; reload(%s); from %s import *" % (
490
491 arg,arg,arg)
492
493 )
494
495 ip.expose_magic('impall', doimp)
496
497 You can also define your own aliased names for magic functions. In your
498 ipythonrc file, placing a line like:
499
500 execute __IP.magic_cl = __IP.magic_clear
501
502 will define %cl as a new name for %clear.
503
504 Type %magic for more information, including a list of all available
505 magic functions at any time and their docstrings. You can also type
506 %magic_function_name? (see sec. 6.4 <#sec:dyn-object-info> for
507 information on the '?' system) to get information about any particular
508 magic function you are interested in.
509
510
511 Magic commands
512 --------------
513
514 The rest of this section is automatically generated for each release
515 from the docstrings in the IPython code. Therefore the formatting is
516 somewhat minimal, but this method has the advantage of having
517 information always in sync with the code.
518
519 A list of all the magic commands available in IPython's default
520 installation follows. This is similar to what you'll see by simply
521 typing %magic at the prompt, but that will also give you information
522 about magic commands you may have added as part of your personal
523 customizations.
524
525 .. magic_start
526
527 **%Exit**::
528
529 Exit IPython without confirmation.
530
531 **%Pprint**::
532
533 Toggle pretty printing on/off.
534
535 **%alias**::
536
537 Define an alias for a system command.
538
539 '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd'
540
541 Then, typing 'alias_name params' will execute the system command 'cmd
542 params' (from your underlying operating system).
543
544 Aliases have lower precedence than magic functions and Python normal
545 variables, so if 'foo' is both a Python variable and an alias, the
546 alias can not be executed until 'del foo' removes the Python variable.
547
548 You can use the %l specifier in an alias definition to represent the
549 whole line when the alias is called. For example:
550
551 In [2]: alias all echo "Input in brackets: <%l>"\
552 In [3]: all hello world\
553 Input in brackets: <hello world>
554
555 You can also define aliases with parameters using %s specifiers (one
556 per parameter):
557
558 In [1]: alias parts echo first %s second %s\
559 In [2]: %parts A B\
560 first A second B\
561 In [3]: %parts A\
562 Incorrect number of arguments: 2 expected.\
563 parts is an alias to: 'echo first %s second %s'
564
565 Note that %l and %s are mutually exclusive. You can only use one or
566 the other in your aliases.
567
568 Aliases expand Python variables just like system calls using ! or !!
569 do: all expressions prefixed with '$' get expanded. For details of
570 the semantic rules, see PEP-215:
571 http://www.python.org/peps/pep-0215.html. This is the library used by
572 IPython for variable expansion. If you want to access a true shell
573 variable, an extra $ is necessary to prevent its expansion by IPython:
574
575 In [6]: alias show echo\
576 In [7]: PATH='A Python string'\
577 In [8]: show $PATH\
578 A Python string\
579 In [9]: show $$PATH\
580 /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:...
581
582 You can use the alias facility to acess all of $PATH. See the %rehash
583 and %rehashx functions, which automatically create aliases for the
584 contents of your $PATH.
585
586 If called with no parameters, %alias prints the current alias table.
587
588 **%autocall**::
589
590 Make functions callable without having to type parentheses.
591
592 Usage:
593
594 %autocall [mode]
595
596 The mode can be one of: 0->Off, 1->Smart, 2->Full. If not given, the
597 value is toggled on and off (remembering the previous state).
598
599 In more detail, these values mean:
600
601 0 -> fully disabled
602
603 1 -> active, but do not apply if there are no arguments on the line.
604
605 In this mode, you get:
606
607 In [1]: callable
608 Out[1]: <built-in function callable>
609
610 In [2]: callable 'hello'
611 ------> callable('hello')
612 Out[2]: False
613
614 2 -> Active always. Even if no arguments are present, the callable
615 object is called:
616
617 In [4]: callable
618 ------> callable()
619
620 Note that even with autocall off, you can still use '/' at the start of
621 a line to treat the first argument on the command line as a function
622 and add parentheses to it:
623
624 In [8]: /str 43
625 ------> str(43)
626 Out[8]: '43'
627
628 **%autoindent**::
629
630 Toggle autoindent on/off (if available).
631
632 **%automagic**::
633
634 Make magic functions callable without having to type the initial %.
635
636 Without argumentsl toggles on/off (when off, you must call it as
637 %automagic, of course). With arguments it sets the value, and you can
638 use any of (case insensitive):
639
640 - on,1,True: to activate
641
642 - off,0,False: to deactivate.
643
644 Note that magic functions have lowest priority, so if there's a
645 variable whose name collides with that of a magic fn, automagic won't
646 work for that function (you get the variable instead). However, if you
647 delete the variable (del var), the previously shadowed magic function
648 becomes visible to automagic again.
649
650 **%bg**::
651
652 Run a job in the background, in a separate thread.
653
654 For example,
655
656 %bg myfunc(x,y,z=1)
657
658 will execute 'myfunc(x,y,z=1)' in a background thread. As soon as the
659 execution starts, a message will be printed indicating the job
660 number. If your job number is 5, you can use
661
662 myvar = jobs.result(5) or myvar = jobs[5].result
663
664 to assign this result to variable 'myvar'.
665
666 IPython has a job manager, accessible via the 'jobs' object. You can
667 type jobs? to get more information about it, and use jobs.<TAB> to see
668 its attributes. All attributes not starting with an underscore are
669 meant for public use.
670
671 In particular, look at the jobs.new() method, which is used to create
672 new jobs. This magic %bg function is just a convenience wrapper
673 around jobs.new(), for expression-based jobs. If you want to create a
674 new job with an explicit function object and arguments, you must call
675 jobs.new() directly.
676
677 The jobs.new docstring also describes in detail several important
678 caveats associated with a thread-based model for background job
679 execution. Type jobs.new? for details.
680
681 You can check the status of all jobs with jobs.status().
682
683 The jobs variable is set by IPython into the Python builtin namespace.
684 If you ever declare a variable named 'jobs', you will shadow this
685 name. You can either delete your global jobs variable to regain
686 access to the job manager, or make a new name and assign it manually
687 to the manager (stored in IPython's namespace). For example, to
688 assign the job manager to the Jobs name, use:
689
690 Jobs = __builtins__.jobs
691
692 **%bookmark**::
693
694 Manage IPython's bookmark system.
695
696 %bookmark <name> - set bookmark to current dir
697 %bookmark <name> <dir> - set bookmark to <dir>
698 %bookmark -l - list all bookmarks
699 %bookmark -d <name> - remove bookmark
700 %bookmark -r - remove all bookmarks
701
702 You can later on access a bookmarked folder with:
703 %cd -b <name>
704 or simply '%cd <name>' if there is no directory called <name> AND
705 there is such a bookmark defined.
706
707 Your bookmarks persist through IPython sessions, but they are
708 associated with each profile.
709
710 **%cd**::
711
712 Change the current working directory.
713
714 This command automatically maintains an internal list of directories
715 you visit during your IPython session, in the variable _dh. The
716 command %dhist shows this history nicely formatted. You can also
717 do 'cd -<tab>' to see directory history conveniently.
718
719 Usage:
720
721 cd 'dir': changes to directory 'dir'.
722
723 cd -: changes to the last visited directory.
724
725 cd -<n>: changes to the n-th directory in the directory history.
726
727 cd -b <bookmark_name>: jump to a bookmark set by %bookmark
728 (note: cd <bookmark_name> is enough if there is no
729 directory <bookmark_name>, but a bookmark with the name exists.)
730 'cd -b <tab>' allows you to tab-complete bookmark names.
731
732 Options:
733
734 -q: quiet. Do not print the working directory after the cd command is
735 executed. By default IPython's cd command does print this directory,
736 since the default prompts do not display path information.
737
738 Note that !cd doesn't work for this purpose because the shell where
739 !command runs is immediately discarded after executing 'command'.
740
741 **%clear**::
742
743 Clear various data (e.g. stored history data)
744
745 %clear out - clear output history
746 %clear in - clear input history
747 %clear shadow_compress - Compresses shadow history (to speed up ipython)
748 %clear shadow_nuke - permanently erase all entries in shadow history
749 %clear dhist - clear dir history
750
751 **%color_info**::
752
753 Toggle color_info.
754
755 The color_info configuration parameter controls whether colors are
756 used for displaying object details (by things like %psource, %pfile or
757 the '?' system). This function toggles this value with each call.
758
759 Note that unless you have a fairly recent pager (less works better
760 than more) in your system, using colored object information displays
761 will not work properly. Test it and see.
762
763 **%colors**::
764
765 Switch color scheme for prompts, info system and exception handlers.
766
767 Currently implemented schemes: NoColor, Linux, LightBG.
768
769 Color scheme names are not case-sensitive.
770
771 **%cpaste**::
772
773 Allows you to paste & execute a pre-formatted code block from clipboard
774
775 You must terminate the block with '--' (two minus-signs) alone on the
776 line. You can also provide your own sentinel with '%paste -s %%' ('%%'
777 is the new sentinel for this operation)
778
779 The block is dedented prior to execution to enable execution of method
780 definitions. '>' and '+' characters at the beginning of a line are
781 ignored, to allow pasting directly from e-mails or diff files. The
782 executed block is also assigned to variable named 'pasted_block' for
783 later editing with '%edit pasted_block'.
784
785 You can also pass a variable name as an argument, e.g. '%cpaste foo'.
786 This assigns the pasted block to variable 'foo' as string, without
787 dedenting or executing it.
788
789 Do not be alarmed by garbled output on Windows (it's a readline bug).
790 Just press enter and type -- (and press enter again) and the block
791 will be what was just pasted.
792
793 IPython statements (magics, shell escapes) are not supported (yet).
794
795 **%debug**::
796
797 Activate the interactive debugger in post-mortem mode.
798
799 If an exception has just occurred, this lets you inspect its stack
800 frames interactively. Note that this will always work only on the last
801 traceback that occurred, so you must call this quickly after an
802 exception that you wish to inspect has fired, because if another one
803 occurs, it clobbers the previous one.
804
805 If you want IPython to automatically do this on every exception, see
806 the %pdb magic for more details.
807
808 **%dhist**::
809
810 Print your history of visited directories.
811
812 %dhist -> print full history\
813 %dhist n -> print last n entries only\
814 %dhist n1 n2 -> print entries between n1 and n2 (n1 not included)\
815
816 This history is automatically maintained by the %cd command, and
817 always available as the global list variable _dh. You can use %cd -<n>
818 to go to directory number <n>.
819
820 Note that most of time, you should view directory history by entering
821 cd -<TAB>.
822
823 **%dirs**::
824
825 Return the current directory stack.
826
827 **%doctest_mode**::
828
829 Toggle doctest mode on and off.
830
831 This mode allows you to toggle the prompt behavior between normal
832 IPython prompts and ones that are as similar to the default IPython
833 interpreter as possible.
834
835 It also supports the pasting of code snippets that have leading '>>>'
836 and '...' prompts in them. This means that you can paste doctests from
837 files or docstrings (even if they have leading whitespace), and the
838 code will execute correctly. You can then use '%history -tn' to see
839 the translated history without line numbers; this will give you the
840 input after removal of all the leading prompts and whitespace, which
841 can be pasted back into an editor.
842
843 With these features, you can switch into this mode easily whenever you
844 need to do testing and changes to doctests, without having to leave
845 your existing IPython session.
846
847 **%ed**::
848
849 Alias to %edit.
850
851 **%edit**::
852
853 Bring up an editor and execute the resulting code.
854
855 Usage:
856 %edit [options] [args]
857
858 %edit runs IPython's editor hook. The default version of this hook is
859 set to call the __IPYTHON__.rc.editor command. This is read from your
860 environment variable $EDITOR. If this isn't found, it will default to
861 vi under Linux/Unix and to notepad under Windows. See the end of this
862 docstring for how to change the editor hook.
863
864 You can also set the value of this editor via the command line option
865 '-editor' or in your ipythonrc file. This is useful if you wish to use
866 specifically for IPython an editor different from your typical default
867 (and for Windows users who typically don't set environment variables).
868
869 This command allows you to conveniently edit multi-line code right in
870 your IPython session.
871
872 If called without arguments, %edit opens up an empty editor with a
873 temporary file and will execute the contents of this file when you
874 close it (don't forget to save it!).
875
876
877 Options:
878
879 -n <number>: open the editor at a specified line number. By default,
880 the IPython editor hook uses the unix syntax 'editor +N filename', but
881 you can configure this by providing your own modified hook if your
882 favorite editor supports line-number specifications with a different
883 syntax.
884
885 -p: this will call the editor with the same data as the previous time
886 it was used, regardless of how long ago (in your current session) it
887 was.
888
889 -r: use 'raw' input. This option only applies to input taken from the
890 user's history. By default, the 'processed' history is used, so that
891 magics are loaded in their transformed version to valid Python. If
892 this option is given, the raw input as typed as the command line is
893 used instead. When you exit the editor, it will be executed by
894 IPython's own processor.
895
896 -x: do not execute the edited code immediately upon exit. This is
897 mainly useful if you are editing programs which need to be called with
898 command line arguments, which you can then do using %run.
899
900
901 Arguments:
902
903 If arguments are given, the following possibilites exist:
904
905 - The arguments are numbers or pairs of colon-separated numbers (like
906 1 4:8 9). These are interpreted as lines of previous input to be
907 loaded into the editor. The syntax is the same of the %macro command.
908
909 - If the argument doesn't start with a number, it is evaluated as a
910 variable and its contents loaded into the editor. You can thus edit
911 any string which contains python code (including the result of
912 previous edits).
913
914 - If the argument is the name of an object (other than a string),
915 IPython will try to locate the file where it was defined and open the
916 editor at the point where it is defined. You can use `%edit function`
917 to load an editor exactly at the point where 'function' is defined,
918 edit it and have the file be executed automatically.
919
920 If the object is a macro (see %macro for details), this opens up your
921 specified editor with a temporary file containing the macro's data.
922 Upon exit, the macro is reloaded with the contents of the file.
923
924 Note: opening at an exact line is only supported under Unix, and some
925 editors (like kedit and gedit up to Gnome 2.8) do not understand the
926 '+NUMBER' parameter necessary for this feature. Good editors like
927 (X)Emacs, vi, jed, pico and joe all do.
928
929 - If the argument is not found as a variable, IPython will look for a
930 file with that name (adding .py if necessary) and load it into the
931 editor. It will execute its contents with execfile() when you exit,
932 loading any code in the file into your interactive namespace.
933
934 After executing your code, %edit will return as output the code you
935 typed in the editor (except when it was an existing file). This way
936 you can reload the code in further invocations of %edit as a variable,
937 via _<NUMBER> or Out[<NUMBER>], where <NUMBER> is the prompt number of
938 the output.
939
940 Note that %edit is also available through the alias %ed.
941
942 This is an example of creating a simple function inside the editor and
943 then modifying it. First, start up the editor:
944
945 In [1]: ed\
946 Editing... done. Executing edited code...\
947 Out[1]: 'def foo():\n print "foo() was defined in an editing session"\n'
948
949 We can then call the function foo():
950
951 In [2]: foo()\
952 foo() was defined in an editing session
953
954 Now we edit foo. IPython automatically loads the editor with the
955 (temporary) file where foo() was previously defined:
956
957 In [3]: ed foo\
958 Editing... done. Executing edited code...
959
960 And if we call foo() again we get the modified version:
961
962 In [4]: foo()\
963 foo() has now been changed!
964
965 Here is an example of how to edit a code snippet successive
966 times. First we call the editor:
967
968 In [8]: ed\
969 Editing... done. Executing edited code...\
970 hello\
971 Out[8]: "print 'hello'\n"
972
973 Now we call it again with the previous output (stored in _):
974
975 In [9]: ed _\
976 Editing... done. Executing edited code...\
977 hello world\
978 Out[9]: "print 'hello world'\n"
979
980 Now we call it with the output #8 (stored in _8, also as Out[8]):
981
982 In [10]: ed _8\
983 Editing... done. Executing edited code...\
984 hello again\
985 Out[10]: "print 'hello again'\n"
986
987
988 Changing the default editor hook:
989
990 If you wish to write your own editor hook, you can put it in a
991 configuration file which you load at startup time. The default hook
992 is defined in the IPython.hooks module, and you can use that as a
993 starting example for further modifications. That file also has
994 general instructions on how to set a new hook for use once you've
995 defined it.
996
997 **%env**::
998
999 List environment variables.
1000
1001 **%exit**::
1002
1003 Exit IPython, confirming if configured to do so.
1004
1005 You can configure whether IPython asks for confirmation upon exit by
1006 setting the confirm_exit flag in the ipythonrc file.
1007
1008 **%hist**::
1009
1010 Alternate name for %history.
1011
1012 **%history**::
1013
1014 Print input history (_i<n> variables), with most recent last.
1015
1016 %history -> print at most 40 inputs (some may be multi-line)\
1017 %history n -> print at most n inputs\
1018 %history n1 n2 -> print inputs between n1 and n2 (n2 not included)\
1019
1020 Each input's number <n> is shown, and is accessible as the
1021 automatically generated variable _i<n>. Multi-line statements are
1022 printed starting at a new line for easy copy/paste.
1023
1024
1025 Options:
1026
1027 -n: do NOT print line numbers. This is useful if you want to get a
1028 printout of many lines which can be directly pasted into a text
1029 editor.
1030
1031 This feature is only available if numbered prompts are in use.
1032
1033 -t: (default) print the 'translated' history, as IPython understands it.
1034 IPython filters your input and converts it all into valid Python source
1035 before executing it (things like magics or aliases are turned into
1036 function calls, for example). With this option, you'll see the native
1037 history instead of the user-entered version: '%cd /' will be seen as
1038 '_ip.magic("%cd /")' instead of '%cd /'.
1039
1040 -r: print the 'raw' history, i.e. the actual commands you typed.
1041
1042 -g: treat the arg as a pattern to grep for in (full) history.
1043 This includes the "shadow history" (almost all commands ever written).
1044 Use '%hist -g' to show full shadow history (may be very long).
1045 In shadow history, every index nuwber starts with 0.
1046
1047 -f FILENAME: instead of printing the output to the screen, redirect it to
1048 the given file. The file is always overwritten, though IPython asks for
1049 confirmation first if it already exists.
1050
1051 **%logoff**::
1052
1053 Temporarily stop logging.
1054
1055 You must have previously started logging.
1056
1057 **%logon**::
1058
1059 Restart logging.
1060
1061 This function is for restarting logging which you've temporarily
1062 stopped with %logoff. For starting logging for the first time, you
1063 must use the %logstart function, which allows you to specify an
1064 optional log filename.
1065
1066 **%logstart**::
1067
1068 Start logging anywhere in a session.
1069
1070 %logstart [-o|-r|-t] [log_name [log_mode]]
1071
1072 If no name is given, it defaults to a file named 'ipython_log.py' in your
1073 current directory, in 'rotate' mode (see below).
1074
1075 '%logstart name' saves to file 'name' in 'backup' mode. It saves your
1076 history up to that point and then continues logging.
1077
1078 %logstart takes a second optional parameter: logging mode. This can be one
1079 of (note that the modes are given unquoted):\
1080 append: well, that says it.\
1081 backup: rename (if exists) to name~ and start name.\
1082 global: single logfile in your home dir, appended to.\
1083 over : overwrite existing log.\
1084 rotate: create rotating logs name.1~, name.2~, etc.
1085
1086 Options:
1087
1088 -o: log also IPython's output. In this mode, all commands which
1089 generate an Out[NN] prompt are recorded to the logfile, right after
1090 their corresponding input line. The output lines are always
1091 prepended with a '#[Out]# ' marker, so that the log remains valid
1092 Python code.
1093
1094 Since this marker is always the same, filtering only the output from
1095 a log is very easy, using for example a simple awk call:
1096
1097 awk -F'#\[Out\]# ' '{if($2) {print $2}}' ipython_log.py
1098
1099 -r: log 'raw' input. Normally, IPython's logs contain the processed
1100 input, so that user lines are logged in their final form, converted
1101 into valid Python. For example, %Exit is logged as
1102 '_ip.magic("Exit"). If the -r flag is given, all input is logged
1103 exactly as typed, with no transformations applied.
1104
1105 -t: put timestamps before each input line logged (these are put in
1106 comments).
1107
1108 **%logstate**::
1109
1110 Print the status of the logging system.
1111
1112 **%logstop**::
1113
1114 Fully stop logging and close log file.
1115
1116 In order to start logging again, a new %logstart call needs to be made,
1117 possibly (though not necessarily) with a new filename, mode and other
1118 options.
1119
1120 **%lsmagic**::
1121
1122 List currently available magic functions.
1123
1124 **%macro**::
1125
1126 Define a set of input lines as a macro for future re-execution.
1127
1128 Usage:\
1129 %macro [options] name n1-n2 n3-n4 ... n5 .. n6 ...
1130
1131 Options:
1132
1133 -r: use 'raw' input. By default, the 'processed' history is used,
1134 so that magics are loaded in their transformed version to valid
1135 Python. If this option is given, the raw input as typed as the
1136 command line is used instead.
1137
1138 This will define a global variable called `name` which is a string
1139 made of joining the slices and lines you specify (n1,n2,... numbers
1140 above) from your input history into a single string. This variable
1141 acts like an automatic function which re-executes those lines as if
1142 you had typed them. You just type 'name' at the prompt and the code
1143 executes.
1144
1145 The notation for indicating number ranges is: n1-n2 means 'use line
1146 numbers n1,...n2' (the endpoint is included). That is, '5-7' means
1147 using the lines numbered 5,6 and 7.
1148
1149 Note: as a 'hidden' feature, you can also use traditional python slice
1150 notation, where N:M means numbers N through M-1.
1151
1152 For example, if your history contains (%hist prints it):
1153
1154 44: x=1\
1155 45: y=3\
1156 46: z=x+y\
1157 47: print x\
1158 48: a=5\
1159 49: print 'x',x,'y',y\
1160
1161 you can create a macro with lines 44 through 47 (included) and line 49
1162 called my_macro with:
1163
1164 In [51]: %macro my_macro 44-47 49
1165
1166 Now, typing `my_macro` (without quotes) will re-execute all this code
1167 in one pass.
1168
1169 You don't need to give the line-numbers in order, and any given line
1170 number can appear multiple times. You can assemble macros with any
1171 lines from your input history in any order.
1172
1173 The macro is a simple object which holds its value in an attribute,
1174 but IPython's display system checks for macros and executes them as
1175 code instead of printing them when you type their name.
1176
1177 You can view a macro's contents by explicitly printing it with:
1178
1179 'print macro_name'.
1180
1181 For one-off cases which DON'T contain magic function calls in them you
1182 can obtain similar results by explicitly executing slices from your
1183 input history with:
1184
1185 In [60]: exec In[44:48]+In[49]
1186
1187 **%magic**::
1188
1189 Print information about the magic function system.
1190
1191 **%mglob**::
1192
1193 This program allows specifying filenames with "mglob" mechanism.
1194 Supported syntax in globs (wilcard matching patterns)::
1195
1196 *.cpp ?ellowo*
1197 - obvious. Differs from normal glob in that dirs are not included.
1198 Unix users might want to write this as: "*.cpp" "?ellowo*"
1199 rec:/usr/share=*.txt,*.doc
1200 - get all *.txt and *.doc under /usr/share,
1201 recursively
1202 rec:/usr/share
1203 - All files under /usr/share, recursively
1204 rec:*.py
1205 - All .py files under current working dir, recursively
1206 foo
1207 - File or dir foo
1208 !*.bak readme*
1209 - readme*, exclude files ending with .bak
1210 !.svn/ !.hg/ !*_Data/ rec:.
1211 - Skip .svn, .hg, foo_Data dirs (and their subdirs) in recurse.
1212 Trailing / is the key, \ does not work!
1213 dir:foo
1214 - the directory foo if it exists (not files in foo)
1215 dir:*
1216 - all directories in current folder
1217 foo.py bar.* !h* rec:*.py
1218 - Obvious. !h* exclusion only applies for rec:*.py.
1219 foo.py is *not* included twice.
1220 @filelist.txt
1221 - All files listed in 'filelist.txt' file, on separate lines.
1222
1223 **%page**::
1224
1225 Pretty print the object and display it through a pager.
1226
1227 %page [options] OBJECT
1228
1229 If no object is given, use _ (last output).
1230
1231 Options:
1232
1233 -r: page str(object), don't pretty-print it.
1234
1235 **%pdb**::
1236
1237 Control the automatic calling of the pdb interactive debugger.
1238
1239 Call as '%pdb on', '%pdb 1', '%pdb off' or '%pdb 0'. If called without
1240 argument it works as a toggle.
1241
1242 When an exception is triggered, IPython can optionally call the
1243 interactive pdb debugger after the traceback printout. %pdb toggles
1244 this feature on and off.
1245
1246 The initial state of this feature is set in your ipythonrc
1247 configuration file (the variable is called 'pdb').
1248
1249 If you want to just activate the debugger AFTER an exception has fired,
1250 without having to type '%pdb on' and rerunning your code, you can use
1251 the %debug magic.
1252
1253 **%pdef**::
1254
1255 Print the definition header for any callable object.
1256
1257 If the object is a class, print the constructor information.
1258
1259 **%pdoc**::
1260
1261 Print the docstring for an object.
1262
1263 If the given object is a class, it will print both the class and the
1264 constructor docstrings.
1265
1266 **%pfile**::
1267
1268 Print (or run through pager) the file where an object is defined.
1269
1270 The file opens at the line where the object definition begins. IPython
1271 will honor the environment variable PAGER if set, and otherwise will
1272 do its best to print the file in a convenient form.
1273
1274 If the given argument is not an object currently defined, IPython will
1275 try to interpret it as a filename (automatically adding a .py extension
1276 if needed). You can thus use %pfile as a syntax highlighting code
1277 viewer.
1278
1279 **%pinfo**::
1280
1281 Provide detailed information about an object.
1282
1283 '%pinfo object' is just a synonym for object? or ?object.
1284
1285 **%popd**::
1286
1287 Change to directory popped off the top of the stack.
1288
1289 **%profile**::
1290
1291 Print your currently active IPyhton profile.
1292
1293 **%prun**::
1294
1295 Run a statement through the python code profiler.
1296
1297 Usage:\
1298 %prun [options] statement
1299
1300 The given statement (which doesn't require quote marks) is run via the
1301 python profiler in a manner similar to the profile.run() function.
1302 Namespaces are internally managed to work correctly; profile.run
1303 cannot be used in IPython because it makes certain assumptions about
1304 namespaces which do not hold under IPython.
1305
1306 Options:
1307
1308 -l <limit>: you can place restrictions on what or how much of the
1309 profile gets printed. The limit value can be:
1310
1311 * A string: only information for function names containing this string
1312 is printed.
1313
1314 * An integer: only these many lines are printed.
1315
1316 * A float (between 0 and 1): this fraction of the report is printed
1317 (for example, use a limit of 0.4 to see the topmost 40% only).
1318
1319 You can combine several limits with repeated use of the option. For
1320 example, '-l __init__ -l 5' will print only the topmost 5 lines of
1321 information about class constructors.
1322
1323 -r: return the pstats.Stats object generated by the profiling. This
1324 object has all the information about the profile in it, and you can
1325 later use it for further analysis or in other functions.
1326
1327 -s <key>: sort profile by given key. You can provide more than one key
1328 by using the option several times: '-s key1 -s key2 -s key3...'. The
1329 default sorting key is 'time'.
1330
1331 The following is copied verbatim from the profile documentation
1332 referenced below:
1333
1334 When more than one key is provided, additional keys are used as
1335 secondary criteria when the there is equality in all keys selected
1336 before them.
1337
1338 Abbreviations can be used for any key names, as long as the
1339 abbreviation is unambiguous. The following are the keys currently
1340 defined:
1341
1342 Valid Arg Meaning\
1343 "calls" call count\
1344 "cumulative" cumulative time\
1345 "file" file name\
1346 "module" file name\
1347 "pcalls" primitive call count\
1348 "line" line number\
1349 "name" function name\
1350 "nfl" name/file/line\
1351 "stdname" standard name\
1352 "time" internal time
1353
1354 Note that all sorts on statistics are in descending order (placing
1355 most time consuming items first), where as name, file, and line number
1356 searches are in ascending order (i.e., alphabetical). The subtle
1357 distinction between "nfl" and "stdname" is that the standard name is a
1358 sort of the name as printed, which means that the embedded line
1359 numbers get compared in an odd way. For example, lines 3, 20, and 40
1360 would (if the file names were the same) appear in the string order
1361 "20" "3" and "40". In contrast, "nfl" does a numeric compare of the
1362 line numbers. In fact, sort_stats("nfl") is the same as
1363 sort_stats("name", "file", "line").
1364
1365 -T <filename>: save profile results as shown on screen to a text
1366 file. The profile is still shown on screen.
1367
1368 -D <filename>: save (via dump_stats) profile statistics to given
1369 filename. This data is in a format understod by the pstats module, and
1370 is generated by a call to the dump_stats() method of profile
1371 objects. The profile is still shown on screen.
1372
1373 If you want to run complete programs under the profiler's control, use
1374 '%run -p [prof_opts] filename.py [args to program]' where prof_opts
1375 contains profiler specific options as described here.
1376
1377 You can read the complete documentation for the profile module with:\
1378 In [1]: import profile; profile.help()
1379
1380 **%psearch**::
1381
1382 Search for object in namespaces by wildcard.
1383
1384 %psearch [options] PATTERN [OBJECT TYPE]
1385
1386 Note: ? can be used as a synonym for %psearch, at the beginning or at
1387 the end: both a*? and ?a* are equivalent to '%psearch a*'. Still, the
1388 rest of the command line must be unchanged (options come first), so
1389 for example the following forms are equivalent
1390
1391 %psearch -i a* function
1392 -i a* function?
1393 ?-i a* function
1394
1395 Arguments:
1396
1397 PATTERN
1398
1399 where PATTERN is a string containing * as a wildcard similar to its
1400 use in a shell. The pattern is matched in all namespaces on the
1401 search path. By default objects starting with a single _ are not
1402 matched, many IPython generated objects have a single
1403 underscore. The default is case insensitive matching. Matching is
1404 also done on the attributes of objects and not only on the objects
1405 in a module.
1406
1407 [OBJECT TYPE]
1408
1409 Is the name of a python type from the types module. The name is
1410 given in lowercase without the ending type, ex. StringType is
1411 written string. By adding a type here only objects matching the
1412 given type are matched. Using all here makes the pattern match all
1413 types (this is the default).
1414
1415 Options:
1416
1417 -a: makes the pattern match even objects whose names start with a
1418 single underscore. These names are normally ommitted from the
1419 search.
1420
1421 -i/-c: make the pattern case insensitive/sensitive. If neither of
1422 these options is given, the default is read from your ipythonrc
1423 file. The option name which sets this value is
1424 'wildcards_case_sensitive'. If this option is not specified in your
1425 ipythonrc file, IPython's internal default is to do a case sensitive
1426 search.
1427
1428 -e/-s NAMESPACE: exclude/search a given namespace. The pattern you
1429 specifiy can be searched in any of the following namespaces:
1430 'builtin', 'user', 'user_global','internal', 'alias', where
1431 'builtin' and 'user' are the search defaults. Note that you should
1432 not use quotes when specifying namespaces.
1433
1434 'Builtin' contains the python module builtin, 'user' contains all
1435 user data, 'alias' only contain the shell aliases and no python
1436 objects, 'internal' contains objects used by IPython. The
1437 'user_global' namespace is only used by embedded IPython instances,
1438 and it contains module-level globals. You can add namespaces to the
1439 search with -s or exclude them with -e (these options can be given
1440 more than once).
1441
1442 Examples:
1443
1444 %psearch a* -> objects beginning with an a
1445 %psearch -e builtin a* -> objects NOT in the builtin space starting in a
1446 %psearch a* function -> all functions beginning with an a
1447 %psearch re.e* -> objects beginning with an e in module re
1448 %psearch r*.e* -> objects that start with e in modules starting in r
1449 %psearch r*.* string -> all strings in modules beginning with r
1450
1451 Case sensitve search:
1452
1453 %psearch -c a* list all object beginning with lower case a
1454
1455 Show objects beginning with a single _:
1456
1457 %psearch -a _* list objects beginning with a single underscore
1458
1459 **%psource**::
1460
1461 Print (or run through pager) the source code for an object.
1462
1463 **%pushd**::
1464
1465 Place the current dir on stack and change directory.
1466
1467 Usage:\
1468 %pushd ['dirname']
1469
1470 **%pwd**::
1471
1472 Return the current working directory path.
1473
1474 **%pycat**::
1475
1476 Show a syntax-highlighted file through a pager.
1477
1478 This magic is similar to the cat utility, but it will assume the file
1479 to be Python source and will show it with syntax highlighting.
1480
1481 **%quickref**::
1482
1483 Show a quick reference sheet
1484
1485 **%quit**::
1486
1487 Exit IPython, confirming if configured to do so (like %exit)
1488
1489 **%r**::
1490
1491 Repeat previous input.
1492
1493 Note: Consider using the more powerfull %rep instead!
1494
1495 If given an argument, repeats the previous command which starts with
1496 the same string, otherwise it just repeats the previous input.
1497
1498 Shell escaped commands (with ! as first character) are not recognized
1499 by this system, only pure python code and magic commands.
1500
1501 **%rehashdir**::
1502
1503 Add executables in all specified dirs to alias table
1504
1505 Usage:
1506
1507 %rehashdir c:/bin;c:/tools
1508 - Add all executables under c:/bin and c:/tools to alias table, in
1509 order to make them directly executable from any directory.
1510
1511 Without arguments, add all executables in current directory.
1512
1513 **%rehashx**::
1514
1515 Update the alias table with all executable files in $PATH.
1516
1517 This version explicitly checks that every entry in $PATH is a file
1518 with execute access (os.X_OK), so it is much slower than %rehash.
1519
1520 Under Windows, it checks executability as a match agains a
1521 '|'-separated string of extensions, stored in the IPython config
1522 variable win_exec_ext. This defaults to 'exe|com|bat'.
1523
1524 This function also resets the root module cache of module completer,
1525 used on slow filesystems.
1526
1527 **%rep**::
1528
1529 Repeat a command, or get command to input line for editing
1530
1531 - %rep (no arguments):
1532
1533 Place a string version of last computation result (stored in the special '_'
1534 variable) to the next input prompt. Allows you to create elaborate command
1535 lines without using copy-paste::
1536
1537 $ l = ["hei", "vaan"]
1538 $ "".join(l)
1539 ==> heivaan
1540 $ %rep
1541 $ heivaan_ <== cursor blinking
1542
1543 %rep 45
1544
1545 Place history line 45 to next input prompt. Use %hist to find out the
1546 number.
1547
1548 %rep 1-4 6-7 3
1549
1550 Repeat the specified lines immediately. Input slice syntax is the same as
1551 in %macro and %save.
1552
1553 %rep foo
1554
1555 Place the most recent line that has the substring "foo" to next input.
1556 (e.g. 'svn ci -m foobar').
1557
1558 **%reset**::
1559
1560 Resets the namespace by removing all names defined by the user.
1561
1562 Input/Output history are left around in case you need them.
1563
1564 **%run**::
1565
1566 Run the named file inside IPython as a program.
1567
1568 Usage:\
1569 %run [-n -i -t [-N<N>] -d [-b<N>] -p [profile options]] file [args]
1570
1571 Parameters after the filename are passed as command-line arguments to
1572 the program (put in sys.argv). Then, control returns to IPython's
1573 prompt.
1574
1575 This is similar to running at a system prompt:\
1576 $ python file args\
1577 but with the advantage of giving you IPython's tracebacks, and of
1578 loading all variables into your interactive namespace for further use
1579 (unless -p is used, see below).
1580
1581 The file is executed in a namespace initially consisting only of
1582 __name__=='__main__' and sys.argv constructed as indicated. It thus
1583 sees its environment as if it were being run as a stand-alone program
1584 (except for sharing global objects such as previously imported
1585 modules). But after execution, the IPython interactive namespace gets
1586 updated with all variables defined in the program (except for __name__
1587 and sys.argv). This allows for very convenient loading of code for
1588 interactive work, while giving each program a 'clean sheet' to run in.
1589
1590 Options:
1591
1592 -n: __name__ is NOT set to '__main__', but to the running file's name
1593 without extension (as python does under import). This allows running
1594 scripts and reloading the definitions in them without calling code
1595 protected by an ' if __name__ == "__main__" ' clause.
1596
1597 -i: run the file in IPython's namespace instead of an empty one. This
1598 is useful if you are experimenting with code written in a text editor
1599 which depends on variables defined interactively.
1600
1601 -e: ignore sys.exit() calls or SystemExit exceptions in the script
1602 being run. This is particularly useful if IPython is being used to
1603 run unittests, which always exit with a sys.exit() call. In such
1604 cases you are interested in the output of the test results, not in
1605 seeing a traceback of the unittest module.
1606
1607 -t: print timing information at the end of the run. IPython will give
1608 you an estimated CPU time consumption for your script, which under
1609 Unix uses the resource module to avoid the wraparound problems of
1610 time.clock(). Under Unix, an estimate of time spent on system tasks
1611 is also given (for Windows platforms this is reported as 0.0).
1612
1613 If -t is given, an additional -N<N> option can be given, where <N>
1614 must be an integer indicating how many times you want the script to
1615 run. The final timing report will include total and per run results.
1616
1617 For example (testing the script uniq_stable.py):
1618
1619 In [1]: run -t uniq_stable
1620
1621 IPython CPU timings (estimated):\
1622 User : 0.19597 s.\
1623 System: 0.0 s.\
1624
1625 In [2]: run -t -N5 uniq_stable
1626
1627 IPython CPU timings (estimated):\
1628 Total runs performed: 5\
1629 Times : Total Per run\
1630 User : 0.910862 s, 0.1821724 s.\
1631 System: 0.0 s, 0.0 s.
1632
1633 -d: run your program under the control of pdb, the Python debugger.
1634 This allows you to execute your program step by step, watch variables,
1635 etc. Internally, what IPython does is similar to calling:
1636
1637 pdb.run('execfile("YOURFILENAME")')
1638
1639 with a breakpoint set on line 1 of your file. You can change the line
1640 number for this automatic breakpoint to be <N> by using the -bN option
1641 (where N must be an integer). For example:
1642
1643 %run -d -b40 myscript
1644
1645 will set the first breakpoint at line 40 in myscript.py. Note that
1646 the first breakpoint must be set on a line which actually does
1647 something (not a comment or docstring) for it to stop execution.
1648
1649 When the pdb debugger starts, you will see a (Pdb) prompt. You must
1650 first enter 'c' (without qoutes) to start execution up to the first
1651 breakpoint.
1652
1653 Entering 'help' gives information about the use of the debugger. You
1654 can easily see pdb's full documentation with "import pdb;pdb.help()"
1655 at a prompt.
1656
1657 -p: run program under the control of the Python profiler module (which
1658 prints a detailed report of execution times, function calls, etc).
1659
1660 You can pass other options after -p which affect the behavior of the
1661 profiler itself. See the docs for %prun for details.
1662
1663 In this mode, the program's variables do NOT propagate back to the
1664 IPython interactive namespace (because they remain in the namespace
1665 where the profiler executes them).
1666
1667 Internally this triggers a call to %prun, see its documentation for
1668 details on the options available specifically for profiling.
1669
1670 There is one special usage for which the text above doesn't apply:
1671 if the filename ends with .ipy, the file is run as ipython script,
1672 just as if the commands were written on IPython prompt.
1673
1674 **%runlog**::
1675
1676 Run files as logs.
1677
1678 Usage:\
1679 %runlog file1 file2 ...
1680
1681 Run the named files (treating them as log files) in sequence inside
1682 the interpreter, and return to the prompt. This is much slower than
1683 %run because each line is executed in a try/except block, but it
1684 allows running files with syntax errors in them.
1685
1686 Normally IPython will guess when a file is one of its own logfiles, so
1687 you can typically use %run even for logs. This shorthand allows you to
1688 force any file to be treated as a log file.
1689
1690 **%save**::
1691
1692 Save a set of lines to a given filename.
1693
1694 Usage:\
1695 %save [options] filename n1-n2 n3-n4 ... n5 .. n6 ...
1696
1697 Options:
1698
1699 -r: use 'raw' input. By default, the 'processed' history is used,
1700 so that magics are loaded in their transformed version to valid
1701 Python. If this option is given, the raw input as typed as the
1702 command line is used instead.
1703
1704 This function uses the same syntax as %macro for line extraction, but
1705 instead of creating a macro it saves the resulting string to the
1706 filename you specify.
1707
1708 It adds a '.py' extension to the file if you don't do so yourself, and
1709 it asks for confirmation before overwriting existing files.
1710
1711 **%sc**::
1712
1713 Shell capture - execute a shell command and capture its output.
1714
1715 DEPRECATED. Suboptimal, retained for backwards compatibility.
1716
1717 You should use the form 'var = !command' instead. Example:
1718
1719 "%sc -l myfiles = ls ~" should now be written as
1720
1721 "myfiles = !ls ~"
1722
1723 myfiles.s, myfiles.l and myfiles.n still apply as documented
1724 below.
1725
1726 --
1727 %sc [options] varname=command
1728
1729 IPython will run the given command using commands.getoutput(), and
1730 will then update the user's interactive namespace with a variable
1731 called varname, containing the value of the call. Your command can
1732 contain shell wildcards, pipes, etc.
1733
1734 The '=' sign in the syntax is mandatory, and the variable name you
1735 supply must follow Python's standard conventions for valid names.
1736
1737 (A special format without variable name exists for internal use)
1738
1739 Options:
1740
1741 -l: list output. Split the output on newlines into a list before
1742 assigning it to the given variable. By default the output is stored
1743 as a single string.
1744
1745 -v: verbose. Print the contents of the variable.
1746
1747 In most cases you should not need to split as a list, because the
1748 returned value is a special type of string which can automatically
1749 provide its contents either as a list (split on newlines) or as a
1750 space-separated string. These are convenient, respectively, either
1751 for sequential processing or to be passed to a shell command.
1752
1753 For example:
1754
1755 # Capture into variable a
1756 In [9]: sc a=ls *py
1757
1758 # a is a string with embedded newlines
1759 In [10]: a
1760 Out[10]: 'setup.py win32_manual_post_install.py'
1761
1762 # which can be seen as a list:
1763 In [11]: a.l
1764 Out[11]: ['setup.py', 'win32_manual_post_install.py']
1765
1766 # or as a whitespace-separated string:
1767 In [12]: a.s
1768 Out[12]: 'setup.py win32_manual_post_install.py'
1769
1770 # a.s is useful to pass as a single command line:
1771 In [13]: !wc -l $a.s
1772 146 setup.py
1773 130 win32_manual_post_install.py
1774 276 total
1775
1776 # while the list form is useful to loop over:
1777 In [14]: for f in a.l:
1778 ....: !wc -l $f
1779 ....:
1780 146 setup.py
1781 130 win32_manual_post_install.py
1782
1783 Similiarly, the lists returned by the -l option are also special, in
1784 the sense that you can equally invoke the .s attribute on them to
1785 automatically get a whitespace-separated string from their contents:
1786
1787 In [1]: sc -l b=ls *py
1788
1789 In [2]: b
1790 Out[2]: ['setup.py', 'win32_manual_post_install.py']
1791
1792 In [3]: b.s
1793 Out[3]: 'setup.py win32_manual_post_install.py'
1794
1795 In summary, both the lists and strings used for ouptut capture have
1796 the following special attributes:
1797
1798 .l (or .list) : value as list.
1799 .n (or .nlstr): value as newline-separated string.
1800 .s (or .spstr): value as space-separated string.
1801
1802 **%store**::
1803
1804 Lightweight persistence for python variables.
1805
1806 Example:
1807
1808 ville@badger[~]|1> A = ['hello',10,'world']\
1809 ville@badger[~]|2> %store A\
1810 ville@badger[~]|3> Exit
1811
1812 (IPython session is closed and started again...)
1813
1814 ville@badger:~$ ipython -p pysh\
1815 ville@badger[~]|1> print A
1816
1817 ['hello', 10, 'world']
1818
1819 Usage:
1820
1821 %store - Show list of all variables and their current values\
1822 %store <var> - Store the *current* value of the variable to disk\
1823 %store -d <var> - Remove the variable and its value from storage\
1824 %store -z - Remove all variables from storage\
1825 %store -r - Refresh all variables from store (delete current vals)\
1826 %store foo >a.txt - Store value of foo to new file a.txt\
1827 %store foo >>a.txt - Append value of foo to file a.txt\
1828
1829 It should be noted that if you change the value of a variable, you
1830 need to %store it again if you want to persist the new value.
1831
1832 Note also that the variables will need to be pickleable; most basic
1833 python types can be safely %stored.
1834
1835 Also aliases can be %store'd across sessions.
1836
1837 **%sx**::
1838
1839 Shell execute - run a shell command and capture its output.
1840
1841 %sx command
1842
1843 IPython will run the given command using commands.getoutput(), and
1844 return the result formatted as a list (split on '\n'). Since the
1845 output is _returned_, it will be stored in ipython's regular output
1846 cache Out[N] and in the '_N' automatic variables.
1847
1848 Notes:
1849
1850 1) If an input line begins with '!!', then %sx is automatically
1851 invoked. That is, while:
1852 !ls
1853 causes ipython to simply issue system('ls'), typing
1854 !!ls
1855 is a shorthand equivalent to:
1856 %sx ls
1857
1858 2) %sx differs from %sc in that %sx automatically splits into a list,
1859 like '%sc -l'. The reason for this is to make it as easy as possible
1860 to process line-oriented shell output via further python commands.
1861 %sc is meant to provide much finer control, but requires more
1862 typing.
1863
1864 3) Just like %sc -l, this is a list with special attributes:
1865
1866 .l (or .list) : value as list.
1867 .n (or .nlstr): value as newline-separated string.
1868 .s (or .spstr): value as whitespace-separated string.
1869
1870 This is very useful when trying to use such lists as arguments to
1871 system commands.
1872
1873 **%system_verbose**::
1874
1875 Set verbose printing of system calls.
1876
1877 If called without an argument, act as a toggle
1878
1879 **%time**::
1880
1881 Time execution of a Python statement or expression.
1882
1883 The CPU and wall clock times are printed, and the value of the
1884 expression (if any) is returned. Note that under Win32, system time
1885 is always reported as 0, since it can not be measured.
1886
1887 This function provides very basic timing functionality. In Python
1888 2.3, the timeit module offers more control and sophistication, so this
1889 could be rewritten to use it (patches welcome).
1890
1891 Some examples:
1892
1893 In [1]: time 2**128
1894 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
1895 Wall time: 0.00
1896 Out[1]: 340282366920938463463374607431768211456L
1897
1898 In [2]: n = 1000000
1899
1900 In [3]: time sum(range(n))
1901 CPU times: user 1.20 s, sys: 0.05 s, total: 1.25 s
1902 Wall time: 1.37
1903 Out[3]: 499999500000L
1904
1905 In [4]: time print 'hello world'
1906 hello world
1907 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
1908 Wall time: 0.00
1909
1910 Note that the time needed by Python to compile the given expression
1911 will be reported if it is more than 0.1s. In this example, the
1912 actual exponentiation is done by Python at compilation time, so while
1913 the expression can take a noticeable amount of time to compute, that
1914 time is purely due to the compilation:
1915
1916 In [5]: time 3**9999;
1917 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
1918 Wall time: 0.00 s
1919
1920 In [6]: time 3**999999;
1921 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
1922 Wall time: 0.00 s
1923 Compiler : 0.78 s
1924
1925 **%timeit**::
1926
1927 Time execution of a Python statement or expression
1928
1929 Usage:\
1930 %timeit [-n<N> -r<R> [-t|-c]] statement
1931
1932 Time execution of a Python statement or expression using the timeit
1933 module.
1934
1935 Options:
1936 -n<N>: execute the given statement <N> times in a loop. If this value
1937 is not given, a fitting value is chosen.
1938
1939 -r<R>: repeat the loop iteration <R> times and take the best result.
1940 Default: 3
1941
1942 -t: use time.time to measure the time, which is the default on Unix.
1943 This function measures wall time.
1944
1945 -c: use time.clock to measure the time, which is the default on
1946 Windows and measures wall time. On Unix, resource.getrusage is used
1947 instead and returns the CPU user time.
1948
1949 -p<P>: use a precision of <P> digits to display the timing result.
1950 Default: 3
1951
1952
1953 Examples:\
1954 In [1]: %timeit pass
1955 10000000 loops, best of 3: 53.3 ns per loop
1956
1957 In [2]: u = None
1958
1959 In [3]: %timeit u is None
1960 10000000 loops, best of 3: 184 ns per loop
1961
1962 In [4]: %timeit -r 4 u == None
1963 1000000 loops, best of 4: 242 ns per loop
1964
1965 In [5]: import time
1966
1967 In [6]: %timeit -n1 time.sleep(2)
1968 1 loops, best of 3: 2 s per loop
1969
1970
1971 The times reported by %timeit will be slightly higher than those
1972 reported by the timeit.py script when variables are accessed. This is
1973 due to the fact that %timeit executes the statement in the namespace
1974 of the shell, compared with timeit.py, which uses a single setup
1975 statement to import function or create variables. Generally, the bias
1976 does not matter as long as results from timeit.py are not mixed with
1977 those from %timeit.
1978
1979 **%unalias**::
1980
1981 Remove an alias
1982
1983 **%upgrade**::
1984
1985 Upgrade your IPython installation
1986
1987 This will copy the config files that don't yet exist in your
1988 ipython dir from the system config dir. Use this after upgrading
1989 IPython if you don't wish to delete your .ipython dir.
1990
1991 Call with -nolegacy to get rid of ipythonrc* files (recommended for
1992 new users)
1993
1994 **%which**::
1995
1996 %which <cmd> => search PATH for files matching cmd. Also scans aliases.
1997
1998 Traverses PATH and prints all files (not just executables!) that match the
1999 pattern on command line. Probably more useful in finding stuff
2000 interactively than 'which', which only prints the first matching item.
2001
2002 Also discovers and expands aliases, so you'll see what will be executed
2003 when you call an alias.
2004
2005 Example:
2006
2007 [~]|62> %which d
2008 d -> ls -F --color=auto
2009 == c:\cygwin\bin\ls.exe
2010 c:\cygwin\bin\d.exe
2011
2012 [~]|64> %which diff*
2013 diff3 -> diff3
2014 == c:\cygwin\bin\diff3.exe
2015 diff -> diff
2016 == c:\cygwin\bin\diff.exe
2017 c:\cygwin\bin\diff.exe
2018 c:\cygwin\bin\diff3.exe
2019
2020 **%who**::
2021
2022 Print all interactive variables, with some minimal formatting.
2023
2024 If any arguments are given, only variables whose type matches one of
2025 these are printed. For example:
2026
2027 %who function str
2028
2029 will only list functions and strings, excluding all other types of
2030 variables. To find the proper type names, simply use type(var) at a
2031 command line to see how python prints type names. For example:
2032
2033 In [1]: type('hello')\
2034 Out[1]: <type 'str'>
2035
2036 indicates that the type name for strings is 'str'.
2037
2038 %who always excludes executed names loaded through your configuration
2039 file and things which are internal to IPython.
2040
2041 This is deliberate, as typically you may load many modules and the
2042 purpose of %who is to show you only what you've manually defined.
2043
2044 **%who_ls**::
2045
2046 Return a sorted list of all interactive variables.
2047
2048 If arguments are given, only variables of types matching these
2049 arguments are returned.
2050
2051 **%whos**::
2052
2053 Like %who, but gives some extra information about each variable.
2054
2055 The same type filtering of %who can be applied here.
2056
2057 For all variables, the type is printed. Additionally it prints:
2058
2059 - For {},[],(): their length.
2060
2061 - For numpy and Numeric arrays, a summary with shape, number of
2062 elements, typecode and size in memory.
2063
2064 - Everything else: a string representation, snipping their middle if
2065 too long.
2066
2067 **%xmode**::
2068
2069 Switch modes for the exception handlers.
2070
2071 Valid modes: Plain, Context and Verbose.
2072
2073 If called without arguments, acts as a toggle.
2074
2075 .. magic_end
2076
2077 Access to the standard Python help
2078 ----------------------------------
2079
2080 As of Python 2.1, a help system is available with access to object
2081 docstrings and the Python manuals. Simply type 'help' (no quotes) to
2082 access it. You can also type help(object) to obtain information about a
2083 given object, and help('keyword') for information on a keyword. As noted
2084 in sec. `accessing help`_, you need to properly configure
2085 your environment variable PYTHONDOCS for this feature to work correctly.
2086
2087
2088 Dynamic object information
2089 --------------------------
2090
2091 Typing ?word or word? prints detailed information about an object. If
2092 certain strings in the object are too long (docstrings, code, etc.) they
2093 get snipped in the center for brevity. This system gives access variable
2094 types and values, full source code for any object (if available),
2095 function prototypes and other useful information.
2096
2097 Typing ??word or word?? gives access to the full information without
2098 snipping long strings. Long strings are sent to the screen through the
2099 less pager if longer than the screen and printed otherwise. On systems
2100 lacking the less command, IPython uses a very basic internal pager.
2101
2102 The following magic functions are particularly useful for gathering
2103 information about your working environment. You can get more details by
2104 typing %magic or querying them individually (use %function_name? with or
2105 without the %), this is just a summary:
2106
2107 * **%pdoc <object>**: Print (or run through a pager if too long) the
2108 docstring for an object. If the given object is a class, it will
2109 print both the class and the constructor docstrings.
2110 * **%pdef <object>**: Print the definition header for any callable
2111 object. If the object is a class, print the constructor information.
2112 * **%psource <object>**: Print (or run through a pager if too long)
2113 the source code for an object.
2114 * **%pfile <object>**: Show the entire source file where an object was
2115 defined via a pager, opening it at the line where the object
2116 definition begins.
2117 * **%who/%whos**: These functions give information about identifiers
2118 you have defined interactively (not things you loaded or defined
2119 in your configuration files). %who just prints a list of
2120 identifiers and %whos prints a table with some basic details about
2121 each identifier.
2122
2123 Note that the dynamic object information functions (?/??, %pdoc, %pfile,
2124 %pdef, %psource) give you access to documentation even on things which
2125 are not really defined as separate identifiers. Try for example typing
2126 {}.get? or after doing import os, type os.path.abspath??.
2127
2128
2129 .. _Readline:
2130
2131 Readline-based features
2132 -----------------------
2133
2134 These features require the GNU readline library, so they won't work if
2135 your Python installation lacks readline support. We will first describe
2136 the default behavior IPython uses, and then how to change it to suit
2137 your preferences.
2138
2139
2140 Command line completion
2141 +++++++++++++++++++++++
2142
2143 At any time, hitting TAB will complete any available python commands or
2144 variable names, and show you a list of the possible completions if
2145 there's no unambiguous one. It will also complete filenames in the
2146 current directory if no python names match what you've typed so far.
2147
2148
2149 Search command history
2150 ++++++++++++++++++++++
2151
2152 IPython provides two ways for searching through previous input and thus
2153 reduce the need for repetitive typing:
2154
2155 1. Start typing, and then use Ctrl-p (previous,up) and Ctrl-n
2156 (next,down) to search through only the history items that match
2157 what you've typed so far. If you use Ctrl-p/Ctrl-n at a blank
2158 prompt, they just behave like normal arrow keys.
2159 2. Hit Ctrl-r: opens a search prompt. Begin typing and the system
2160 searches your history for lines that contain what you've typed so
2161 far, completing as much as it can.
2162
2163
2164 Persistent command history across sessions
2165 ++++++++++++++++++++++++++++++++++++++++++
2166
2167 IPython will save your input history when it leaves and reload it next
2168 time you restart it. By default, the history file is named
2169 $IPYTHONDIR/history, but if you've loaded a named profile,
2170 '-PROFILE_NAME' is appended to the name. This allows you to keep
2171 separate histories related to various tasks: commands related to
2172 numerical work will not be clobbered by a system shell history, for
2173 example.
2174
2175
2176 Autoindent
2177 ++++++++++
2178
2179 IPython can recognize lines ending in ':' and indent the next line,
2180 while also un-indenting automatically after 'raise' or 'return'.
2181
2182 This feature uses the readline library, so it will honor your ~/.inputrc
2183 configuration (or whatever file your INPUTRC variable points to). Adding
2184 the following lines to your .inputrc file can make indenting/unindenting
2185 more convenient (M-i indents, M-u unindents)::
2186
2187 $if Python
2188 "\M-i": " "
2189 "\M-u": "\d\d\d\d"
2190 $endif
2191
2192 Note that there are 4 spaces between the quote marks after "M-i" above.
2193
2194 Warning: this feature is ON by default, but it can cause problems with
2195 the pasting of multi-line indented code (the pasted code gets
2196 re-indented on each line). A magic function %autoindent allows you to
2197 toggle it on/off at runtime. You can also disable it permanently on in
2198 your ipythonrc file (set autoindent 0).
2199
2200
2201 Customizing readline behavior
2202 +++++++++++++++++++++++++++++
2203
2204 All these features are based on the GNU readline library, which has an
2205 extremely customizable interface. Normally, readline is configured via a
2206 file which defines the behavior of the library; the details of the
2207 syntax for this can be found in the readline documentation available
2208 with your system or on the Internet. IPython doesn't read this file (if
2209 it exists) directly, but it does support passing to readline valid
2210 options via a simple interface. In brief, you can customize readline by
2211 setting the following options in your ipythonrc configuration file (note
2212 that these options can not be specified at the command line):
2213
2214 * **readline_parse_and_bind**: this option can appear as many times as
2215 you want, each time defining a string to be executed via a
2216 readline.parse_and_bind() command. The syntax for valid commands
2217 of this kind can be found by reading the documentation for the GNU
2218 readline library, as these commands are of the kind which readline
2219 accepts in its configuration file.
2220 * **readline_remove_delims**: a string of characters to be removed
2221 from the default word-delimiters list used by readline, so that
2222 completions may be performed on strings which contain them. Do not
2223 change the default value unless you know what you're doing.
2224 * **readline_omit__names**: when tab-completion is enabled, hitting
2225 <tab> after a '.' in a name will complete all attributes of an
2226 object, including all the special methods whose names include
2227 double underscores (like __getitem__ or __class__). If you'd
2228 rather not see these names by default, you can set this option to
2229 1. Note that even when this option is set, you can still see those
2230 names by explicitly typing a _ after the period and hitting <tab>:
2231 'name._<tab>' will always complete attribute names starting with '_'.
2232
2233 This option is off by default so that new users see all
2234 attributes of any objects they are dealing with.
2235
2236 You will find the default values along with a corresponding detailed
2237 explanation in your ipythonrc file.
2238
2239
2240 Session logging and restoring
2241 -----------------------------
2242
2243 You can log all input from a session either by starting IPython with
2244 the command line switches -log or -logfile (see sec. `command line
2245 options`_) or by activating the logging at any moment with the magic
2246 function %logstart.
2247
2248 Log files can later be reloaded with the -logplay option and IPython
2249 will attempt to 'replay' the log by executing all the lines in it, thus
2250 restoring the state of a previous session. This feature is not quite
2251 perfect, but can still be useful in many cases.
2252
2253 The log files can also be used as a way to have a permanent record of
2254 any code you wrote while experimenting. Log files are regular text files
2255 which you can later open in your favorite text editor to extract code or
2256 to 'clean them up' before using them to replay a session.
2257
2258 The %logstart function for activating logging in mid-session is used as
2259 follows:
2260
2261 %logstart [log_name [log_mode]]
2262
2263 If no name is given, it defaults to a file named 'log' in your
2264 IPYTHONDIR directory, in 'rotate' mode (see below).
2265
2266 '%logstart name' saves to file 'name' in 'backup' mode. It saves your
2267 history up to that point and then continues logging.
2268
2269 %logstart takes a second optional parameter: logging mode. This can be
2270 one of (note that the modes are given unquoted):
2271
2272 * [over:] overwrite existing log_name.
2273 * [backup:] rename (if exists) to log_name~ and start log_name.
2274 * [append:] well, that says it.
2275 * [rotate:] create rotating logs log_name.1~, log_name.2~, etc.
2276
2277 The %logoff and %logon functions allow you to temporarily stop and
2278 resume logging to a file which had previously been started with
2279 %logstart. They will fail (with an explanation) if you try to use them
2280 before logging has been started.
2281
2282 System shell access
2283 -------------------
2284
2285 Any input line beginning with a ! character is passed verbatim (minus
2286 the !, of course) to the underlying operating system. For example,
2287 typing !ls will run 'ls' in the current directory.
2288
2289 Manual capture of command output
2290 --------------------------------
2291
2292 If the input line begins with two exclamation marks, !!, the command is
2293 executed but its output is captured and returned as a python list, split
2294 on newlines. Any output sent by the subprocess to standard error is
2295 printed separately, so that the resulting list only captures standard
2296 output. The !! syntax is a shorthand for the %sx magic command.
2297
2298 Finally, the %sc magic (short for 'shell capture') is similar to %sx,
2299 but allowing more fine-grained control of the capture details, and
2300 storing the result directly into a named variable. The direct use of
2301 %sc is now deprecated, and you should ise the ``var = !cmd`` syntax
2302 instead.
2303
2304 IPython also allows you to expand the value of python variables when
2305 making system calls. Any python variable or expression which you prepend
2306 with $ will get expanded before the system call is made::
2307
2308 In [1]: pyvar='Hello world'
2309 In [2]: !echo "A python variable: $pyvar"
2310 A python variable: Hello world
2311
2312 If you want the shell to actually see a literal $, you need to type it
2313 twice::
2314
2315 In [3]: !echo "A system variable: $$HOME"
2316 A system variable: /home/fperez
2317
2318 You can pass arbitrary expressions, though you'll need to delimit them
2319 with {} if there is ambiguity as to the extent of the expression::
2320
2321 In [5]: x=10
2322 In [6]: y=20
2323 In [13]: !echo $x+y
2324 10+y
2325 In [7]: !echo ${x+y}
2326 30
2327
2328 Even object attributes can be expanded::
2329
2330 In [12]: !echo $sys.argv
2331 [/home/fperez/usr/bin/ipython]
2332
2333
2334 System command aliases
2335 ----------------------
2336
2337 The %alias magic function and the alias option in the ipythonrc
2338 configuration file allow you to define magic functions which are in fact
2339 system shell commands. These aliases can have parameters.
2340
2341 '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd'
2342
2343 Then, typing '%alias_name params' will execute the system command 'cmd
2344 params' (from your underlying operating system).
2345
2346 You can also define aliases with parameters using %s specifiers (one per
2347 parameter). The following example defines the %parts function as an
2348 alias to the command 'echo first %s second %s' where each %s will be
2349 replaced by a positional parameter to the call to %parts::
2350
2351 In [1]: alias parts echo first %s second %s
2352 In [2]: %parts A B
2353 first A second B
2354 In [3]: %parts A
2355 Incorrect number of arguments: 2 expected.
2356 parts is an alias to: 'echo first %s second %s'
2357
2358 If called with no parameters, %alias prints the table of currently
2359 defined aliases.
2360
2361 The %rehash/rehashx magics allow you to load your entire $PATH as
2362 ipython aliases. See their respective docstrings (or sec. 6.2
2363 <#sec:magic> for further details).
2364
2365
2366 .. _dreload:
2367
2368 Recursive reload
2369 ----------------
2370
2371 The dreload function does a recursive reload of a module: changes made
2372 to the module since you imported will actually be available without
2373 having to exit.
2374
2375
2376 Verbose and colored exception traceback printouts
2377 -------------------------------------------------
2378
2379 IPython provides the option to see very detailed exception tracebacks,
2380 which can be especially useful when debugging large programs. You can
2381 run any Python file with the %run function to benefit from these
2382 detailed tracebacks. Furthermore, both normal and verbose tracebacks can
2383 be colored (if your terminal supports it) which makes them much easier
2384 to parse visually.
2385
2386 See the magic xmode and colors functions for details (just type %magic).
2387
2388 These features are basically a terminal version of Ka-Ping Yee's cgitb
2389 module, now part of the standard Python library.
2390
2391
2392 .. _Input caching:
2393
2394 Input caching system
2395 --------------------
2396
2397 IPython offers numbered prompts (In/Out) with input and output caching.
2398 All input is saved and can be retrieved as variables (besides the usual
2399 arrow key recall).
2400
2401 The following GLOBAL variables always exist (so don't overwrite them!):
2402 _i: stores previous input. _ii: next previous. _iii: next-next previous.
2403 _ih : a list of all input _ih[n] is the input from line n and this list
2404 is aliased to the global variable In. If you overwrite In with a
2405 variable of your own, you can remake the assignment to the internal list
2406 with a simple 'In=_ih'.
2407
2408 Additionally, global variables named _i<n> are dynamically created (<n>
2409 being the prompt counter), such that
2410 _i<n> == _ih[<n>] == In[<n>].
2411
2412 For example, what you typed at prompt 14 is available as _i14, _ih[14]
2413 and In[14].
2414
2415 This allows you to easily cut and paste multi line interactive prompts
2416 by printing them out: they print like a clean string, without prompt
2417 characters. You can also manipulate them like regular variables (they
2418 are strings), modify or exec them (typing 'exec _i9' will re-execute the
2419 contents of input prompt 9, 'exec In[9:14]+In[18]' will re-execute lines
2420 9 through 13 and line 18).
2421
2422 You can also re-execute multiple lines of input easily by using the
2423 magic %macro function (which automates the process and allows
2424 re-execution without having to type 'exec' every time). The macro system
2425 also allows you to re-execute previous lines which include magic
2426 function calls (which require special processing). Type %macro? or see
2427 sec. 6.2 <#sec:magic> for more details on the macro system.
2428
2429 A history function %hist allows you to see any part of your input
2430 history by printing a range of the _i variables.
2431
2432 .. _Output caching:
2433
2434 Output caching system
2435 ---------------------
2436
2437 For output that is returned from actions, a system similar to the input
2438 cache exists but using _ instead of _i. Only actions that produce a
2439 result (NOT assignments, for example) are cached. If you are familiar
2440 with Mathematica, IPython's _ variables behave exactly like
2441 Mathematica's % variables.
2442
2443 The following GLOBAL variables always exist (so don't overwrite them!):
2444
2445 * [_] (a single underscore) : stores previous output, like Python's
2446 default interpreter.
2447 * [__] (two underscores): next previous.
2448 * [___] (three underscores): next-next previous.
2449
2450 Additionally, global variables named _<n> are dynamically created (<n>
2451 being the prompt counter), such that the result of output <n> is always
2452 available as _<n> (don't use the angle brackets, just the number, e.g.
2453 _21).
2454
2455 These global variables are all stored in a global dictionary (not a
2456 list, since it only has entries for lines which returned a result)
2457 available under the names _oh and Out (similar to _ih and In). So the
2458 output from line 12 can be obtained as _12, Out[12] or _oh[12]. If you
2459 accidentally overwrite the Out variable you can recover it by typing
2460 'Out=_oh' at the prompt.
2461
2462 This system obviously can potentially put heavy memory demands on your
2463 system, since it prevents Python's garbage collector from removing any
2464 previously computed results. You can control how many results are kept
2465 in memory with the option (at the command line or in your ipythonrc
2466 file) cache_size. If you set it to 0, the whole system is completely
2467 disabled and the prompts revert to the classic '>>>' of normal Python.
2468
2469
2470 Directory history
2471 -----------------
2472
2473 Your history of visited directories is kept in the global list _dh, and
2474 the magic %cd command can be used to go to any entry in that list. The
2475 %dhist command allows you to view this history. do ``cd -<TAB`` to
2476 conventiently view the directory history.
2477
2478
2479 Automatic parentheses and quotes
2480 --------------------------------
2481
2482 These features were adapted from Nathan Gray's LazyPython. They are
2483 meant to allow less typing for common situations.
2484
2485
2486 Automatic parentheses
2487 ---------------------
2488
2489 Callable objects (i.e. functions, methods, etc) can be invoked like this
2490 (notice the commas between the arguments)::
2491
2492 >>> callable_ob arg1, arg2, arg3
2493
2494 and the input will be translated to this::
2495
2496 -> callable_ob(arg1, arg2, arg3)
2497
2498 You can force automatic parentheses by using '/' as the first character
2499 of a line. For example::
2500
2501 >>> /globals # becomes 'globals()'
2502
2503 Note that the '/' MUST be the first character on the line! This won't work::
2504
2505 >>> print /globals # syntax error
2506
2507 In most cases the automatic algorithm should work, so you should rarely
2508 need to explicitly invoke /. One notable exception is if you are trying
2509 to call a function with a list of tuples as arguments (the parenthesis
2510 will confuse IPython)::
2511
2512 In [1]: zip (1,2,3),(4,5,6) # won't work
2513
2514 but this will work::
2515
2516 In [2]: /zip (1,2,3),(4,5,6)
2517 ---> zip ((1,2,3),(4,5,6))
2518 Out[2]= [(1, 4), (2, 5), (3, 6)]
2519
2520 IPython tells you that it has altered your command line by displaying
2521 the new command line preceded by ->. e.g.::
2522
2523 In [18]: callable list
2524 ----> callable (list)
2525
2526
2527 Automatic quoting
2528 -----------------
2529
2530 You can force automatic quoting of a function's arguments by using ','
2531 or ';' as the first character of a line. For example::
2532
2533 >>> ,my_function /home/me # becomes my_function("/home/me")
2534
2535 If you use ';' instead, the whole argument is quoted as a single string
2536 (while ',' splits on whitespace)::
2537
2538 >>> ,my_function a b c # becomes my_function("a","b","c")
2539
2540 >>> ;my_function a b c # becomes my_function("a b c")
2541
2542 Note that the ',' or ';' MUST be the first character on the line! This
2543 won't work::
2544
2545 >>> x = ,my_function /home/me # syntax error
2546
2547 IPython as your default Python environment
2548 ==========================================
2549
2550 Python honors the environment variable PYTHONSTARTUP and will execute at
2551 startup the file referenced by this variable. If you put at the end of
2552 this file the following two lines of code::
2553
2554 import IPython
2555 IPython.Shell.IPShell().mainloop(sys_exit=1)
2556
2557 then IPython will be your working environment anytime you start Python.
2558 The sys_exit=1 is needed to have IPython issue a call to sys.exit() when
2559 it finishes, otherwise you'll be back at the normal Python '>>>'
2560 prompt.
2561
2562 This is probably useful to developers who manage multiple Python
2563 versions and don't want to have correspondingly multiple IPython
2564 versions. Note that in this mode, there is no way to pass IPython any
2565 command-line options, as those are trapped first by Python itself.
2566
2567 .. _Embedding:
2568
2569 Embedding IPython
2570 =================
2571
2572 It is possible to start an IPython instance inside your own Python
2573 programs. This allows you to evaluate dynamically the state of your
2574 code, operate with your variables, analyze them, etc. Note however that
2575 any changes you make to values while in the shell do not propagate back
2576 to the running code, so it is safe to modify your values because you
2577 won't break your code in bizarre ways by doing so.
2578
2579 This feature allows you to easily have a fully functional python
2580 environment for doing object introspection anywhere in your code with a
2581 simple function call. In some cases a simple print statement is enough,
2582 but if you need to do more detailed analysis of a code fragment this
2583 feature can be very valuable.
2584
2585 It can also be useful in scientific computing situations where it is
2586 common to need to do some automatic, computationally intensive part and
2587 then stop to look at data, plots, etc.
2588 Opening an IPython instance will give you full access to your data and
2589 functions, and you can resume program execution once you are done with
2590 the interactive part (perhaps to stop again later, as many times as
2591 needed).
2592
2593 The following code snippet is the bare minimum you need to include in
2594 your Python programs for this to work (detailed examples follow later)::
2595
2596 from IPython.Shell import IPShellEmbed
2597
2598 ipshell = IPShellEmbed()
2599
2600 ipshell() # this call anywhere in your program will start IPython
2601
2602 You can run embedded instances even in code which is itself being run at
2603 the IPython interactive prompt with '%run <filename>'. Since it's easy
2604 to get lost as to where you are (in your top-level IPython or in your
2605 embedded one), it's a good idea in such cases to set the in/out prompts
2606 to something different for the embedded instances. The code examples
2607 below illustrate this.
2608
2609 You can also have multiple IPython instances in your program and open
2610 them separately, for example with different options for data
2611 presentation. If you close and open the same instance multiple times,
2612 its prompt counters simply continue from each execution to the next.
2613
2614 Please look at the docstrings in the Shell.py module for more details on
2615 the use of this system.
2616
2617 The following sample file illustrating how to use the embedding
2618 functionality is provided in the examples directory as example-embed.py.
2619 It should be fairly self-explanatory::
2620
2621
2622 #!/usr/bin/env python
2623
2624 """An example of how to embed an IPython shell into a running program.
2625
2626 Please see the documentation in the IPython.Shell module for more details.
2627
2628 The accompanying file example-embed-short.py has quick code fragments for
2629 embedding which you can cut and paste in your code once you understand how
2630 things work.
2631
2632 The code in this file is deliberately extra-verbose, meant for learning."""
2633
2634 # The basics to get you going:
2635
2636 # IPython sets the __IPYTHON__ variable so you can know if you have nested
2637 # copies running.
2638
2639 # Try running this code both at the command line and from inside IPython (with
2640 # %run example-embed.py)
2641 try:
2642 __IPYTHON__
2643 except NameError:
2644 nested = 0
2645 args = ['']
2646 else:
2647 print "Running nested copies of IPython."
2648 print "The prompts for the nested copy have been modified"
2649 nested = 1
2650 # what the embedded instance will see as sys.argv:
2651 args = ['-pi1','In <\\#>: ','-pi2',' .\\D.: ',
2652 '-po','Out<\\#>: ','-nosep']
2653
2654 # First import the embeddable shell class
2655 from IPython.Shell import IPShellEmbed
2656
2657 # Now create an instance of the embeddable shell. The first argument is a
2658 # string with options exactly as you would type them if you were starting
2659 # IPython at the system command line. Any parameters you want to define for
2660 # configuration can thus be specified here.
2661 ipshell = IPShellEmbed(args,
2662 banner = 'Dropping into IPython',
2663 exit_msg = 'Leaving Interpreter, back to program.')
2664
2665 # Make a second instance, you can have as many as you want.
2666 if nested:
2667 args[1] = 'In2<\\#>'
2668 else:
2669 args = ['-pi1','In2<\\#>: ','-pi2',' .\\D.: ',
2670 '-po','Out<\\#>: ','-nosep']
2671 ipshell2 = IPShellEmbed(args,banner = 'Second IPython instance.')
2672
2673 print '\nHello. This is printed from the main controller program.\n'
2674
2675 # You can then call ipshell() anywhere you need it (with an optional
2676 # message):
2677 ipshell('***Called from top level. '
2678 'Hit Ctrl-D to exit interpreter and continue program.\n'
2679 'Note that if you use %kill_embedded, you can fully deactivate\n'
2680 'This embedded instance so it will never turn on again')
2681
2682 print '\nBack in caller program, moving along...\n'
2683
2684 #---------------------------------------------------------------------------
2685 # More details:
2686
2687 # IPShellEmbed instances don't print the standard system banner and
2688 # messages. The IPython banner (which actually may contain initialization
2689 # messages) is available as <instance>.IP.BANNER in case you want it.
2690
2691 # IPShellEmbed instances print the following information everytime they
2692 # start:
2693
2694 # - A global startup banner.
2695
2696 # - A call-specific header string, which you can use to indicate where in the
2697 # execution flow the shell is starting.
2698
2699 # They also print an exit message every time they exit.
2700
2701 # Both the startup banner and the exit message default to None, and can be set
2702 # either at the instance constructor or at any other time with the
2703 # set_banner() and set_exit_msg() methods.
2704
2705 # The shell instance can be also put in 'dummy' mode globally or on a per-call
2706 # basis. This gives you fine control for debugging without having to change
2707 # code all over the place.
2708
2709 # The code below illustrates all this.
2710
2711
2712 # This is how the global banner and exit_msg can be reset at any point
2713 ipshell.set_banner('Entering interpreter - New Banner')
2714 ipshell.set_exit_msg('Leaving interpreter - New exit_msg')
2715
2716 def foo(m):
2717 s = 'spam'
2718 ipshell('***In foo(). Try @whos, or print s or m:')
2719 print 'foo says m = ',m
2720
2721 def bar(n):
2722 s = 'eggs'
2723 ipshell('***In bar(). Try @whos, or print s or n:')
2724 print 'bar says n = ',n
2725
2726 # Some calls to the above functions which will trigger IPython:
2727 print 'Main program calling foo("eggs")\n'
2728 foo('eggs')
2729
2730 # The shell can be put in 'dummy' mode where calls to it silently return. This
2731 # allows you, for example, to globally turn off debugging for a program with a
2732 # single call.
2733 ipshell.set_dummy_mode(1)
2734 print '\nTrying to call IPython which is now "dummy":'
2735 ipshell()
2736 print 'Nothing happened...'
2737 # The global 'dummy' mode can still be overridden for a single call
2738 print '\nOverriding dummy mode manually:'
2739 ipshell(dummy=0)
2740
2741 # Reactivate the IPython shell
2742 ipshell.set_dummy_mode(0)
2743
2744 print 'You can even have multiple embedded instances:'
2745 ipshell2()
2746
2747 print '\nMain program calling bar("spam")\n'
2748 bar('spam')
2749
2750 print 'Main program finished. Bye!'
2751
2752 #********************** End of file <example-embed.py> ***********************
2753
2754 Once you understand how the system functions, you can use the following
2755 code fragments in your programs which are ready for cut and paste::
2756
2757
2758 """Quick code snippets for embedding IPython into other programs.
2759
2760 See example-embed.py for full details, this file has the bare minimum code for
2761 cut and paste use once you understand how to use the system."""
2762
2763 #---------------------------------------------------------------------------
2764 # This code loads IPython but modifies a few things if it detects it's running
2765 # embedded in another IPython session (helps avoid confusion)
2766
2767 try:
2768 __IPYTHON__
2769 except NameError:
2770 argv = ['']
2771 banner = exit_msg = ''
2772 else:
2773 # Command-line options for IPython (a list like sys.argv)
2774 argv = ['-pi1','In <\\#>:','-pi2',' .\\D.:','-po','Out<\\#>:']
2775 banner = '*** Nested interpreter ***'
2776 exit_msg = '*** Back in main IPython ***'
2777
2778 # First import the embeddable shell class
2779 from IPython.Shell import IPShellEmbed
2780 # Now create the IPython shell instance. Put ipshell() anywhere in your code
2781 # where you want it to open.
2782 ipshell = IPShellEmbed(argv,banner=banner,exit_msg=exit_msg)
2783
2784 #---------------------------------------------------------------------------
2785 # This code will load an embeddable IPython shell always with no changes for
2786 # nested embededings.
2787
2788 from IPython.Shell import IPShellEmbed
2789 ipshell = IPShellEmbed()
2790 # Now ipshell() will open IPython anywhere in the code.
2791
2792 #---------------------------------------------------------------------------
2793 # This code loads an embeddable shell only if NOT running inside
2794 # IPython. Inside IPython, the embeddable shell variable ipshell is just a
2795 # dummy function.
2796
2797 try:
2798 __IPYTHON__
2799 except NameError:
2800 from IPython.Shell import IPShellEmbed
2801 ipshell = IPShellEmbed()
2802 # Now ipshell() will open IPython anywhere in the code
2803 else:
2804 # Define a dummy ipshell() so the same code doesn't crash inside an
2805 # interactive IPython
2806 def ipshell(): pass
2807
2808 #******************* End of file <example-embed-short.py> ********************
2809
2810 Using the Python debugger (pdb)
2811 ===============================
2812
2813 Running entire programs via pdb
2814 -------------------------------
2815
2816 pdb, the Python debugger, is a powerful interactive debugger which
2817 allows you to step through code, set breakpoints, watch variables,
2818 etc. IPython makes it very easy to start any script under the control
2819 of pdb, regardless of whether you have wrapped it into a 'main()'
2820 function or not. For this, simply type '%run -d myscript' at an
2821 IPython prompt. See the %run command's documentation (via '%run?' or
2822 in Sec. magic_ for more details, including how to control where pdb
2823 will stop execution first.
2824
2825 For more information on the use of the pdb debugger, read the included
2826 pdb.doc file (part of the standard Python distribution). On a stock
2827 Linux system it is located at /usr/lib/python2.3/pdb.doc, but the
2828 easiest way to read it is by using the help() function of the pdb module
2829 as follows (in an IPython prompt):
2830
2831 In [1]: import pdb
2832 In [2]: pdb.help()
2833
2834 This will load the pdb.doc document in a file viewer for you automatically.
2835
2836
2837 Automatic invocation of pdb on exceptions
2838 -----------------------------------------
2839
2840 IPython, if started with the -pdb option (or if the option is set in
2841 your rc file) can call the Python pdb debugger every time your code
2842 triggers an uncaught exception. This feature
2843 can also be toggled at any time with the %pdb magic command. This can be
2844 extremely useful in order to find the origin of subtle bugs, because pdb
2845 opens up at the point in your code which triggered the exception, and
2846 while your program is at this point 'dead', all the data is still
2847 available and you can walk up and down the stack frame and understand
2848 the origin of the problem.
2849
2850 Furthermore, you can use these debugging facilities both with the
2851 embedded IPython mode and without IPython at all. For an embedded shell
2852 (see sec. Embedding_), simply call the constructor with
2853 '-pdb' in the argument string and automatically pdb will be called if an
2854 uncaught exception is triggered by your code.
2855
2856 For stand-alone use of the feature in your programs which do not use
2857 IPython at all, put the following lines toward the top of your 'main'
2858 routine::
2859
2860 import sys,IPython.ultraTB
2861 sys.excepthook = IPython.ultraTB.FormattedTB(mode='Verbose',
2862 color_scheme='Linux', call_pdb=1)
2863
2864 The mode keyword can be either 'Verbose' or 'Plain', giving either very
2865 detailed or normal tracebacks respectively. The color_scheme keyword can
2866 be one of 'NoColor', 'Linux' (default) or 'LightBG'. These are the same
2867 options which can be set in IPython with -colors and -xmode.
2868
2869 This will give any of your programs detailed, colored tracebacks with
2870 automatic invocation of pdb.
2871
2872
2873 Extensions for syntax processing
2874 ================================
2875
2876 This isn't for the faint of heart, because the potential for breaking
2877 things is quite high. But it can be a very powerful and useful feature.
2878 In a nutshell, you can redefine the way IPython processes the user input
2879 line to accept new, special extensions to the syntax without needing to
2880 change any of IPython's own code.
2881
2882 In the IPython/Extensions directory you will find some examples
2883 supplied, which we will briefly describe now. These can be used 'as is'
2884 (and both provide very useful functionality), or you can use them as a
2885 starting point for writing your own extensions.
2886
2887
2888 Pasting of code starting with '>>> ' or '... '
2889 ----------------------------------------------
2890
2891 In the python tutorial it is common to find code examples which have
2892 been taken from real python sessions. The problem with those is that all
2893 the lines begin with either '>>> ' or '... ', which makes it impossible
2894 to paste them all at once. One must instead do a line by line manual
2895 copying, carefully removing the leading extraneous characters.
2896
2897 This extension identifies those starting characters and removes them
2898 from the input automatically, so that one can paste multi-line examples
2899 directly into IPython, saving a lot of time. Please look at the file
2900 InterpreterPasteInput.py in the IPython/Extensions directory for details
2901 on how this is done.
2902
2903 IPython comes with a special profile enabling this feature, called
2904 tutorial. Simply start IPython via 'ipython -p tutorial' and the feature
2905 will be available. In a normal IPython session you can activate the
2906 feature by importing the corresponding module with:
2907 In [1]: import IPython.Extensions.InterpreterPasteInput
2908
2909 The following is a 'screenshot' of how things work when this extension
2910 is on, copying an example from the standard tutorial::
2911
2912 IPython profile: tutorial
2913
2914 *** Pasting of code with ">>>" or "..." has been enabled.
2915
2916 In [1]: >>> def fib2(n): # return Fibonacci series up to n
2917 ...: ... """Return a list containing the Fibonacci series up to
2918 n."""
2919 ...: ... result = []
2920 ...: ... a, b = 0, 1
2921 ...: ... while b < n:
2922 ...: ... result.append(b) # see below
2923 ...: ... a, b = b, a+b
2924 ...: ... return result
2925 ...:
2926
2927 In [2]: fib2(10)
2928 Out[2]: [1, 1, 2, 3, 5, 8]
2929
2930 Note that as currently written, this extension does not recognize
2931 IPython's prompts for pasting. Those are more complicated, since the
2932 user can change them very easily, they involve numbers and can vary in
2933 length. One could however extract all the relevant information from the
2934 IPython instance and build an appropriate regular expression. This is
2935 left as an exercise for the reader.
2936
2937
2938 Input of physical quantities with units
2939 ---------------------------------------
2940
2941 The module PhysicalQInput allows a simplified form of input for physical
2942 quantities with units. This file is meant to be used in conjunction with
2943 the PhysicalQInteractive module (in the same directory) and
2944 Physics.PhysicalQuantities from Konrad Hinsen's ScientificPython
2945 (http://dirac.cnrs-orleans.fr/ScientificPython/).
2946
2947 The Physics.PhysicalQuantities module defines PhysicalQuantity objects,
2948 but these must be declared as instances of a class. For example, to
2949 define v as a velocity of 3 m/s, normally you would write::
2950
2951 In [1]: v = PhysicalQuantity(3,'m/s')
2952
2953 Using the PhysicalQ_Input extension this can be input instead as:
2954 In [1]: v = 3 m/s
2955 which is much more convenient for interactive use (even though it is
2956 blatantly invalid Python syntax).
2957
2958 The physics profile supplied with IPython (enabled via 'ipython -p
2959 physics') uses these extensions, which you can also activate with:
2960
2961 from math import * # math MUST be imported BEFORE PhysicalQInteractive
2962 from IPython.Extensions.PhysicalQInteractive import *
2963 import IPython.Extensions.PhysicalQInput
2964
2965
2966 Threading support
2967 =================
2968
2969 WARNING: The threading support is still somewhat experimental, and it
2970 has only seen reasonable testing under Linux. Threaded code is
2971 particularly tricky to debug, and it tends to show extremely
2972 platform-dependent behavior. Since I only have access to Linux machines,
2973 I will have to rely on user's experiences and assistance for this area
2974 of IPython to improve under other platforms.
2975
2976 IPython, via the -gthread , -qthread, -q4thread and -wthread options
2977 (described in Sec. `Threading options`_), can run in
2978 multithreaded mode to support pyGTK, Qt3, Qt4 and WXPython applications
2979 respectively. These GUI toolkits need to control the python main loop of
2980 execution, so under a normal Python interpreter, starting a pyGTK, Qt3,
2981 Qt4 or WXPython application will immediately freeze the shell.
2982
2983 IPython, with one of these options (you can only use one at a time),
2984 separates the graphical loop and IPython's code execution run into
2985 different threads. This allows you to test interactively (with %run, for
2986 example) your GUI code without blocking.
2987
2988 A nice mini-tutorial on using IPython along with the Qt Designer
2989 application is available at the SciPy wiki:
2990 http://www.scipy.org/Cookbook/Matplotlib/Qt_with_IPython_and_Designer.
2991
2992
2993 Tk issues
2994 ---------
2995
2996 As indicated in Sec. `Threading options`_, a special -tk option is
2997 provided to try and allow Tk graphical applications to coexist
2998 interactively with WX, Qt or GTK ones. Whether this works at all,
2999 however, is very platform and configuration dependent. Please
3000 experiment with simple test cases before committing to using this
3001 combination of Tk and GTK/Qt/WX threading in a production environment.
3002
3003
3004 I/O pitfalls
3005 ------------
3006
3007 Be mindful that the Python interpreter switches between threads every
3008 $N$ bytecodes, where the default value as of Python 2.3 is $N=100.$ This
3009 value can be read by using the sys.getcheckinterval() function, and it
3010 can be reset via sys.setcheckinterval(N). This switching of threads can
3011 cause subtly confusing effects if one of your threads is doing file I/O.
3012 In text mode, most systems only flush file buffers when they encounter a
3013 '\n'. An instruction as simple as::
3014
3015 print >> filehandle, ''hello world''
3016
3017 actually consists of several bytecodes, so it is possible that the
3018 newline does not reach your file before the next thread switch.
3019 Similarly, if you are writing to a file in binary mode, the file won't
3020 be flushed until the buffer fills, and your other thread may see
3021 apparently truncated files.
3022
3023 For this reason, if you are using IPython's thread support and have (for
3024 example) a GUI application which will read data generated by files
3025 written to from the IPython thread, the safest approach is to open all
3026 of your files in unbuffered mode (the third argument to the file/open
3027 function is the buffering value)::
3028
3029 filehandle = open(filename,mode,0)
3030
3031 This is obviously a brute force way of avoiding race conditions with the
3032 file buffering. If you want to do it cleanly, and you have a resource
3033 which is being shared by the interactive IPython loop and your GUI
3034 thread, you should really handle it with thread locking and
3035 syncrhonization properties. The Python documentation discusses these.
3036
3037 .. _Interactive demos:
3038
3039 Interactive demos with IPython
3040 ==============================
3041
3042 IPython ships with a basic system for running scripts interactively in
3043 sections, useful when presenting code to audiences. A few tags embedded
3044 in comments (so that the script remains valid Python code) divide a file
3045 into separate blocks, and the demo can be run one block at a time, with
3046 IPython printing (with syntax highlighting) the block before executing
3047 it, and returning to the interactive prompt after each block. The
3048 interactive namespace is updated after each block is run with the
3049 contents of the demo's namespace.
3050
3051 This allows you to show a piece of code, run it and then execute
3052 interactively commands based on the variables just created. Once you
3053 want to continue, you simply execute the next block of the demo. The
3054 following listing shows the markup necessary for dividing a script into
3055 sections for execution as a demo::
3056
3057
3058 """A simple interactive demo to illustrate the use of IPython's Demo class.
3059
3060 Any python script can be run as a demo, but that does little more than showing
3061 it on-screen, syntax-highlighted in one shot. If you add a little simple
3062 markup, you can stop at specified intervals and return to the ipython prompt,
3063 resuming execution later.
3064 """
3065
3066 print 'Hello, welcome to an interactive IPython demo.'
3067 print 'Executing this block should require confirmation before proceeding,'
3068 print 'unless auto_all has been set to true in the demo object'
3069
3070 # The mark below defines a block boundary, which is a point where IPython will
3071 # stop execution and return to the interactive prompt.
3072 # Note that in actual interactive execution,
3073 # <demo> --- stop ---
3074
3075 x = 1
3076 y = 2
3077
3078 # <demo> --- stop ---
3079
3080 # the mark below makes this block as silent
3081 # <demo> silent
3082
3083 print 'This is a silent block, which gets executed but not printed.'
3084
3085 # <demo> --- stop ---
3086 # <demo> auto
3087 print 'This is an automatic block.'
3088 print 'It is executed without asking for confirmation, but printed.'
3089 z = x+y
3090
3091 print 'z=',x
3092
3093 # <demo> --- stop ---
3094 # This is just another normal block.
3095 print 'z is now:', z
3096
3097 print 'bye!'
3098
3099 In order to run a file as a demo, you must first make a Demo object out
3100 of it. If the file is named myscript.py, the following code will make a
3101 demo::
3102
3103 from IPython.demo import Demo
3104
3105 mydemo = Demo('myscript.py')
3106
3107 This creates the mydemo object, whose blocks you run one at a time by
3108 simply calling the object with no arguments. If you have autocall active
3109 in IPython (the default), all you need to do is type::
3110
3111 mydemo
3112
3113 and IPython will call it, executing each block. Demo objects can be
3114 restarted, you can move forward or back skipping blocks, re-execute the
3115 last block, etc. Simply use the Tab key on a demo object to see its
3116 methods, and call '?' on them to see their docstrings for more usage
3117 details. In addition, the demo module itself contains a comprehensive
3118 docstring, which you can access via::
3119
3120 from IPython import demo
3121
3122 demo?
3123
3124 Limitations: It is important to note that these demos are limited to
3125 fairly simple uses. In particular, you can not put division marks in
3126 indented code (loops, if statements, function definitions, etc.)
3127 Supporting something like this would basically require tracking the
3128 internal execution state of the Python interpreter, so only top-level
3129 divisions are allowed. If you want to be able to open an IPython
3130 instance at an arbitrary point in a program, you can use IPython's
3131 embedding facilities, described in detail in Sec. 9
3132
3133
3134 .. _Matplotlib support:
3135
3136 Plotting with matplotlib
3137 ========================
3138
3139 The matplotlib library (http://matplotlib.sourceforge.net
3140 http://matplotlib.sourceforge.net) provides high quality 2D plotting for
3141 Python. Matplotlib can produce plots on screen using a variety of GUI
3142 toolkits, including Tk, GTK and WXPython. It also provides a number of
3143 commands useful for scientific computing, all with a syntax compatible
3144 with that of the popular Matlab program.
3145
3146 IPython accepts the special option -pylab (Sec. `Command line
3147 options`_). This configures it to support matplotlib, honoring the
3148 settings in the .matplotlibrc file. IPython will detect the user's
3149 choice of matplotlib GUI backend, and automatically select the proper
3150 threading model to prevent blocking. It also sets matplotlib in
3151 interactive mode and modifies %run slightly, so that any
3152 matplotlib-based script can be executed using %run and the final
3153 show() command does not block the interactive shell.
3154
3155 The -pylab option must be given first in order for IPython to
3156 configure its threading mode. However, you can still issue other
3157 options afterwards. This allows you to have a matplotlib-based
3158 environment customized with additional modules using the standard
3159 IPython profile mechanism (Sec. Profiles_): ''ipython -pylab -p
3160 myprofile'' will load the profile defined in ipythonrc-myprofile after
3161 configuring matplotlib.
3162
3163
@@ -0,0 +1,284 b''
1 .. _ipython_as_shell:
2
3 =========================
4 IPython as a system shell
5 =========================
6
7 Overview
8 ========
9
10 The 'sh' profile optimizes IPython for system shell usage. Apart from
11 certain job control functionality that is present in unix (ctrl+z does
12 "suspend"), the sh profile should provide you with most of the
13 functionality you use daily in system shell, and more. Invoke IPython
14 in 'sh' profile by doing 'ipython -p sh', or (in win32) by launching
15 the "pysh" shortcut in start menu.
16
17 If you want to use the features of sh profile as your defaults (which
18 might be a good idea if you use other profiles a lot of the time but
19 still want the convenience of sh profile), add ``import ipy_profile_sh``
20 to your ~/.ipython/ipy_user_conf.py.
21
22 The 'sh' profile is different from the default profile in that:
23
24 * Prompt shows the current directory
25 * Spacing between prompts and input is more compact (no padding with
26 empty lines). The startup banner is more compact as well.
27 * System commands are directly available (in alias table) without
28 requesting %rehashx - however, if you install new programs along
29 your PATH, you might want to run %rehashx to update the persistent
30 alias table
31 * Macros are stored in raw format by default. That is, instead of
32 '_ip.system("cat foo"), the macro will contain text 'cat foo')
33 * Autocall is in full mode
34 * Calling "up" does "cd .."
35
36 The 'sh' profile is different from the now-obsolete (and unavailable)
37 'pysh' profile in that:
38
39 * '$$var = command' and '$var = command' syntax is not supported
40 * anymore. Use 'var = !command' instead (incidentally, this is
41 * available in all IPython profiles). Note that !!command *will*
42 * work.
43
44 Aliases
45 =======
46
47 All of your $PATH has been loaded as IPython aliases, so you should be
48 able to type any normal system command and have it executed. See
49 %alias? and %unalias? for details on the alias facilities. See also
50 %rehashx? for details on the mechanism used to load $PATH.
51
52
53 Directory management
54 ====================
55
56 Since each command passed by ipython to the underlying system is executed
57 in a subshell which exits immediately, you can NOT use !cd to navigate
58 the filesystem.
59
60 IPython provides its own builtin '%cd' magic command to move in the
61 filesystem (the % is not required with automagic on). It also maintains
62 a list of visited directories (use %dhist to see it) and allows direct
63 switching to any of them. Type 'cd?' for more details.
64
65 %pushd, %popd and %dirs are provided for directory stack handling.
66
67
68 Enabled extensions
69 ==================
70
71 Some extensions, listed below, are enabled as default in this profile.
72
73 envpersist
74 ----------
75
76 %env can be used to "remember" environment variable manipulations. Examples::
77
78 %env - Show all environment variables
79 %env VISUAL=jed - set VISUAL to jed
80 %env PATH+=;/foo - append ;foo to PATH
81 %env PATH+=;/bar - also append ;bar to PATH
82 %env PATH-=/wbin; - prepend /wbin; to PATH
83 %env -d VISUAL - forget VISUAL persistent val
84 %env -p - print all persistent env modifications
85
86 ipy_which
87 ---------
88
89 %which magic command. Like 'which' in unix, but knows about ipython aliases.
90
91 Example::
92
93 [C:/ipython]|14> %which st
94 st -> start .
95 [C:/ipython]|15> %which d
96 d -> dir /w /og /on
97 [C:/ipython]|16> %which cp
98 cp -> cp
99 == c:\bin\cp.exe
100 c:\bin\cp.exe
101
102 ipy_app_completers
103 ------------------
104
105 Custom tab completers for some apps like svn, hg, bzr, apt-get. Try 'apt-get install <TAB>' in debian/ubuntu.
106
107 ipy_rehashdir
108 -------------
109
110 Allows you to add system command aliases for commands that are not along your path. Let's say that you just installed Putty and want to be able to invoke it without adding it to path, you can create the alias for it with rehashdir::
111
112 [~]|22> cd c:/opt/PuTTY/
113 [c:opt/PuTTY]|23> rehashdir .
114 <23> ['pageant', 'plink', 'pscp', 'psftp', 'putty', 'puttygen', 'unins000']
115
116 Now, you can execute any of those commams directly::
117
118 [c:opt/PuTTY]|24> cd
119 [~]|25> putty
120
121 (the putty window opens).
122
123 If you want to store the alias so that it will always be available, do '%store putty'. If you want to %store all these aliases persistently, just do it in a for loop::
124
125 [~]|27> for a in _23:
126 |..> %store $a
127 |..>
128 |..>
129 Alias stored: pageant (0, 'c:\\opt\\PuTTY\\pageant.exe')
130 Alias stored: plink (0, 'c:\\opt\\PuTTY\\plink.exe')
131 Alias stored: pscp (0, 'c:\\opt\\PuTTY\\pscp.exe')
132 Alias stored: psftp (0, 'c:\\opt\\PuTTY\\psftp.exe')
133 ...
134
135 mglob
136 -----
137
138 Provide the magic function %mglob, which makes it easier (than the 'find' command) to collect (possibly recursive) file lists. Examples::
139
140 [c:/ipython]|9> mglob *.py
141 [c:/ipython]|10> mglob *.py rec:*.txt
142 [c:/ipython]|19> workfiles = %mglob !.svn/ !.hg/ !*_Data/ !*.bak rec:.
143
144 Note that the first 2 calls will put the file list in result history (_, _9, _10), and the last one will assign it to 'workfiles'.
145
146
147 Prompt customization
148 ====================
149
150 The sh profile uses the following prompt configurations::
151
152 o.prompt_in1= r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Green|\#>'
153 o.prompt_in2= r'\C_Green|\C_LightGreen\D\C_Green>'
154
155 You can change the prompt configuration to your liking by editing
156 ipy_user_conf.py.
157
158 String lists
159 ============
160
161 String lists (IPython.genutils.SList) are handy way to process output
162 from system commands. They are produced by ``var = !cmd`` syntax.
163
164 First, we acquire the output of 'ls -l'::
165
166 [Q:doc/examples]|2> lines = !ls -l
167 ==
168 ['total 23',
169 '-rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py',
170 '-rw-rw-rw- 1 ville None 1927 Sep 30 2006 example-embed-short.py',
171 '-rwxrwxrwx 1 ville None 4606 Sep 1 17:15 example-embed.py',
172 '-rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py',
173 '-rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py',
174 '-rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py',
175 '-rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc']
176
177 Now, let's take a look at the contents of 'lines' (the first number is
178 the list element number)::
179
180 [Q:doc/examples]|3> lines
181 <3> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
182
183 0: total 23
184 1: -rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py
185 2: -rw-rw-rw- 1 ville None 1927 Sep 30 2006 example-embed-short.py
186 3: -rwxrwxrwx 1 ville None 4606 Sep 1 17:15 example-embed.py
187 4: -rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py
188 5: -rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py
189 6: -rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py
190 7: -rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc
191
192 Now, let's filter out the 'embed' lines::
193
194 [Q:doc/examples]|4> l2 = lines.grep('embed',prune=1)
195 [Q:doc/examples]|5> l2
196 <5> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
197
198 0: total 23
199 1: -rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py
200 2: -rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py
201 3: -rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py
202 4: -rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py
203 5: -rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc
204
205 Now, we want strings having just file names and permissions::
206
207 [Q:doc/examples]|6> l2.fields(8,0)
208 <6> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
209
210 0: total
211 1: example-demo.py -rw-rw-rw-
212 2: example-gnuplot.py -rwxrwxrwx
213 3: extension.py -rwxrwxrwx
214 4: seteditor.py -rwxrwxrwx
215 5: seteditor.pyc -rwxrwxrwx
216
217 Note how the line with 'total' does not raise IndexError.
218
219 If you want to split these (yielding lists), call fields() without
220 arguments::
221
222 [Q:doc/examples]|7> _.fields()
223 <7>
224 [['total'],
225 ['example-demo.py', '-rw-rw-rw-'],
226 ['example-gnuplot.py', '-rwxrwxrwx'],
227 ['extension.py', '-rwxrwxrwx'],
228 ['seteditor.py', '-rwxrwxrwx'],
229 ['seteditor.pyc', '-rwxrwxrwx']]
230
231 If you want to pass these separated with spaces to a command (typical
232 for lists if files), use the .s property::
233
234
235 [Q:doc/examples]|13> files = l2.fields(8).s
236 [Q:doc/examples]|14> files
237 <14> 'example-demo.py example-gnuplot.py extension.py seteditor.py seteditor.pyc'
238 [Q:doc/examples]|15> ls $files
239 example-demo.py example-gnuplot.py extension.py seteditor.py seteditor.pyc
240
241 SLists are inherited from normal python lists, so every list method is
242 available::
243
244 [Q:doc/examples]|21> lines.append('hey')
245
246
247 Real world example: remove all files outside version control
248 ============================================================
249
250 First, capture output of "hg status"::
251
252 [Q:/ipython]|28> out = !hg status
253 ==
254 ['M IPython\\Extensions\\ipy_kitcfg.py',
255 'M IPython\\Extensions\\ipy_rehashdir.py',
256 ...
257 '? build\\lib\\IPython\\Debugger.py',
258 '? build\\lib\\IPython\\Extensions\\InterpreterExec.py',
259 '? build\\lib\\IPython\\Extensions\\InterpreterPasteInput.py',
260 ...
261
262 (lines starting with ? are not under version control).
263
264 ::
265
266 [Q:/ipython]|35> junk = out.grep(r'^\?').fields(1)
267 [Q:/ipython]|36> junk
268 <36> SList (.p, .n, .l, .s, .grep(), .fields() availab
269 ...
270 10: build\bdist.win32\winexe\temp\_ctypes.py
271 11: build\bdist.win32\winexe\temp\_hashlib.py
272 12: build\bdist.win32\winexe\temp\_socket.py
273
274 Now we can just remove these files by doing 'rm $junk.s'.
275
276 The .s, .n, .p properties
277 =========================
278
279 The '.s' property returns one string where lines are separated by
280 single space (for convenient passing to system commands). The '.n'
281 property return one string where the lines are separated by '\n'
282 (i.e. the original output of the function). If the items in string
283 list are file names, '.p' can be used to get a list of "path" objects
284 for convenient file manipulation. No newline at end of file
@@ -0,0 +1,315 b''
1 .. _tutorial:
2
3 ======================
4 Quick IPython tutorial
5 ======================
6
7 .. contents::
8
9 IPython can be used as an improved replacement for the Python prompt,
10 and for that you don't really need to read any more of this manual. But
11 in this section we'll try to summarize a few tips on how to make the
12 most effective use of it for everyday Python development, highlighting
13 things you might miss in the rest of the manual (which is getting long).
14 We'll give references to parts in the manual which provide more detail
15 when appropriate.
16
17 The following article by Jeremy Jones provides an introductory tutorial
18 about IPython: http://www.onlamp.com/pub/a/python/2005/01/27/ipython.html
19
20 Highlights
21 ==========
22
23 Tab completion
24 --------------
25
26 TAB-completion, especially for attributes, is a convenient way to explore the
27 structure of any object you're dealing with. Simply type object_name.<TAB>
28 and a list of the object's attributes will be printed (see readline_ for
29 more). Tab completion also works on file and directory names, which combined
30 with IPython's alias system allows you to do from within IPython many of the
31 things you normally would need the system shell for.
32
33 Explore your objects
34 --------------------
35
36 Typing object_name? will print all sorts of details about any object,
37 including docstrings, function definition lines (for call arguments) and
38 constructor details for classes. The magic commands %pdoc, %pdef, %psource
39 and %pfile will respectively print the docstring, function definition line,
40 full source code and the complete file for any object (when they can be
41 found). If automagic is on (it is by default), you don't need to type the '%'
42 explicitly. See sec. `dynamic object information`_ for more.
43
44 The `%run` magic command
45 ------------------------
46
47 The %run magic command allows you to run any python script and load all of
48 its data directly into the interactive namespace. Since the file is re-read
49 from disk each time, changes you make to it are reflected immediately (in
50 contrast to the behavior of import). I rarely use import for code I am
51 testing, relying on %run instead. See magic_ section for more on this and
52 other magic commands, or type the name of any magic command and ? to get
53 details on it. See also sec. dreload_ for a recursive reload command. %run
54 also has special flags for timing the execution of your scripts (-t) and for
55 executing them under the control of either Python's pdb debugger (-d) or
56 profiler (-p). With all of these, %run can be used as the main tool for
57 efficient interactive development of code which you write in your editor of
58 choice.
59
60 Debug a Python script
61 ---------------------
62
63 Use the Python debugger, pdb. The %pdb command allows you to toggle on and
64 off the automatic invocation of an IPython-enhanced pdb debugger (with
65 coloring, tab completion and more) at any uncaught exception. The advantage
66 of this is that pdb starts inside the function where the exception occurred,
67 with all data still available. You can print variables, see code, execute
68 statements and even walk up and down the call stack to track down the true
69 source of the problem (which often is many layers in the stack above where
70 the exception gets triggered). Running programs with %run and pdb active can
71 be an efficient to develop and debug code, in many cases eliminating the need
72 for print statements or external debugging tools. I often simply put a 1/0 in
73 a place where I want to take a look so that pdb gets called, quickly view
74 whatever variables I need to or test various pieces of code and then remove
75 the 1/0. Note also that '%run -d' activates pdb and automatically sets
76 initial breakpoints for you to step through your code, watch variables, etc.
77 See Sec. `Output caching`_ for details.
78
79 Use the output cache
80 --------------------
81
82 All output results are automatically stored in a global dictionary named Out
83 and variables named _1, _2, etc. alias them. For example, the result of input
84 line 4 is available either as Out[4] or as _4. Additionally, three variables
85 named _, __ and ___ are always kept updated with the for the last three
86 results. This allows you to recall any previous result and further use it for
87 new calculations. See Sec. `Output caching`_ for more.
88
89 Suppress output
90 ---------------
91
92 Put a ';' at the end of a line to suppress the printing of output. This is
93 useful when doing calculations which generate long output you are not
94 interested in seeing. The _* variables and the Out[] list do get updated with
95 the contents of the output, even if it is not printed. You can thus still
96 access the generated results this way for further processing.
97
98 Input cache
99 -----------
100
101 A similar system exists for caching input. All input is stored in a global
102 list called In , so you can re-execute lines 22 through 28 plus line 34 by
103 typing 'exec In[22:29]+In[34]' (using Python slicing notation). If you need
104 to execute the same set of lines often, you can assign them to a macro with
105 the %macro function. See sec. `Input caching`_ for more.
106
107 Use your input history
108 ----------------------
109
110 The %hist command can show you all previous input, without line numbers if
111 desired (option -n) so you can directly copy and paste code either back in
112 IPython or in a text editor. You can also save all your history by turning on
113 logging via %logstart; these logs can later be either reloaded as IPython
114 sessions or used as code for your programs.
115
116 Define your own system aliases
117 ------------------------------
118
119 Even though IPython gives you access to your system shell via the ! prefix,
120 it is convenient to have aliases to the system commands you use most often.
121 This allows you to work seamlessly from inside IPython with the same commands
122 you are used to in your system shell. IPython comes with some pre-defined
123 aliases and a complete system for changing directories, both via a stack (see
124 %pushd, %popd and %dhist) and via direct %cd. The latter keeps a history of
125 visited directories and allows you to go to any previously visited one.
126
127 Call system shell commands
128 --------------------------
129
130 Use Python to manipulate the results of system commands. The '!!' special
131 syntax, and the %sc and %sx magic commands allow you to capture system output
132 into Python variables.
133
134 Use Python variables when calling the shell
135 -------------------------------------------
136
137 Expand python variables when calling the shell (either via '!' and '!!' or
138 via aliases) by prepending a $ in front of them. You can also expand complete
139 python expressions. See `System shell access`_ for more.
140
141 Use profiles
142 ------------
143
144 Use profiles to maintain different configurations (modules to load, function
145 definitions, option settings) for particular tasks. You can then have
146 customized versions of IPython for specific purposes. See sec. profiles_ for
147 more.
148
149
150 Embed IPython in your programs
151 ------------------------------
152
153 A few lines of code are enough to load a complete IPython inside your own
154 programs, giving you the ability to work with your data interactively after
155 automatic processing has been completed. See sec. embedding_ for more.
156
157 Use the Python profiler
158 -----------------------
159
160 When dealing with performance issues, the %run command with a -p option
161 allows you to run complete programs under the control of the Python profiler.
162 The %prun command does a similar job for single Python expressions (like
163 function calls).
164
165 Use IPython to present interactive demos
166 ----------------------------------------
167
168 Use the IPython.demo.Demo class to load any Python script as an interactive
169 demo. With a minimal amount of simple markup, you can control the execution
170 of the script, stopping as needed. See sec. `interactive demos`_ for more.
171
172 Run doctests
173 ------------
174
175 Run your doctests from within IPython for development and debugging. The
176 special %doctest_mode command toggles a mode where the prompt, output and
177 exceptions display matches as closely as possible that of the default Python
178 interpreter. In addition, this mode allows you to directly paste in code that
179 contains leading '>>>' prompts, even if they have extra leading whitespace
180 (as is common in doctest files). This combined with the '%history -tn' call
181 to see your translated history (with these extra prompts removed and no line
182 numbers) allows for an easy doctest workflow, where you can go from doctest
183 to interactive execution to pasting into valid Python code as needed.
184
185 Source code handling tips
186 =========================
187
188 IPython is a line-oriented program, without full control of the
189 terminal. Therefore, it doesn't support true multiline editing. However,
190 it has a number of useful tools to help you in dealing effectively with
191 more complex editing.
192
193 The %edit command gives a reasonable approximation of multiline editing,
194 by invoking your favorite editor on the spot. IPython will execute the
195 code you type in there as if it were typed interactively. Type %edit?
196 for the full details on the edit command.
197
198 If you have typed various commands during a session, which you'd like to
199 reuse, IPython provides you with a number of tools. Start by using %hist
200 to see your input history, so you can see the line numbers of all input.
201 Let us say that you'd like to reuse lines 10 through 20, plus lines 24
202 and 28. All the commands below can operate on these with the syntax::
203
204 %command 10-20 24 28
205
206 where the command given can be:
207
208 * %macro <macroname>: this stores the lines into a variable which,
209 when called at the prompt, re-executes the input. Macros can be
210 edited later using '%edit macroname', and they can be stored
211 persistently across sessions with '%store macroname' (the storage
212 system is per-profile). The combination of quick macros,
213 persistent storage and editing, allows you to easily refine
214 quick-and-dirty interactive input into permanent utilities, always
215 available both in IPython and as files for general reuse.
216 * %edit: this will open a text editor with those lines pre-loaded
217 for further modification. It will then execute the resulting
218 file's contents as if you had typed it at the prompt.
219 * %save <filename>: this saves the lines directly to a named file on
220 disk.
221
222 While %macro saves input lines into memory for interactive re-execution,
223 sometimes you'd like to save your input directly to a file. The %save
224 magic does this: its input sytnax is the same as %macro, but it saves
225 your input directly to a Python file. Note that the %logstart command
226 also saves input, but it logs all input to disk (though you can
227 temporarily suspend it and reactivate it with %logoff/%logon); %save
228 allows you to select which lines of input you need to save.
229
230
231 Lightweight 'version control'
232 =============================
233
234 When you call %edit with no arguments, IPython opens an empty editor
235 with a temporary file, and it returns the contents of your editing
236 session as a string variable. Thanks to IPython's output caching
237 mechanism, this is automatically stored::
238
239 In [1]: %edit
240
241 IPython will make a temporary file named: /tmp/ipython_edit_yR-HCN.py
242
243 Editing... done. Executing edited code...
244
245 hello - this is a temporary file
246
247 Out[1]: "print 'hello - this is a temporary file'\n"
248
249 Now, if you call '%edit -p', IPython tries to open an editor with the
250 same data as the last time you used %edit. So if you haven't used %edit
251 in the meantime, this same contents will reopen; however, it will be
252 done in a new file. This means that if you make changes and you later
253 want to find an old version, you can always retrieve it by using its
254 output number, via '%edit _NN', where NN is the number of the output
255 prompt.
256
257 Continuing with the example above, this should illustrate this idea::
258
259 In [2]: edit -p
260
261 IPython will make a temporary file named: /tmp/ipython_edit_nA09Qk.py
262
263 Editing... done. Executing edited code...
264
265 hello - now I made some changes
266
267 Out[2]: "print 'hello - now I made some changes'\n"
268
269 In [3]: edit _1
270
271 IPython will make a temporary file named: /tmp/ipython_edit_gy6-zD.py
272
273 Editing... done. Executing edited code...
274
275 hello - this is a temporary file
276
277 IPython version control at work :)
278
279 Out[3]: "print 'hello - this is a temporary file'\nprint 'IPython version control at work :)'\n"
280
281
282 This section was written after a contribution by Alexander Belchenko on
283 the IPython user list.
284
285
286 Effective logging
287 =================
288
289 A very useful suggestion sent in by Robert Kern follows:
290
291 I recently happened on a nifty way to keep tidy per-project log files. I
292 made a profile for my project (which is called "parkfield")::
293
294 include ipythonrc
295
296 # cancel earlier logfile invocation:
297
298 logfile ''
299
300 execute import time
301
302 execute __cmd = '/Users/kern/research/logfiles/parkfield-%s.log rotate'
303
304 execute __IP.magic_logstart(__cmd % time.strftime('%Y-%m-%d'))
305
306 I also added a shell alias for convenience::
307
308 alias parkfield="ipython -pylab -profile parkfield"
309
310 Now I have a nice little directory with everything I ever type in,
311 organized by project and date.
312
313 Contribute your own: If you have your own favorite tip on using IPython
314 efficiently for a certain task (especially things which can't be done in
315 the normal Python interpreter), don't hesitate to send it!
@@ -0,0 +1,189 b''
1 .. _overview:
2
3 ============
4 Introduction
5 ============
6
7 This is the official documentation for IPython 0.x series (i.e. what
8 we are used to refer to just as "IPython"). The original text of the
9 manual (most of which is still in place) has been authored by Fernando
10 Perez, but as recommended usage patterns and new features have
11 emerged, this manual has been updated to reflect that fact. Most of
12 the additions have been authored by Ville M. Vainio.
13
14 The manual has been generated from reStructuredText source markup with
15 Sphinx, which should make it much easier to keep it up-to-date in the
16 future. Some reST artifacts and bugs may still be apparent in the
17 documentation, but this should improve as the toolchain matures.
18
19 Overview
20 ========
21
22 One of Python's most useful features is its interactive interpreter.
23 This system allows very fast testing of ideas without the overhead of
24 creating test files as is typical in most programming languages.
25 However, the interpreter supplied with the standard Python distribution
26 is somewhat limited for extended interactive use.
27
28 IPython is a free software project (released under the BSD license)
29 which tries to:
30
31 1. Provide an interactive shell superior to Python's default. IPython
32 has many features for object introspection, system shell access,
33 and its own special command system for adding functionality when
34 working interactively. It tries to be a very efficient environment
35 both for Python code development and for exploration of problems
36 using Python objects (in situations like data analysis).
37 2. Serve as an embeddable, ready to use interpreter for your own
38 programs. IPython can be started with a single call from inside
39 another program, providing access to the current namespace. This
40 can be very useful both for debugging purposes and for situations
41 where a blend of batch-processing and interactive exploration are
42 needed.
43 3. Offer a flexible framework which can be used as the base
44 environment for other systems with Python as the underlying
45 language. Specifically scientific environments like Mathematica,
46 IDL and Matlab inspired its design, but similar ideas can be
47 useful in many fields.
48 4. Allow interactive testing of threaded graphical toolkits. IPython
49 has support for interactive, non-blocking control of GTK, Qt and
50 WX applications via special threading flags. The normal Python
51 shell can only do this for Tkinter applications.
52
53
54 Main features
55 -------------
56
57 * Dynamic object introspection. One can access docstrings, function
58 definition prototypes, source code, source files and other details
59 of any object accessible to the interpreter with a single
60 keystroke ('?', and using '??' provides additional detail).
61 * Searching through modules and namespaces with '*' wildcards, both
62 when using the '?' system and via the %psearch command.
63 * Completion in the local namespace, by typing TAB at the prompt.
64 This works for keywords, modules, methods, variables and files in the
65 current directory. This is supported via the readline library, and
66 full access to configuring readline's behavior is provided.
67 Custom completers can be implemented easily for different purposes
68 (system commands, magic arguments etc.)
69 * Numbered input/output prompts with command history (persistent
70 across sessions and tied to each profile), full searching in this
71 history and caching of all input and output.
72 * User-extensible 'magic' commands. A set of commands prefixed with
73 % is available for controlling IPython itself and provides
74 directory control, namespace information and many aliases to
75 common system shell commands.
76 * Alias facility for defining your own system aliases.
77 * Complete system shell access. Lines starting with ! are passed
78 directly to the system shell, and using !! or var = !cmd
79 captures shell output into python variables for further use.
80 * Background execution of Python commands in a separate thread.
81 IPython has an internal job manager called jobs, and a
82 conveninence backgrounding magic function called %bg.
83 * The ability to expand python variables when calling the system
84 shell. In a shell command, any python variable prefixed with $ is
85 expanded. A double $$ allows passing a literal $ to the shell (for
86 access to shell and environment variables like $PATH).
87 * Filesystem navigation, via a magic %cd command, along with a
88 persistent bookmark system (using %bookmark) for fast access to
89 frequently visited directories.
90 * A lightweight persistence framework via the %store command, which
91 allows you to save arbitrary Python variables. These get restored
92 automatically when your session restarts.
93 * Automatic indentation (optional) of code as you type (through the
94 readline library).
95 * Macro system for quickly re-executing multiple lines of previous
96 input with a single name. Macros can be stored persistently via
97 %store and edited via %edit.
98 * Session logging (you can then later use these logs as code in your
99 programs). Logs can optionally timestamp all input, and also store
100 session output (marked as comments, so the log remains valid
101 Python source code).
102 * Session restoring: logs can be replayed to restore a previous
103 session to the state where you left it.
104 * Verbose and colored exception traceback printouts. Easier to parse
105 visually, and in verbose mode they produce a lot of useful
106 debugging information (basically a terminal version of the cgitb
107 module).
108 * Auto-parentheses: callable objects can be executed without
109 parentheses: 'sin 3' is automatically converted to 'sin(3)'.
110 * Auto-quoting: using ',' or ';' as the first character forces
111 auto-quoting of the rest of the line: ',my_function a b' becomes
112 automatically 'my_function("a","b")', while ';my_function a b'
113 becomes 'my_function("a b")'.
114 * Extensible input syntax. You can define filters that pre-process
115 user input to simplify input in special situations. This allows
116 for example pasting multi-line code fragments which start with
117 '>>>' or '...' such as those from other python sessions or the
118 standard Python documentation.
119 * Flexible configuration system. It uses a configuration file which
120 allows permanent setting of all command-line options, module
121 loading, code and file execution. The system allows recursive file
122 inclusion, so you can have a base file with defaults and layers
123 which load other customizations for particular projects.
124 * Embeddable. You can call IPython as a python shell inside your own
125 python programs. This can be used both for debugging code or for
126 providing interactive abilities to your programs with knowledge
127 about the local namespaces (very useful in debugging and data
128 analysis situations).
129 * Easy debugger access. You can set IPython to call up an enhanced
130 version of the Python debugger (pdb) every time there is an
131 uncaught exception. This drops you inside the code which triggered
132 the exception with all the data live and it is possible to
133 navigate the stack to rapidly isolate the source of a bug. The
134 %run magic command -with the -d option- can run any script under
135 pdb's control, automatically setting initial breakpoints for you.
136 This version of pdb has IPython-specific improvements, including
137 tab-completion and traceback coloring support. For even easier
138 debugger access, try %debug after seeing an exception. winpdb is
139 also supported, see ipy_winpdb extension.
140 * Profiler support. You can run single statements (similar to
141 profile.run()) or complete programs under the profiler's control.
142 While this is possible with standard cProfile or profile modules,
143 IPython wraps this functionality with magic commands (see '%prun'
144 and '%run -p') convenient for rapid interactive work.
145 * Doctest support. The special %doctest_mode command toggles a mode
146 that allows you to paste existing doctests (with leading '>>>'
147 prompts and whitespace) and uses doctest-compatible prompts and
148 output, so you can use IPython sessions as doctest code.
149
150
151 Portability and Python requirements
152 -----------------------------------
153
154 Python requirements: IPython requires with Python version 2.3 or newer.
155 If you are still using Python 2.2 and can not upgrade, the last version
156 of IPython which worked with Python 2.2 was 0.6.15, so you will have to
157 use that.
158
159 IPython is developed under Linux, but it should work in any reasonable
160 Unix-type system (tested OK under Solaris and the BSD family, for which
161 a port exists thanks to Dryice Liu).
162
163 Mac OS X: it works, apparently without any problems (thanks to Jim Boyle
164 at Lawrence Livermore for the information). Thanks to Andrea Riciputi,
165 Fink support is available.
166
167 CygWin: it works mostly OK, though some users have reported problems
168 with prompt coloring. No satisfactory solution to this has been found so
169 far, you may want to disable colors permanently in the ipythonrc
170 configuration file if you experience problems. If you have proper color
171 support under cygwin, please post to the IPython mailing list so this
172 issue can be resolved for all users.
173
174 Windows: it works well under Windows Vista/XP/2k, and I suspect NT should
175 behave similarly. Section "Installation under windows" describes
176 installation details for Windows, including some additional tools needed
177 on this platform.
178
179 Windows 9x support is present, and has been reported to work fine (at
180 least on WinME).
181
182 Location
183 --------
184
185 IPython is generously hosted at http://ipython.scipy.org by the
186 Enthought, Inc and the SciPy project. This site offers downloads,
187 subversion access, mailing lists and a bug tracking system. I am very
188 grateful to Enthought (http://www.enthought.com) and all of the SciPy
189 team for their contribution. No newline at end of file
@@ -1,27 +1,81 b''
1 ===================
1 .. _changes:
2 Changes in IPython
2
3 ===================
3 ==========
4 What's new
5 ==========
4
6
5 .. contents::
7 .. contents::
6
8
7 Release 0.3
9 Release 0.9
8 ===========
10 ===========
9
11
10 New features
12 New features
11 ------------
13 ------------
12
14
15 * All of the parallel computing capabilities from `ipython1-dev` have been merged into
16 IPython proper. This resulted in the following new subpackages:
17 :mod:`IPython.kernel`, :mod:`IPython.kernel.core`, :mod:`IPython.config`,
18 :mod:`IPython.tools` and :mod:`IPython.testing`.
19 * As part of merging in the `ipython1-dev` stuff, the `setup.py` script and friends
20 have been completely refactored. Now we are checking for dependencies using
21 the approach that matplotlib uses.
22 * The documentation has been completely reorganized to accept the documentation
23 from `ipython1-dev`.
24 * We have switched to using Foolscap for all of our network protocols in
25 :mod:`IPython.kernel`. This gives us secure connections that are both encrypted
26 and authenticated.
27 * We have a brand new `COPYING.txt` files that describes the IPython license
28 and copyright. The biggest change is that we are putting "The IPython
29 Development Team" as the copyright holder. We give more details about exactly
30 what this means in this file. All developer should read this and use the new
31 banner in all IPython source code files.
32
33 Bug fixes
34 ---------
35
36 * A few subpackages has missing `__init__.py` files.
37 * The documentation is only created is Sphinx is found. Previously, the `setup.py`
38 script would fail if it was missing.
39
40 Backwards incompatible changes
41 ------------------------------
42
43 * IPython has a larger set of dependencies if you want all of its capabilities.
44 See the `setup.py` script for details.
45 * The constructors for :class:`IPython.kernel.client.MultiEngineClient` and
46 :class:`IPython.kernel.client.TaskClient` no longer take the (ip,port) tuple.
47 Instead they take the filename of a file that contains the FURL for that
48 client. If the FURL file is in your IPYTHONDIR, it will be found automatically
49 and the constructor can be left empty.
50 * The asynchronous clients in :mod:`IPython.kernel.asyncclient` are now created
51 using the factory functions :func:`get_multiengine_client` and
52 :func:`get_task_client`. These return a `Deferred` to the actual client.
53 * The command line options to `ipcontroller` and `ipengine` have changed to
54 reflect the new Foolscap network protocol and the FURL files. Please see the
55 help for these scripts for details.
56 * The configuration files for the kernel have changed because of the Foolscap stuff.
57 If you were using custom config files before, you should delete them and regenerate
58 new ones.
59
60 Changes merged in from IPython1
61 -------------------------------
62
63 New features
64 ............
65
13 * Much improved ``setup.py`` and ``setupegg.py`` scripts. Because Twisted
66 * Much improved ``setup.py`` and ``setupegg.py`` scripts. Because Twisted
14 and zope.interface are now easy installable, we can declare them as dependencies
67 and zope.interface are now easy installable, we can declare them as dependencies
15 in our setupegg.py script.
68 in our setupegg.py script.
16 * IPython is now compatible with Twisted 2.5.0 and 8.x.
69 * IPython is now compatible with Twisted 2.5.0 and 8.x.
17 * Added a new example of how to use :mod:`ipython1.kernel.asynclient`.
70 * Added a new example of how to use :mod:`ipython1.kernel.asynclient`.
18 * Initial draft of a process daemon in :mod:`ipython1.daemon`.
71 * Initial draft of a process daemon in :mod:`ipython1.daemon`. This has not
72 been merged into IPython and is still in `ipython1-dev`.
19 * The ``TaskController`` now has methods for getting the queue status.
73 * The ``TaskController`` now has methods for getting the queue status.
20 * The ``TaskResult`` objects not have information about how long the task
74 * The ``TaskResult`` objects not have information about how long the task
21 took to run.
75 took to run.
22 * We are attaching additional attributes to exceptions ``(_ipython_*)`` that
76 * We are attaching additional attributes to exceptions ``(_ipython_*)`` that
23 we use to carry additional info around.
77 we use to carry additional info around.
24 * New top-level module :mod:`asynclient` that has asynchronous versions (that
78 * New top-level module :mod:`asyncclient` that has asynchronous versions (that
25 return deferreds) of the client classes. This is designed to users who want
79 return deferreds) of the client classes. This is designed to users who want
26 to run their own Twisted reactor
80 to run their own Twisted reactor
27 * All the clients in :mod:`client` are now based on Twisted. This is done by
81 * All the clients in :mod:`client` are now based on Twisted. This is done by
@@ -41,7 +95,7 b' New features'
41 for users.
95 for users.
42
96
43 Bug fixes
97 Bug fixes
44 ---------
98 .........
45
99
46 * Created a proper ``MANIFEST.in`` file to create source distributions.
100 * Created a proper ``MANIFEST.in`` file to create source distributions.
47 * Fixed a bug in the ``MultiEngine`` interface. Previously, multi-engine
101 * Fixed a bug in the ``MultiEngine`` interface. Previously, multi-engine
@@ -56,7 +110,7 b' Bug fixes'
56 exception.
110 exception.
57
111
58 Backwards incompatible changes
112 Backwards incompatible changes
59 ------------------------------
113 ..............................
60
114
61 * All names have been renamed to conform to the lowercase_with_underscore
115 * All names have been renamed to conform to the lowercase_with_underscore
62 convention. This will require users to change references to all names like
116 convention. This will require users to change references to all names like
@@ -80,25 +134,28 b' Backwards incompatible changes'
80 * Changed the ``setupNS`` and ``resultNames`` in the ``Task`` class to ``push``
134 * Changed the ``setupNS`` and ``resultNames`` in the ``Task`` class to ``push``
81 and ``pull``.
135 and ``pull``.
82
136
83 Version 0.8.2
137 Release 0.8.4
84 =============
138 =============
85
139
86 Changes made since version 0.8.1 was released:
140 Someone needs to describe what went into 0.8.4.
141
142 Release 0.8.2
143 =============
87
144
88 * %pushd/%popd behave differently; now "pushd /foo" pushes CURRENT directory
145 * %pushd/%popd behave differently; now "pushd /foo" pushes CURRENT directory
89 and jumps to /foo. The current behaviour is closer to the documented
146 and jumps to /foo. The current behaviour is closer to the documented
90 behaviour, and should not trip anyone.
147 behaviour, and should not trip anyone.
91
148
92 Version 0.8.3
149 Release 0.8.3
93 =============
150 =============
94
151
95 * pydb is now disabled by default (due to %run -d problems). You can enable
152 * pydb is now disabled by default (due to %run -d problems). You can enable
96 it by passing -pydb command line argument to IPython. Note that setting
153 it by passing -pydb command line argument to IPython. Note that setting
97 it in config file won't work.
154 it in config file won't work.
98
155
99 Releases prior to 0.3
156 Older releases
100 =====================
157 ==============
101
158
102 Changes prior to version 0.3 of IPython are described in the older file ``ChangeLog``.
159 Changes in earlier releases of IPython are described in the older file ``ChangeLog``.
103 Please refer to this document for details.
160 Please refer to this document for details.
104
161
@@ -42,9 +42,9 b" copyright = '2008, The IPython Development Team'"
42 # other places throughout the built documents.
42 # other places throughout the built documents.
43 #
43 #
44 # The short X.Y version.
44 # The short X.Y version.
45 version = '0.8.4'
45 version = '0.9'
46 # The full version, including alpha/beta/rc tags.
46 # The full version, including alpha/beta/rc tags.
47 release = '0.8.4'
47 release = '0.9'
48
48
49 # There are two options for replacing |today|: either, you set today to some
49 # There are two options for replacing |today|: either, you set today to some
50 # non-false value, then it is used:
50 # non-false value, then it is used:
@@ -1,4 +1,5 b''
1 Developing IPython
1 ==================
2 Development
2 ==================
3 ==================
3
4
4 .. toctree::
5 .. toctree::
@@ -1,34 +1,12 b''
1 .. _faq:
1 .. _faq:
2
2
3 ================
3 ========================================
4 FAQ for IPython
4 Frequently asked questions
5 ================
5 ========================================
6
6
7 General questions
7 General questions
8 =================
8 =================
9
9
10 What is the difference between IPython and IPython?
11 ----------------------------------------------------
12
13 IPython is the next generation of IPython. It is being created with three main goals in
14 mind:
15
16 1. Clean up the existing codebase and write lots of tests.
17 2. Separate the core functionality of IPython from the terminal to enable IPython
18 to be used from within a variety of GUI applications.
19 3. Implement a system for interactive parallel computing.
20
21 Currently, IPython is not a full replacement for IPython and until that happens,
22 IPython will be developed as a separate project. IPython currently provides a stable
23 and powerful architecture for parallel computing that can be used with IPython or even
24 the default Python shell. For more information, see our `introduction to parallel
25 computing with IPython`__.
26
27 .. __: ./parallel_intro
28
29 What is the history of IPython?
30 --------------------------------
31
32 Questions about parallel computing with IPython
10 Questions about parallel computing with IPython
33 ================================================
11 ================================================
34
12
@@ -1,3 +1,56 b''
1 ======================
1 .. _history:
2 The History of IPython
2
3 ======================
3 =======
4 History
5 =======
6
7 Origins
8 =======
9
10 The current IPython system grew out of the following three projects:
11
12 * [ipython] by Fernando Pérez. I was working on adding
13 Mathematica-type prompts and a flexible configuration system
14 (something better than $PYTHONSTARTUP) to the standard Python
15 interactive interpreter.
16 * [IPP] by Janko Hauser. Very well organized, great usability. Had
17 an old help system. IPP was used as the 'container' code into
18 which I added the functionality from ipython and LazyPython.
19 * [LazyPython] by Nathan Gray. Simple but very powerful. The quick
20 syntax (auto parens, auto quotes) and verbose/colored tracebacks
21 were all taken from here.
22
23 When I found out about IPP and LazyPython I tried to join all three
24 into a unified system. I thought this could provide a very nice
25 working environment, both for regular programming and scientific
26 computing: shell-like features, IDL/Matlab numerics, Mathematica-type
27 prompt history and great object introspection and help facilities. I
28 think it worked reasonably well, though it was a lot more work than I
29 had initially planned.
30
31
32 Current status
33 ==============
34
35 The above listed features work, and quite well for the most part. But
36 until a major internal restructuring is done (see below), only bug
37 fixing will be done, no other features will be added (unless very minor
38 and well localized in the cleaner parts of the code).
39
40 IPython consists of some 18000 lines of pure python code, of which
41 roughly two thirds is reasonably clean. The rest is, messy code which
42 needs a massive restructuring before any further major work is done.
43 Even the messy code is fairly well documented though, and most of the
44 problems in the (non-existent) class design are well pointed to by a
45 PyChecker run. So the rewriting work isn't that bad, it will just be
46 time-consuming.
47
48
49 Future
50 ------
51
52 See the separate new_design document for details. Ultimately, I would
53 like to see IPython become part of the standard Python distribution as a
54 'big brother with batteries' to the standard Python interactive
55 interpreter. But that will never happen with the current state of the
56 code, so all contributions are welcome. No newline at end of file
@@ -1,12 +1,24 b''
1 =====================
1 IPython Documentation
2 IPython Documentation
2 =====================
3 =====================
3
4
5 Contents
6 ========
7
4 .. toctree::
8 .. toctree::
5 :maxdepth: 1
9 :maxdepth: 1
6
10
7 core/index.txt
11 overview.txt
8 dev/index.txt
12 install/index.txt
9 kernel/index.txt
13 interactive/index.txt
14 parallel/index.txt
15 config/index.txt
16 changes.txt
17 development/index.txt
18 faq.txt
19 history.txt
20 license_and_copyright.txt
21 credits.txt
10
22
11 Indices and tables
23 Indices and tables
12 ==================
24 ==================
@@ -2,12 +2,6 b''
2 Advanced installation options for IPython
2 Advanced installation options for IPython
3 =========================================
3 =========================================
4
4
5 .. _install:
6
7 ===================
8 Installing IPython
9 ===================
10
11 .. contents::
5 .. contents::
12
6
13 Introduction
7 Introduction
@@ -103,35 +97,6 b' The dependencies need to be installed before installing IPython. After installi'
103
97
104 .. note:: Here we are using setup.py rather than setupegg.py.
98 .. note:: Here we are using setup.py rather than setupegg.py.
105
99
106 .. _install_config:
107
108 Configuration
109 =============
110
111 IPython has a configuration system. When running IPython for the first time,
112 reasonable defaults are used for the configuration. The configuration of IPython
113 can be changed in two ways:
114
115 * Configuration files
116 * Commands line options (which override the configuration files)
117
118 IPython has a separate configuration file for each subpackage. Thus, the main
119 configuration files are (in your ``~/.ipython`` directory):
120
121 * ``ipython1.core.ini``
122 * ``ipython1.kernel.ini``
123 * ``ipython1.notebook.ini``
124
125 To create these files for the first time, do the following::
126
127 from ipython1.kernel.config import config_manager as kernel_config
128 kernel_config.write_default_config_file()
129
130 But, you should only need to do this if you need to modify the defaults. If needed
131 repeat this process with the ``notebook`` and ``core`` configuration as well. If you
132 are running into problems with IPython, you might try deleting these configuration
133 files.
134
135 .. _install_testing:
100 .. _install_testing:
136
101
137 Testing
102 Testing
@@ -1,8 +1,6 b''
1 IPython kernel documentation
1 ==================
2 ============================
2 Installation
3
3 ==================
4 User Documentation
5 ------------------
6
4
7 .. toctree::
5 .. toctree::
8 :maxdepth: 2
6 :maxdepth: 2
@@ -1,16 +1,11 b''
1 IPython Documentation
1 ==================================
2 =====================
2 Using IPython for interactive work
3 ==================================
3
4
4 .. toctree::
5 .. toctree::
5 :maxdepth: 1
6 :maxdepth: 1
6
7
7 core/index.txt
8 tutorial.txt
8 dev/index.txt
9 reference.txt
9 kernel/index.txt
10 shell.txt
10
11 extension_api.txt
11 Indices and tables
12 ==================
13
14 * :ref:`genindex`
15 * :ref:`modindex`
16 * :ref:`search` No newline at end of file
@@ -1,3 +1,61 b''
1 .. _license:
2
1 =============================
3 =============================
2 IPython Copyright and License
4 License and Copyright
3 =============================
5 =============================
6
7 This files needs to be updated to reflect what the new COPYING.txt files says about our license and copyright!
8
9 IPython is released under the terms of the BSD license, whose general
10 form can be found at: http://www.opensource.org/licenses/bsd-license.php. The full text of the
11 IPython license is reproduced below::
12
13 IPython is released under a BSD-type license.
14
15 Copyright (c) 2001, 2002, 2003, 2004 Fernando Perez
16 <fperez@colorado.edu>.
17
18 Copyright (c) 2001 Janko Hauser <jhauser@zscout.de> and
19 Nathaniel Gray <n8gray@caltech.edu>.
20
21 All rights reserved.
22
23 Redistribution and use in source and binary forms, with or without
24 modification, are permitted provided that the following conditions
25 are met:
26
27 a. Redistributions of source code must retain the above copyright
28 notice, this list of conditions and the following disclaimer.
29
30 b. Redistributions in binary form must reproduce the above copyright
31 notice, this list of conditions and the following disclaimer in the
32 documentation and/or other materials provided with the distribution.
33
34 c. Neither the name of the copyright holders nor the names of any
35 contributors to this software may be used to endorse or promote
36 products derived from this software without specific prior written
37 permission.
38
39 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
40 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
41 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
42 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
43 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
44 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
45 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
47 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
49 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
50 POSSIBILITY OF SUCH DAMAGE.
51
52 Individual authors are the holders of the copyright for their code and
53 are listed in each file.
54
55 Some files (DPyGetOpt.py, for example) may be licensed under different
56 conditions. Ultimately each file indicates clearly the conditions under
57 which its author/authors have decided to publish the code.
58
59 Versions of IPython up to and including 0.6.3 were released under the
60 GNU Lesser General Public License (LGPL), available at
61 http://www.gnu.org/copyleft/lesser.html. No newline at end of file
@@ -1,8 +1,9 b''
1 IPython kernel documentation
1 ====================================
2 ============================
2 Using IPython for Parallel computing
3 ====================================
3
4
4 User Documentation
5 User Documentation
5 ------------------
6 ==================
6
7
7 .. toctree::
8 .. toctree::
8 :maxdepth: 2
9 :maxdepth: 2
@@ -168,12 +168,6 b' Starting the controller and engines on different machines'
168 This section needs to be updated to reflect the new Foolscap capabilities based
168 This section needs to be updated to reflect the new Foolscap capabilities based
169 model.
169 model.
170
170
171 Specifying custom ports
172 -----------------------
173
174 This section needs to be updated to reflect the new Foolscap capabilities based
175 model.
176
177 Using ``ipcluster`` with ``ssh``
171 Using ``ipcluster`` with ``ssh``
178 --------------------------------
172 --------------------------------
179
173
@@ -216,28 +210,6 b' These log files can be extremely useful in debugging problems with'
216 IPython and can be found in the directory ``~/.ipython/log``. Sending
210 IPython and can be found in the directory ``~/.ipython/log``. Sending
217 the log files to us will often help us to debug any problems.
211 the log files to us will often help us to debug any problems.
218
212
219 Security and firewalls
220 ----------------------
221
222 The only process in IPython's architecture that listens on a network
223 port is the controller. Thus the controller is the main security concern.
224 Through the controller, an attacker can execute arbitrary code on the
225 engines. Thus, we highly recommend taking the following precautions:
226
227 * Don't run the controller on a machine that is exposed to the
228 internet.
229 * Don't run the controller on a machine that could have hostile
230 users on it.
231 * If you need to connect to a controller that is behind a firewall,
232 tunnel everything through ssh.
233
234 Currently, IPython does not have any built-in security. Thus, it
235 is up to you to be aware of the security risks associated with using IPython and to take steps to mitigate those risks.
236
237 However, we do have plans to add security measures to IPython itself.
238 This will probably take the form of using SSL for encryption and some
239 authentication scheme.
240
241 Next Steps
213 Next Steps
242 ==========
214 ==========
243
215
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
General Comments 0
You need to be logged in to leave comments. Login now