Trey Hunner: Handy Python REPL... Note

Trey Hunner: Handy Python REPL Modifications

The author frequently uses the Python REPL for various coding tasks and teaching. They customize the REPL using a PYTHONSTARTUP file to automatically run code on startup. This setup involves defining custom keyboard shortcuts for easier code editing, like moving to the beginning/end of code blocks and line swapping. These customizations rely on the _pyrepl and _colorize modules, added in Python 3.13 and 3.14. The author created a package, pyrepl-hacks, to simplify these customizations and hide the underlying implementation details. To make the library accessible in every REPL, they modified sys.path. This installs the library in a specific location. The author also provides a way to create custom REPL commands using decorators. The package simplifies the process, making keybindings user-friendly. The author emphasizes that using these internal modules is undocumented and therefore risky. They invite feedback and contributions to the pyrepl-hacks project.