IPython Documentation

Table Of Contents

Previous topic

Module: kernel.zmq.session

Next topic

Module: lib.backgroundjobs

This Page

Module: kernel.zmq.zmqshell

A ZMQ-based subclass of InteractiveShell.

This code is meant to ease the refactoring of the base InteractiveShell into something with a cleaner architecture for 2-process use, without actually breaking InteractiveShell itself. So we’re doing something a bit ugly, where we subclass and override what we want to fix. Once this is working well, we can go back to the base class and refactor the code for a cleaner inheritance implementation that doesn’t rely on so much monkeypatching.

But this lets us maintain a fully working IPython as we develop the new machinery. This should thus be thought of as scaffolding.

3 Classes

class IPython.kernel.zmq.zmqshell.ZMQDisplayPublisher(**kwargs)

Bases: IPython.core.displaypub.DisplayPublisher

A display publisher that publishes data using a ZeroMQ PUB socket.


Set the parent for outbound messages.

class IPython.kernel.zmq.zmqshell.KernelMagics(shell=None, **kwargs)

Bases: IPython.core.magic.Magics


Set the autosave interval in the notebook (in seconds).

The default value is 120, or two minutes. %autosave 0 will disable autosave.

This magic only has an effect when called from the notebook interface. It has no effect when called in a startup file.


Clear the terminal.


Print information for connecting other clients to this kernel

It will print the contents of this session’s connection file, as well as shortcuts for local clients.

In the simplest case, when called from the most recently launched kernel, secondary clients can be connected, simply with:

$> ipython <app> –existing

edit(parameter_s='', last_call=['', ''])

Bring up an editor and execute the resulting code.

%edit [options] [args]

%edit runs an external text editor. You will need to set the command for this editor via the TerminalInteractiveShell.editor option in your configuration file before it will work.

This command allows you to conveniently edit multi-line code right in your IPython session.

If called without arguments, %edit opens up an empty editor with a temporary file and will execute the contents of this file when you close it (don’t forget to save it!).


-n <number> Open the editor at a specified line number. By default, the IPython editor hook uses the unix syntax ‘editor +N filename’, but you can configure this by providing your own modified hook if your favorite editor supports line-number specifications with a different syntax.
-p Call the editor with the same data as the previous time it was used, regardless of how long ago (in your current session) it was.
-r Use ‘raw’ input. This option only applies to input taken from the user’s history. By default, the ‘processed’ history is used, so that magics are loaded in their transformed version to valid Python. If this option is given, the raw input as typed as the command line is used instead. When you exit the editor, it will be executed by IPython’s own processor.


If arguments are given, the following possibilites exist:

  • The arguments are numbers or pairs of colon-separated numbers (like 1 4:8 9). These are interpreted as lines of previous input to be loaded into the editor. The syntax is the same of the %macro command.

  • If the argument doesn’t start with a number, it is evaluated as a variable and its contents loaded into the editor. You can thus edit any string which contains python code (including the result of previous edits).

  • If the argument is the name of an object (other than a string), IPython will try to locate the file where it was defined and open the editor at the point where it is defined. You can use %edit function to load an editor exactly at the point where ‘function’ is defined, edit it and have the file be executed automatically.

    If the object is a macro (see %macro for details), this opens up your specified editor with a temporary file containing the macro’s data. Upon exit, the macro is reloaded with the contents of the file.

    Note: opening at an exact line is only supported under Unix, and some editors (like kedit and gedit up to Gnome 2.8) do not understand the ‘+NUMBER’ parameter necessary for this feature. Good editors like (X)Emacs, vi, jed, pico and joe all do.

  • If the argument is not found as a variable, IPython will look for a file with that name (adding .py if necessary) and load it into the editor. It will execute its contents with execfile() when you exit, loading any code in the file into your interactive namespace.

Unlike in the terminal, this is designed to use a GUI editor, and we do not know when it has closed. So the file you edit will not be automatically executed or printed.

Note that %edit is also available through the alias %ed.


Show a file through the pager.

Files ending in .py are syntax-highlighted.


Find the man page for the given command and display in pager.


Show a file through the pager.

Files ending in .py are syntax-highlighted.


Open a qtconsole connected to this kernel.

Useful for connecting a qtconsole to running notebooks, for better debugging.

class IPython.kernel.zmq.zmqshell.ZMQInteractiveShell(ipython_dir=None, profile_dir=None, user_module=None, user_ns=None, custom_exceptions=((), None), **kwargs)

Bases: IPython.core.interactiveshell.InteractiveShell

A subclass of InteractiveShell for ZMQ.


Engage the exit actions.


Configure the user’s environment.

set_next_input(text, replace=False)

Send the specified text to the frontend to be presented at the next input cell.


Set the parent header for associating output with its triggering input