LinuxCommandLibrary

ptpython3

Run interactive Python 3 interpreter with enhancements

TLDR

View documentation for the original command

$ tldr ptpython
copy

SYNOPSIS

ptpython3 [OPTIONS] [FILE] [ARGUMENTS]

Invoking ptpython3 without arguments typically launches the interactive REPL. An optional FILE can be provided to execute a Python script, after which the REPL can optionally remain interactive. Any subsequent ARGUMENTS are passed to the script.

PARAMETERS

FILE
    Optional: Path to a Python script to execute. If combined with --interactive, the REPL starts after script execution.

ARGUMENTS
    Optional: Additional arguments passed to the script specified by FILE.

--help
    Displays a help message and exits.

--version
    Shows the ptpython3 version information and exits.

--debug
    Enables debug mode, which can provide more verbose output for troubleshooting.

--config
    Specifies an alternative path to a configuration file (default is ~/.ptpython/config.py).

--vi
    Sets the key bindings to Vi mode by default upon startup.

--emacs
    Sets the key bindings to Emacs mode by default upon startup.

--disable-history
    Disables the persistent command history for the current session.

--paste
    Enables paste mode, which is useful for pasting multiline code without unexpected indentation issues.

--interactive
    Forces the REPL to always start in interactive mode, even when a FILE is provided.

--exec-lines
    Executes the given Python code lines before starting the REPL. Useful for setting up the environment.

DESCRIPTION

ptpython3 is an advanced interactive Python shell built upon the powerful prompt_toolkit library. It serves as a superior alternative to the default Python interpreter, offering a significantly enhanced development experience. Key features include real-time syntax highlighting powered by Pygments, smart autocompletion that understands context, multiline editing for complex code blocks, and a persistent command history. It supports both Vi and Emacs key bindings, allowing users to choose their preferred editing style. While it provides many of the essential features found in more heavyweight REPLs like IPython, ptpython3 aims to be lightweight and highly customizable, making it an excellent choice for developers who spend considerable time interacting with Python.

CAVEATS

  • Installation Requirement:
    ptpython3 is not typically pre-installed on most Linux distributions. It usually requires manual installation via pip, the Python package installer.

  • Configuration:
    Customization relies on a Python configuration file (typically ~/.ptpython/config.py), which requires some familiarity with Python scripting.
  • INSTALLATION

    To install ptpython3, you typically use the Python package installer pip:

    pip install ptpython

    Ensure you are using pip associated with your Python 3 installation (e.g., pip3 if multiple Python versions are present). After installation, the command will usually be available as ptpython or ptpython3.

    CONFIGURATION

    Customization of ptpython3 is handled through a Python configuration file, usually located at ~/.ptpython/config.py. This file allows users to define custom key bindings, set default styles, enable or disable features, and configure how autocompletion works. For instance, you can enable Vi mode by default, change color schemes, or load specific modules on startup by editing this file.

    INTERACTIVE FEATURES

    ptpython3 significantly enhances the interactive Python experience with several key features:

  • Syntax Highlighting: Code is colored in real-time as you type, making it easier to read and spot errors.

  • Autocompletion: Provides intelligent, context-aware suggestions for module names, functions, methods, and variables.

  • Multiline Editing: Seamlessly write and execute code blocks spanning multiple lines, with correct indentation.

  • Key Bindings: Offers both Emacs and Vi key bindings, catering to different user preferences.

  • Paste Mode: Helps prevent unexpected indentation issues when pasting code from external sources.
  • HISTORY

    ptpython3 was developed by Jonathan Slenders, the creator of the popular prompt_toolkit library, which forms its core. It emerged as a natural application of prompt_toolkit's capabilities, aiming to provide a modern, highly interactive Python REPL that leverages all the advanced terminal features offered by its underlying library. While IPython gained popularity for its rich features, ptpython (and thus ptpython3) offers a lighter, more focused alternative, prioritizing speed and advanced terminal interaction.

    SEE ALSO

    python(1), ipython(1), pip(1)

    Copied to clipboard