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:
HistoryPrompt 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
strinstances.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.)
- 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
Configinstance, 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 ofConfigurablebefore doing anything else and usingsuper():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'orNone
- autosuggestions_provider¶
 Specifies from which source automatic suggestions are provided. Can be set to
'NavigableAutoSuggestFromHistory'(up and down swap suggestions),'AutoSuggestFromHistory', orNoneto 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, seeprompt_toolkitdocumentation 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.
- enable_history_search¶
 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 andrel_linethe 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
commandkey 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:alwaysneverhas_line_belowhas_line_aboveis_cursor_at_the_end_of_linehas_selectionhas_suggestionvi_modevi_insert_modeemacs_insert_modeemacs_like_insert_modehas_completionsinsert_modedefault_buffer_focusedsearch_buffer_focusedebivimsupports_suspendis_windows_osauto_matchfocused_insertnot_inside_unclosed_stringreadline_like_completionspreceded_by_paired_double_quotespreceded_by_paired_single_quotespreceded_by_raw_str_prefixpreceded_by_two_double_quotespreceded_by_two_single_quotesfollowed_by_closing_paren_or_endpreceded_by_opening_round_parenpreceded_by_opening_bracketpreceded_by_opening_bracepreceded_by_double_quotepreceded_by_single_quotefollowed_by_closing_round_parenfollowed_by_closing_bracketfollowed_by_closing_bracefollowed_by_double_quotefollowed_by_single_quotenavigable_suggestionscursor_in_leading_wspass_through
To disable a shortcut set
new_keysto an empty list. To add a shortcut add keycreatewith valueTrue.When modifying/disabling shortcuts,
match_keys/match_filtercan be omitted if the provided specification uniquely identifies a shortcut to be modified/disabled. When modifying a shortcutnew_filterornew_keyscan 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_inputfor 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-interpreterto “ipython”) available through the built-inM-x run-pythonand third party packages such as elpy.This mode default to
Trueif theIPY_TEST_SIMPLE_PROMPTenvironment 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.
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
TRUECOLORin 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)¶