bpython
bpython is a lightweight Python interpreter that provides a fancy curses-based interface to the standard Python REPL. It enhances the interactive experience with features such as syntax highlighting, expected parameter lists, auto-indentation, and autocompletion. It also includes unique functionalities like 'rewind' (undoing the last line), code pastebin, and in-editor session editing. The library is actively maintained, with version 0.26 being the latest release, and new versions often focus on supporting the latest Python releases.
Warnings
- breaking bpython version 0.26 and newer dropped support for Python 3.9. If you are on Python 3.9, you must use an older version of bpython (e.g., 0.25) or upgrade your Python interpreter. This contradicts the general PyPI 'requires_python: >=3.9' but is explicit in release notes.
- breaking The `bpython-cli` rendering backend was entirely removed in version 0.25, following its deprecation in 0.19. If you were explicitly using this backend, your setup will break.
- breaking Support for Python 2 was completely dropped in version 0.21. Attempts to run bpython 0.21 or newer with Python 2 will fail.
- breaking Support for Python 3.7 and 3.8 was dropped in version 0.25. Users on these Python versions must use an older bpython release (e.g., 0.24) or upgrade their Python interpreter.
- gotcha For clipboard functionality (copy/paste from/to bpython), the `pyperclip` package must be installed separately. Without it, clipboard operations will not work.
- gotcha Prior to version 0.22, the `bpython.embed()` function did not correctly honor local variables passed to it when embedded within a script. This meant the embedded session might not have access to the expected local scope.
Install
-
pip install bpython
Imports
- bpython (command line)
$ bpython
- embed
from bpython import embed
Quickstart
import bpython
def my_function(x, y):
return x * y
print("Starting bpython embedded session...")
# You can pass a dictionary of local variables to the embed function
bpython.embed(locals={'my_func': my_function, 'value': 10})
print("Exited bpython embedded session.")