Here’s a simple example of using multiline_input. It uses a little routine to calculate whether brackets in the input are balanced. Whenever they are not balanced, the input is considered incomplete. It’s quite simple to get this much working, and really provides a great interactive experience.
But I suspect making this library public is a question of justifying the effort to maintain another public API and surface of guaranteed behaviours.
I think the most productive way forward long term, is to create a third party library on PyPi for, to demonstrate demand. All users are free to fork code in the stdlib, under the normal PSF license.
Make it easy for them to show they too are also out there, and they want this too.
It feels like it would be a weird situation to re-fork the python _pyrepl, which used to be a distinct github and pypi project, which designated itself deprecated when python took a vendored copy and made it a private API…
Use _pyrepl under the same condition that one uses pyrepl, at your own risk that apis change.
The latest version of pyrepl, a year ago, is 0.11.4, so it had no stability guarantee either. The release years for available older pyrepl versions were 2019, 2012, 2010, and 2007, so it was not very actively maintained.
The previous C-coded REPL had no python interface, so being able to import _pyrepl in an improvement. It has seen much more active maintainance. But its purpose is to implement REPL in a more maintainable form.
The public CLI module is code, which uses codeop to compile, for a Python CLI. It might be usable, but changing the criterion for more lines would be harder, requiring subclassing and overriding. I would just use the imported readline function.
The problem with exposing just multiline_input() is that _pyrepl.readline implements a subset of the unix readline module + multiline_input on top of _pyrepl. The function itself is a method of a class instance and not directly separable from everything else: _ReadlineWrapper().multiline_input. The method depends on the _pyrepl Console and reader.
The blog shows how to do multiline input with your own “more_lines” function in 3.13+, and how to do custom colorization in 3.14+, tested through 3.16.
I still think this would be a fantastic facility to expose in a structured way, but I appreciate that doing so might be a burden to core developers.