Important

This documentation covers IPython versions 6.0 and higher. Beginning with version 6.0, IPython stopped supporting compatibility with Python versions lower than 3.3 including all versions of Python 2.7.

If you are looking for an IPython version compatible with Python 2.7, please use the IPython 5.x LTS release and refer to its documentation (LTS is the long term support release).

Module: terminal.interactiveshell

IPython terminal interface using prompt_toolkit

2 Classes

class IPython.terminal.interactiveshell.PtkHistoryAdapter(shell)

Bases: History

Prompt toolkit has it’s own way of handling history, Where it assumes it can Push/pull from history.

__init__(shell)
append_string(string)

Add string to the history.

load_history_strings()

This should be a generator that yields str instances.

It should yield the most recent items first, because they are the most important. (The history can already be used, even when it’s only partially loaded.)

store_string(string: str) None

Store the string in persistent storage.

class IPython.terminal.interactiveshell.TerminalInteractiveShell(**kwargs: Any)

Bases: InteractiveShell

__init__(*args, **kwargs) None

Create a configurable given a config config.

Parameters:
  • config (Config) – If this is empty, default values are used. If config is a Config instance, it will be used to configure the instance.

  • parent (Configurable instance, optional) – The parent Configurable instance of this object.

Notes

Subclasses of Configurable must call the __init__() method of Configurable before doing anything else and using super():

class MyConfigurable(Configurable):
    def __init__(self, config=None):
        super(MyConfigurable, self).__init__(config=config)
        # Then any other code you need to finish initialization.

This ensures that instances will be configured properly.

auto_match

Automatically add/delete closing bracket or quote when opening bracket or quote is entered/deleted. Brackets: (), [], {} Quotes: ‘’, “”

auto_rewrite_input(cmd)

Overridden from the parent class to use fancy rewriting prompt

autoformatter

Autoformatter to reformat Terminal code. Can be 'black', 'yapf' or None

autosuggestions_provider

Specifies from which source automatic suggestions are provided. Can be set to 'NavigableAutoSuggestFromHistory' (up and down swap suggestions), 'AutoSuggestFromHistory', or None to disable automatic suggestions. Default is 'NavigableAutoSuggestFromHistory’.

confirm_exit

Set to confirm when you try to exit IPython with an EOF (Control-D in Unix, Control-Z/Enter in Windows). By typing ‘exit’ or ‘quit’, you can force a direct exit without any confirmation.

property debugger_cls

Version of debugger where KeyboardInterrupt exits the debugger altogether.

debugger_history_file

File in which to store and read history

display_completions

Options for displaying tab completions, ‘column’, ‘multicolumn’, and ‘readlinelike’. These options are for prompt_toolkit, see prompt_toolkit documentation for more information.

editing_mode

Shortcut style to use at the prompt. ‘vi’ or ‘emacs’.

editor

Set the editor used by IPython (default to $EDITOR/vi/notepad).

emacs_bindings_in_vi_insert_mode

Add shortcuts from ‘emacs’ insert mode to ‘vi’ insert mode.

Allows to enable/disable the prompt toolkit history search

extra_open_editor_shortcuts

Enable vi (v) or Emacs (C-X C-E) shortcuts to open an external editor. This is in addition to the F2 binding, which is always enabled.

handle_return

Provide an alternative handler to be called when the user presses Return. This is an advanced option intended for debugging, which may be changed or removed in later releases.

highlight_matching_brackets

Highlight matching brackets.

highlighting_style

The name or class of a Pygments style to use for syntax highlighting. To see available styles, run pygmentize -L styles.

highlighting_style_overrides

Override highlighting format for specific tokens

modal_cursor

beam in vi insert mode, block in nav mode, underscore in replace mode.

Type:

Cursor shape changes depending on vi mode

mouse_support

Enable mouse support in the prompt (Note: prevents selecting text with the mouse)

prompt_includes_vi_mode

Display the current vi mode (when using vi editing mode).

prompt_line_number_format

4d}/{rel_line:+03d} | ‘ This will display the current line number, with leading space and a width of at least 4 character, as well as the relative line number 0 padded and always with a + or - sign. Note that when using Emacs mode the prompt of the first line may not update.

Type:

The format for line numbering, will be passed line (int, 1 based) the current line number and rel_line the relative line number. for example to display both you can use the following template string

