Inquirer3 Interactive CLI
Inquirer3 is a Python library providing a collection of common interactive command-line user interfaces, closely mirroring the functionality of Inquirer.js. It is a community-driven fork of the original `python-inquirer` project, aiming for more responsive development and maintenance. The library simplifies the process of asking end-user questions, parsing and validating answers, and managing hierarchical prompts in terminal applications. The current version is 0.6.1, and it maintains an active release cadence with regular updates.
Common errors
-
ModuleNotFoundError: No module named 'inquirer3'
cause The `inquirer3` library is not installed in the currently active Python environment, or your IDE/script is configured to use a different Python interpreter where it is not installed.fixActivate your virtual environment (if using one) and run `pip install inquirer3`. If using an IDE, ensure it's configured to use the correct Python interpreter where `inquirer3` is installed. -
ModuleNotFoundError: No module named 'python_editor' (or similar for 'editor')
cause The `Editor` question type relies on an external editor library. For `inquirer3 < 0.6.0`, it required `python-editor`. For `inquirer3 >= 0.6.0`, it requires `editor`. This error indicates the necessary dependency is missing.fixFor `inquirer3 >= 0.6.0`, install `pip install editor`. For `inquirer3 < 0.6.0`, install `pip install python-editor`. Also, ensure your system has a text editor (e.g., `vim`, `nano`) or set the `EDITOR` or `VISUAL` environment variables. [cite: 1, v0.6.0 release notes] -
TypeError: prompt() got an unexpected keyword argument 'questions'
cause This typically occurs when trying to pass a dictionary-based question list (common in `PyInquirer`) to `inquirer3.prompt`, which expects a list of `inquirer3.Question` objects (e.g., `inquirer3.Text`, `inquirer3.List`).fixEnsure that `inquirer3.prompt` is called with a list of instantiated `inquirer3.Question` objects, like `[inquirer3.Text('name', message='...'), inquirer3.List('choice', choices=['A', 'B'])]`. Do not use dictionary representations for questions.
Warnings
- breaking In version 0.6.0, the dependency for the `Editor` question type changed from `python-editor` to `editor`. If you use the `Editor` question, you must install the `editor` package (`pip install editor`) and potentially uninstall `python-editor` to avoid conflicts or errors.
- gotcha Inquirer3's platform support is primarily for UNIX-based systems (macOS, Linux). While Windows has experimental support, users might encounter unexpected behavior or rendering issues. It's recommended to test thoroughly on Windows if targeting that platform.
- gotcha There are multiple Python libraries with 'inquirer' in their name (`python-inquirer`, `PyInquirer`, `inquirerpy`, `inquirer3`). Ensure you are importing from `inquirer3` and installing the `inquirer3` package specifically to avoid compatibility issues or `ModuleNotFoundError` due to different APIs or underlying dependencies.
Install
-
pip install inquirer3
Imports
- Text
from inquirer3 import Text
- List
from inquirer3 import List
- Checkbox
from inquirer3 import Checkbox
- prompt
import inquirer3 answers = inquirer3.prompt(questions)
Quickstart
import inquirer3
import re
questions = [
inquirer3.Text('name', message="What's your name?"),
inquirer3.Text(
'phone',
message="What's your phone number?",
validate=lambda _, x: re.match(r'\+?\d[\d ]+\d', x) or 'Invalid phone number'
),
inquirer3.List(
'size',
message='What size do you need?',
choices=['Large', 'Medium', 'Small'],
default='Medium'
)
]
answers = inquirer3.prompt(questions)
print(f"Hello {answers['name']}! Your phone is {answers['phone']} and you need a {answers['size']} size.")