Show Menu

IPython Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Command Line Options

Open IPython terminal console
ipython qtconsole
Open IPython qtconsole
ipython notebook
Open IPython Notebook (browser interface)
ipython notebook --pylab inline
Open IPython Notebook with inline graphs


obj?, obj??
Get help, or more help for object
?obj, ??obj
Same as above
List names in 'foo' containing 'abc' in them.
Inform­ation about magic functions
Print quick guide to relevant IPython (console, notebook, qtconsole)


Code and path comple­tion. Second TAB allows cycling through options.
Ctrl + Enter [qtcon­sole]
Allows entering multiple statements (Cell mode)
Shift + Enter
Executes current cell
Ctrl + R [shell]
Reverser history search (All readline shortcuts are supported)

Notebook Magics

Run code below as javascript
Display markup below as html

Executing Code

%time or %%time
Run and output time statement or block (first line for block is setup)
%prun %%prun
Profile statement or block
Run a file and import resulting variables into namespace
%%script <ex­ecu­tab­le>
Run code below using <ex­ecu­tab­le>. --bg runs code in backgrounf and returns Popen object
%%ruby, %%perl, %%bash
Shortcuts for %%script <ru­by|­per­l|b­ash>
Run shell command and return output
%sh <cm­d>, !!<cmd
Run command and capture output as a list of lines
Run code in cell and capture stderr and stdout

File System Magics

cd, ls, mkdir
Aliases for python commands with the same functi­onality
Name current folder. Note that cd <bo­okm­ark> will work.
%dhist, _dh
Display directory history
%pushd, %popd
Save| Restore current directory
Display python source with syntax highli­ghting
Write the text below to a file

Console and Output Magics

%logstart, %logstop
Start|Stop saving commmands into a file (by default IPytho­
Run command output through pager
Toggle automatic pretty printing
Output command history
%recall <nu­m>
Re executed command #num from history
Print latest Traceback
Name statements for later use.
Get result of last statement. Use _i, _ii,_iii to get back in history. Use _<n­um> for going back to a result of a specific line in history.