Type:

c.TerminalInteractiveShell.prompt_line_number_format=’{line

prompts_class

Class used to generate Prompt token for prompt_toolkit

shortcuts

Add, disable or modifying shortcuts.

Each entry on the list should be a dictionary with command key identifying the target function executed by the shortcut and at least one of the following:

  • match_keys: list of keys used to match an existing shortcut,

  • match_filter: shortcut filter used to match an existing shortcut,

  • new_keys: list of keys to set,

  • new_filter: a new shortcut filter to set

The filters have to be composed of pre-defined verbs and joined by one of the following conjunctions: & (and), | (or), ~ (not). The pre-defined verbs are:

  • always

  • never

  • has_line_below

  • has_line_above

  • is_cursor_at_the_end_of_line

  • has_selection

  • has_suggestion

  • vi_mode

  • vi_insert_mode

  • emacs_insert_mode

  • emacs_like_insert_mode

  • has_completions

  • insert_mode

  • default_buffer_focused

  • search_buffer_focused

  • ebivim

  • supports_suspend

  • is_windows_os

  • auto_match

  • focused_insert

  • not_inside_unclosed_string

  • readline_like_completions

  • preceded_by_paired_double_quotes

  • preceded_by_paired_single_quotes

  • preceded_by_raw_str_prefix

  • preceded_by_two_double_quotes

  • preceded_by_two_single_quotes

  • followed_by_closing_paren_or_end

  • preceded_by_opening_round_paren

  • preceded_by_opening_bracket

  • preceded_by_opening_brace

  • preceded_by_double_quote

  • preceded_by_single_quote

  • followed_by_closing_round_paren

  • followed_by_closing_bracket

  • followed_by_closing_brace

  • followed_by_double_quote

  • followed_by_single_quote

  • navigable_suggestions

  • cursor_in_leading_ws

  • pass_through

To disable a shortcut set new_keys to an empty list. To add a shortcut add key create with value True.

When modifying/disabling shortcuts, match_keys/match_filter can be omitted if the provided specification uniquely identifies a shortcut to be modified/disabled. When modifying a shortcut new_filter or new_keys can be omitted which will result in reuse of the existing filter/keys.

Only shortcuts defined in IPython (and not default prompt-toolkit shortcuts) can be modified or disabled. The full list of shortcuts, command identifiers and filters is available under IPython shortcuts.

simple_prompt

Use raw_input for the REPL, without completion and prompt colors.

Useful when controlling IPython as a subprocess, and piping STDIN/OUT/ERR. Known usage are: IPython’s own testing machinery, and emacs’ inferior-python subprocess (assuming you have set python-shell-interpreter to “ipython”) available through the built-in M-x run-python and third party packages such as elpy.

This mode default to True if the IPY_TEST_SIMPLE_PROMPT environment variable is set, or the current terminal is not a tty. Thus the Default value reported in –help-all, or config will often be incorrectly reported.

space_for_menu

Number of line at the bottom of the screen to reserve for the tab completion menu, search history, …etc, the height of these menus will at most this value. Increase it is you prefer long and skinny menus, decrease for short and wide.

switch_doctest_mode(mode)

Switch prompts to classic for %doctest_mode

system(cmd)

Call the given cmd in a subprocess using os.system on Windows or subprocess.call using the system shell on other platforms.

Parameters:

cmd (str) – Command to execute.

term_title

Automatically set the terminal title

term_title_format

{cwd}.

Type:

Customize the terminal title format. This is a python format string. Available substitutions are

timeoutlen

The time in milliseconds that is waited for a mapped key sequence to complete.

true_color

Use 24bit colors instead of 256 colors in prompt highlighting. If your terminal supports true color, the following command should print TRUECOLOR in orange:

printf "\x1b[38;2;255;100;0mTRUECOLOR\x1b[0m\n"
ttimeoutlen

The time in milliseconds that is waited for a key code to complete.

3 Functions

IPython.terminal.interactiveshell.get_default_editor()
IPython.terminal.interactiveshell.black_reformat_handler(text_before_cursor)

We do not need to protect against error, this is taken care at a higher level where any reformat error is ignored. Indeed we may call reformatting on incomplete code.

IPython.terminal.interactiveshell.yapf_reformat_handler(text_before_cursor)