LinuxCommandLibrary

ptpython

Interactive Python REPL with autocompletion

TLDR

Start a REPL (interactive shell)

$ ptpython
copy

Execute a specific Python file
$ ptpython [path/to/file.py]
copy

Execute a specific Python file and start a REPL
$ ptpython [[-i|--interactive]] [path/to/file.py]
copy

Open the menu
$ <F2>
copy

Open the history page
$ <F3>
copy

Toggle paste mode
$ <F6>
copy

Quit
$ <Ctrl d>
copy

SYNOPSIS

ptpython [OPTIONS] [SCRIPT] [ARGS...]

PARAMETERS

--version
    Shows the version of ptpython and exits.

--vi
    Enables Vi keybindings for command-line editing.

--emacs
    Enables Emacs keybindings (this is the default behavior).

--autocompletion-style [fuzzy|common]
    Chooses the autocompletion style. 'fuzzy' allows for more flexible matches, while 'common' matches from the start.

--colorscheme [default|solarized-dark|solarized-light|monokai|per-row]
    Selects a pre-defined color scheme for syntax highlighting and the UI.

--paste-mode
    Enables a special paste mode, useful for pasting large blocks of code without unintended indentations.

--confirm-exit
    Asks for confirmation before exiting the shell, preventing accidental closures.

--disable-input-validation
    Disables real-time syntax validation as you type, which can sometimes be distracting.

--history-search
    Enables incremental search through the command history (Ctrl+R in Emacs mode).

--dont-load-config
    Prevents ptpython from loading the user's default configuration file (~/.ptpython/config.py).

--config-file PATH
    Specifies an alternative path to a custom configuration file.

--quiet
    Suppresses the welcome message displayed at startup.

--startup-paths TEXT
    A comma-separated list of additional paths to add to sys.path, making modules in those directories importable.

--shell-plus
    Integrates with Django's shell_plus command if Django is installed, providing a pre-loaded Django environment.

--help
    Displays a comprehensive help message and exits.

DESCRIPTION

ptpython is an advanced, interactive Python REPL (Read-Eval-Print Loop) built on top of the powerful prompt_toolkit library. It aims to provide a superior interactive experience compared to the default Python interpreter.

Key features include intelligent autocompletion, syntax highlighting, multiline editing with easy navigation, a sophisticated history mechanism with search capabilities, and customizable key bindings (Vi and Emacs modes are supported). Users can extensively configure ptpython through a Python configuration file, allowing for personalized themes, key maps, and startup actions. It's an excellent tool for development, debugging, and general Python exploration.

CAVEATS

While ptpython provides a superior interactive experience, it is a wrapper around the standard Python interpreter, not a direct replacement. It might incur a slightly larger memory footprint or startup time compared to a bare python shell due to its enhanced graphical features and underlying dependencies. It's optimized for interactive development rather than non-interactive script execution.

CONFIGURATION FILE

ptpython is highly customizable through a Python configuration file, typically located at ~/.ptpython/config.py. This file is executed as a standard Python script upon startup, allowing users to define intricate settings for key bindings, color schemes, prompt appearance, and startup actions. This flexibility enables a deeply personalized interactive environment.

KEY BINDINGS

The shell supports both Emacs and Vi keybindings natively, configurable via command-line options. Beyond these defaults, users can define custom key mappings within the config.py file, enabling complex macros or specific shortcuts tailored to individual workflows. This allows for efficient navigation and editing within the REPL.

HISTORY

ptpython was developed by Jonathan Slenders, the creator of prompt_toolkit, a foundational library for building interactive command-line applications. It emerged as a powerful demonstration of prompt_toolkit's capabilities, aiming to modernize and enhance the default Python REPL experience. Its development focused on addressing long-standing limitations of the standard Python shell, such as rudimentary autocompletion, lack of proper multiline editing, and absence of syntax highlighting, quickly establishing itself as a popular choice in the Python developer community.

SEE ALSO

python(1), ipython(1), bpython(1)

Copied to clipboard