{"id":3221,"library":"ptpython","title":"ptpython: Advanced Python REPL","description":"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.","status":"active","version":"3.0.32","language":"en","source_language":"en","source_url":"https://github.com/prompt-toolkit/ptpython","tags":["REPL","interactive","prompt-toolkit","developer-tool","debugger","shell"],"install":[{"cmd":"pip install ptpython","lang":"bash","label":"Install ptpython"},{"cmd":"pip install ptpython[ptipython]","lang":"bash","label":"Install with IPython support"}],"dependencies":[{"reason":"Core UI toolkit for building interactive command line applications, ptpython is built on top of it.","package":"prompt_toolkit","optional":false},{"reason":"Used for code completion and introspection.","package":"jedi","optional":false},{"reason":"Used for syntax highlighting.","package":"pygments","optional":false},{"reason":"Used for determining platform-specific configuration file locations.","package":"appdirs","optional":false},{"reason":"Optional dependency for using ptipython, which integrates ptpython with IPython's features.","package":"ipython","optional":true}],"imports":[{"note":"Used to embed the ptpython REPL directly into a Python application or script. It's common to pass `globals()` and `locals()` to make current scope variables available.","symbol":"embed","correct":"from ptpython.repl import embed"},{"note":"Used to explicitly load a configuration file when embedding the REPL, as configuration files are otherwise ignored in embedded mode.","symbol":"run_config","correct":"from ptpython.repl import run_config"}],"quickstart":{"code":"import os\nfrom ptpython.repl import embed\n\ndef main():\n    print(\"Entering embedded ptpython REPL...\")\n    my_variable = \"Hello from host script\"\n    # Pass globals() and locals() to make variables accessible in the REPL\n    embed(globals(), locals())\n    print(\"Exited embedded ptpython REPL.\")\n\nif __name__ == \"__main__\":\n    # Or simply run from command line:\n    # $ ptpython\n    main()","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade to Python 3.8 or newer, or pin ptpython to <3.0.30.","message":"Python 3.7 support was dropped in version 3.0.30. Users on Python 3.7 or older must use an earlier ptpython version (e.g., ptpython 2.0.5 for Python < 3.6, or a 2.x version for Python 3.7).","severity":"breaking","affected_versions":">=3.0.30"},{"fix":"Explicitly load your configuration using `from ptpython.repl import run_config; run_config(repl, config_path)` within your `configure` callback passed to `embed()`.","message":"When embedding the REPL using `ptpython.repl.embed()`, configuration files (e.g., `~/.config/ptpython/config.py`) are ignored by default. This can lead to unexpected behavior if you rely on custom settings.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure you explicitly pass `--asyncio` when you intend to use the asyncio-enabled REPL for top-level await or other async features.","message":"Since version 3.0.24, the `--asyncio` flag is explicitly required to activate the asyncio REPL when running `ptpython` from the command line. Previously, asyncio mode might have been implicitly active under certain conditions.","severity":"breaking","affected_versions":">=3.0.24"},{"fix":"Be aware that both `exit` and `exit()` will work to leave the embedded REPL.","message":"Version 3.0.28 introduced a custom `exit` function that can be called without parentheses (i.e., just `exit`) to return from the REPL when embedded. While convenient, users accustomed to always calling `exit()` might find this behavior unexpected.","severity":"gotcha","affected_versions":">=3.0.28"},{"fix":"If the default theme's colors are unsatisfactory, you can configure a custom color scheme in your `config.py` file or select a different theme if available.","message":"In version 3.0.32, the default code theme ('default-ansi') switched to using ANSI colors instead of RGB. This can alter the appearance of syntax highlighting depending on your terminal emulator's color configuration, potentially affecting contrast.","severity":"gotcha","affected_versions":">=3.0.32"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}