A guide to customizing the Python REPL using a PYTHONSTARTUP file and the pyrepl-hacks library. Covers setting up custom keyboard shortcuts (Home/End navigation, Shift+Tab dedent, Alt+Up/Down line swapping, and custom data insertion shortcuts), monkey-patching sys.path to make a shared package available across all virtual environments, and creating your own REPL commands using the bind decorator. The post also warns that these hacks rely on the undocumented _pyrepl internal module introduced in Python 3.13, which may break in future versions.
Table of contents
Creating a PYTHONSTARTUP fileMy REPL keyboard shortcutsI created a pyrepl-hacks library for thisWait… let’s acknowledge the dragons 🐲Monkey patching sys.path to allow importing pyrepl_hacksCreating your own custom REPL commandspyrepl-hacks is just a fancy wrapperTry pyrepl-hacks and leave feedbackSort: