ptpython: Advanced Python REPL

3.0.32 · active · verified Sat Apr 11

ptpython is an advanced, cross-platform Python REPL (Read-Eval-Print Loop) built on top of the prompt_toolkit library. It provides features like syntax highlighting, autocompletion, multiline editing, mouse support, and customizable key bindings (Emacs and Vi modes). Currently at version 3.0.32, it sees fairly frequent updates, often with several patch releases per month.

Warnings

Install

Imports

Quickstart

To start a `ptpython` shell, simply run `ptpython` in your terminal. To embed it in a Python script for debugging or interactive sessions, use `ptpython.repl.embed()`. You should pass `globals()` and `locals()` to `embed()` to make the current scope available inside the REPL.

import os
from ptpython.repl import embed

def main():
    print("Entering embedded ptpython REPL...")
    my_variable = "Hello from host script"
    # Pass globals() and locals() to make variables accessible in the REPL
    embed(globals(), locals())
    print("Exited embedded ptpython REPL.")

if __name__ == "__main__":
    # Or simply run from command line:
    # $ ptpython
    main()

view raw JSON →