{"id":414,"library":"prompt-toolkit","title":"prompt-toolkit","description":"A Python library for building powerful interactive command-line applications. Current version: 3.0.52. Release cadence: Regular updates with new features and fixes.","status":"active","version":"3.0.52","language":"python","source_language":"en","source_url":"https://github.com/prompt-toolkit/python-prompt-toolkit","tags":["command-line","interactive","Python"],"install":[{"cmd":"pip install prompt_toolkit","lang":"bash","label":"Install prompt_toolkit"}],"dependencies":[],"imports":[{"note":"Ensure correct import path to access the 'prompt' function.","symbol":"prompt","correct":"from prompt_toolkit import prompt"}],"quickstart":{"code":"from prompt_toolkit import prompt\n\nif __name__ == '__main__':\n    answer = prompt('Give me some input: ')\n    print(f'You said: {answer}')","lang":"python","description":"A simple example demonstrating the usage of the 'prompt' function from prompt_toolkit."},"warnings":[{"fix":"Update your code to remove imports from 'prompt_toolkit.shortcuts' and refactor accordingly.","message":"In version 3.0.49, the 'prompt_toolkit.shortcuts' module was removed, which may affect existing code that relies on this module.","severity":"breaking","affected_versions":"3.0.49"},{"fix":"Run your application in an interactive terminal environment (e.g., using `docker run -it` for Docker, or allocating a TTY in CI/CD setups). Alternatively, if interactive features are not required, consider using a non-interactive input method or a different library, or adjust your code to handle non-terminal input gracefully (e.g., by checking `sys.stdin.isatty()`).","message":"When using 'prompt_toolkit', ensure that the execution environment provides an interactive terminal (TTY). Running in environments without TTY allocation (e.g., certain Docker configurations, CI/CD pipelines, or background scripts) can lead to input/output errors like `PermissionError` (Errno 1: Operation not permitted) during selector registration or `EOFError` when trying to attach input.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"search_vec":"'3.0.52':17 'applic':14 'build':8 'cadenc':19 'command':12,28 'command-lin':11,27 'current':15 'featur':24 'fix':26 'interact':10,30 'librari':6 'line':13,29 'new':23 'power':9 'prompt':2 'prompt-toolkit':1 'python':5,31 'regular':20 'releas':18 'toolkit':3 'updat':21 'version':16","created_at":"2026-03-28T11:15:36.676721+00:00","updated_at":"2026-04-16T18:11:36.927428+00:00","problems":[{"fix":"Upgrade `prompt-toolkit` to the latest stable version and ensure all related packages (like `ipython`) are also up to date. You might need to uninstall and then reinstall `prompt-toolkit`. Example: `pip uninstall prompt-toolkit && pip install --upgrade prompt-toolkit` or `conda install -c conda-forge prompt_toolkit` if using Anaconda.","cause":"This error often occurs due to an incompatibility between `prompt-toolkit` and other libraries like `ipython` or `jupyter`, or an outdated installation of `prompt-toolkit` itself. The `formatted_text` module was introduced or moved, causing older versions or conflicting installations to fail to find it.","error":"ModuleNotFoundError: No module named 'prompt_toolkit.formatted_text'"},{"fix":"Rename your Python script file to something other than `prompt_toolkit.py` (e.g., `my_prompt_app.py`) to avoid conflicting with the library's package name.","cause":"This `ImportError` typically happens when a Python script file is named `prompt_toolkit.py` in the same directory as where the code is being run. Python tries to import from your local file instead of the installed library, leading to a circular import.","error":"ImportError: cannot import name 'PromptSession' from partially initialized module 'prompt_toolkit' (most likely due to a circular import)"},{"fix":"Instead of passing `output` directly to `prompt()`, create a `PromptSession` instance with the desired output and then call its `prompt()` method.\n\n```python\nimport sys\nfrom prompt_toolkit import PromptSession\nfrom prompt_toolkit.output import create_output\n\nstderr_output = create_output(sys.stderr)\nsession = PromptSession(output=stderr_output)\n\ntext = session.prompt('Enter input: ')\n```","cause":"The `prompt_toolkit.shortcuts.prompt()` function does not directly accept an `output` argument. Instead, if you need to customize the output stream (e.g., to `sys.stderr`), you should use the `PromptSession` class and pass the output object to its constructor.","error":"TypeError: prompt() got an unexpected keyword argument 'output'"},{"fix":"This often requires updating the dependent library that is trying to import `create_eventloop` to a version compatible with your `prompt-toolkit` installation, or updating `prompt-toolkit` itself. For `aws-shell`, previous solutions involved reinstalling or using specific `prompt-toolkit` versions.","cause":"This error indicates a version incompatibility. The `create_eventloop` function was removed or relocated from `prompt_toolkit.shortcuts` in newer versions of the library, but older code or dependent libraries (like `aws-shell`) might still be trying to import it.","error":"ImportError: cannot import name 'create_eventloop' from 'prompt_toolkit.shortcuts'"},{"fix":"Instead of calling `asyncio.run()` directly, you should integrate `prompt-toolkit`'s application into the existing event loop using its asynchronous API (e.g., `Application.run_async()`) or ensure that `prompt-toolkit` operations are performed within the main thread/event loop without nesting `asyncio.run()` calls. If running blocking code, consider using `run_in_executor` for better integration with asyncio.","cause":"This error occurs when you try to call `asyncio.run()` (or implicitly run an `asyncio` event loop) from within a context where an `asyncio` event loop is already running, which can happen when integrating `prompt-toolkit` with `asyncio` applications or when using threading incorrectly. `prompt-toolkit` often runs its own event loop.","error":"Exception asyncio.run() cannot be called from a running event loop"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"quickstart_score":0,"quickstart_tag":"stale","pypi_latest":"3.0.52","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/prompt-toolkit/python-prompt-toolkit","docs":"https://python-prompt-toolkit.readthedocs.io/en/stable/","changelog":null,"pypi":"https://pypi.org/project/prompt-toolkit/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops","observability"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":"verified"}}