This is a request to expose the `callback API`_ of GNU readline in the readline module in the Python library. .. _callback API: http://cnswww.cns.cwru.edu/php/chet/readline/readline.html#SEC41 This interface is suitable for asynchronous use, such as with twisted. It is possible to expose the functions on Unix with ctypes:: import readline import ctypes rl_lib = ctypes.cdll.LoadLibrary("libreadline.so.5") readline.callback_handler_remove = rl_lib.rl_callback_handler_remove readline.callback_read_char = rl_lib.rl_callback_read_char # the callback needs special treatment: rlcallbackfunctype = ctypes.CFUNCTYPE(ctypes.c_void_p, ctypes.c_char_p) def setcallbackfunc(prompt, thefunc): rl_lib.rl_callback_handler_install(prompt, rlcallbackfunctype(thefunc)) readline.callback_handler_install = setcallbackfunc but it would be much better to expose them "officially".
I am pretty sure I posted a patch in the sf patch tracker... oh yes, here it is: http://bugs.python.org/issue1744456 I think it still needs some work if you want to make it impossible for users of the API to wreck the interactive prompt. If this possibility is considered ok (it does not make sense to use the callback api from the interactive prompt anyway), I think it's ok. But someone with more readline experience should probably look at it... :-)