Skip to content

IPython / Jupyter Cheatsheet

IPython / Jupyter

  • Using IPython makes interactive work easy.
    • Better shell
    • Notebook interface
    • Embeddable kernel
    • Parallel python

IPython shell shortcuts

  • TAB expansion to complete python names and file paths
  • ~ and * directory / file expansion
  • many "magic" methods:
%lsmagic                # list of all magic methods
%quickref               # cheatsheet


?                       # overall help
help                    # python help system
?someobj or someobj?    # help
??someobj or someobj??  # detailed help

%pdoc %pdef %psource for docstring, function definition, source code only.


To run a program directly from the IPython console:

%run      # instead of execfile("") at the python prompt

%run has special flags for timing the execution of your scripts (-t) or for running them under the control of either Python's pdb debugger (-d) or profiler (-p):

%run -d

Other Commands

%edit %ed               # edit then execute
%load        # load local (example) file (or url) allowing modification
%macro                  # define macro with range of history lines, filenames or string objects

%whos                   # list identifiers you have defined interactively
%reset  -f -s           # remove objects -f for force -s for soft (leaves history).
  • %reset is not a kernel restart
  • Restart with Ctrl+. in "qtconsole"
  • import module ; reload(module) to reload a module from disk


%debug                  # jump into the Python debugger (pdb)
%pdb                    # start the debugger on any uncaught exception.

%cd                     # change directory
%pwd                    # print working directory
%env                    # OS environment variables

OS Commands

%alias                  # system command alias


_ __ ___                # etc... for previous outputs.
_i _ii _i4              # etc.. for previous input. _ih for list of previous inputs

GUI integration

Start with ipython --gui=qt or at the IPython prompt:

%gui wx

Arguments can be wx, qt, gtk and tk.

Matplotlib / pylab graphics in an iPython shell

Start with: ipython --matplotlib ( or --matplotlib=qt etc...)

At the IPython prompt:

%matplotlib             # set matplotlib to work interactively; does not import anythig
%matplotlib  inline
%matplotlib qt          # request a specific GUI backend
%pylab inline

%pylab makes the following imports:

import numpy
import matplotlib
from matplotlib import pylab, mlab, pyplot
np = numpy
plt = pyplot
from IPython.display import display
from IPython.core.pylabtools import figsize, getfigs
from pylab import *
from numpy import *

Qtconsole - an improved console

At the command prompt:

ipython.exe qtconsole --pylab=inline --ConsoleWidget.font_size=10

alternative: --matplotlib inline or within IPython:

%matplotlib  inline
%pylab inline

To embed plots, SVG or HTML in qtconsole, call display:

from IPython.core.display import display, display_html
from IPython.core.display import display_png, display_svg
display(plt.gcf()) # embeds the current figure in the qtconsole
display(*getfigs()) # embeds all active figures in the qtconsole
f = plt.figure()

ipython and ipython notebook for matlab users

IPython Notebook web-based interface

  • Start with: ipython notebook and switch to browser
  • Keyboard shortcuts:
    • Enter to edit a cell
    • Shift + Enter to evaluate
    • Ctrl + m or Esc for the "command mode"

In command mode:

 h list of keyboard shortcuts
 1-6 to convert to heading cell
 m to convert to markdown cell
 y to convert to code
 c copy / v paste
 d d delete cell
 s save notebook
 . to restart kernel