Registry / devops / prompt-toolkit

prompt-toolkit

JSON →
library3.0.52pypypi✓ verified 52d ago

A Python library for building powerful interactive command-line applications. Current version: 3.0.52. Release cadence: Regular updates with new features and fixes.

devopsobservability
pip install prompt_toolkit
Install & Compatibility
Where this runs
tested against v3.0.52 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.925 runs
installs and imports cleanly · install 0.0s · import 0.604s · 28.1MB
glibc
py 3.103.925 runs
installs and imports cleanly · install 1.9s · import 0.521s · 29MB
24MB installed
● package 24MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

prompt
from prompt_toolkit import prompt
Ensure correct import path to access the 'prompt' function.

A simple example demonstrating the usage of the 'prompt' function from prompt_toolkit.

from prompt_toolkit import prompt if __name__ == '__main__': answer = prompt('Give me some input: ') print(f'You said: {answer}')
Debug
Known issues
breakingIn version 3.0.49, the 'prompt_toolkit.shortcuts' module was removed, which may affect existing code that relies on this module.
fix
Update your code to remove imports from 'prompt_toolkit.shortcuts' and refactor accordingly.
affects: 3.0.49
gotchaWhen 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.
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()`).
affects: All
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'prompt_toolkit.formatted_text'
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.
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.
ImportError: cannot import name 'PromptSession' from partially initialized module 'prompt_toolkit' (most likely due to a circular import)
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.
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.
TypeError: prompt() got an unexpected keyword argument 'output'
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.
fix
Instead of passing `output` directly to `prompt()`, create a `PromptSession` instance with the desired output and then call its `prompt()` method.

```python
import sys
from prompt_toolkit import PromptSession
from prompt_toolkit.output import create_output

stderr_output = create_output(sys.stderr)
session = PromptSession(output=stderr_output)

text = session.prompt('Enter input: ')
```
ImportError: cannot import name 'create_eventloop' from 'prompt_toolkit.shortcuts'
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.
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.
Exception asyncio.run() cannot be called from a running event loop
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.
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.
Upgrade
Version history
3.0.52latest on PyPI
Audit
Dependencies

No dependency data recorded yet.

Agent activity
86 hits · last 30 days
node
12
ahrefsbot
3
seranking-bot
3
bytedance
2
Resources