{"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,"last_verified":"2026-05-12T13:40:37.182Z","next_check":"2026-06-26T00:00:00.000Z","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,"install_tag":"verified","quickstart_score":0,"quickstart_tag":"stale","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.42,"mem_mb":13.1,"disk_size":"21.6M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.42,"mem_mb":13.1,"disk_size":"22M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.57,"mem_mb":14.6,"disk_size":"24.0M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.48,"mem_mb":14.6,"disk_size":"24M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.77,"mem_mb":14.6,"disk_size":"15.7M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.73,"mem_mb":14.6,"disk_size":"16M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1,"mem_mb":14.1,"disk_size":"15.3M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.69,"mem_mb":14.1,"disk_size":"16M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.4,"mem_mb":12.3,"disk_size":"21.0M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.35,"mem_mb":12.3,"disk_size":"22M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}}