User Tools

Site Tools


Configure ipython terminal prompts


The idea here is to change the default ipython terminal prompts such that a typical session looks like

In [1]:

instead of

In [1]: a='foo'
   ...: a
Out[1]: 'foo'

which is the default. The new version makes it easy to copy paste stuff across sessions.


Create a profile (~/.ipython/profile_default/ if it is not already created by running

ipython profile create

Add the following to ~/.ipython/profile_default/

# Customize terminal prompts.
# The goal here is to make it easy to copy paste stuff from/to ipython
# sessions. This is achieved by
# * adding an extra line to the input and output prompts
# * removing the continuation prompt
# To build the original prompt, I am using
from IPython.terminal.prompts import Prompts
from pygments.token import Token

class MyPrompt(Prompts):

    # keep the original input prompt but add an extra line
    def in_prompt_tokens(self):
        return [
            (Token.Prompt, self.vi_mode() ),
            (Token.Prompt, 'In ['),
            (Token.PromptNum, str(,
            (Token.Prompt, ']: '),
            (Token.Prompt, '\n'),

    # remove the continuation prompt.
    def continuation_prompt_tokens(self, width=None):
        return [
            (Token.Prompt, ''),

    # keep the original output prompt but add an extra line
    def out_prompt_tokens(self):
        return [
            (Token.OutPrompt, 'Out['),
            (Token.OutPromptNum, str(,
            (Token.OutPrompt, ']: '),
            (Token.OutPrompt, '\n'),

c.TerminalInteractiveShell.prompts_class = MyPrompt

tags | add a newline to ipython input prompt, change ipython terminal prompts, ipython paste without the dots

configure_ipython_terminal_prompts.txt · Last modified: 2020/12/03 20:17 by raju