Inquirer is a Python library that provides a collection of common interactive command-line user interfaces, based on the popular Inquirer.js. It aims to simplify asking questions, parsing and validating answers, and managing hierarchical prompts in CLI applications. The library is actively maintained and receives regular updates, with the current version being 3.4.1.
pip install inquirerVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create a list of different question types (Text, List, Confirm) and use `inquirer.prompt` to display them to the user, collecting the answers in a dictionary.
Upgrade Python to 3.9.2 or newer, or downgrade `inquirer` to 3.4.0 or earlier.
Review code using `inquirer.Path` and remove the `normalize_to_absolute_path` argument. Adjust path handling logic if absolute paths were previously relied upon through this argument.
Ensure your validation lambda or function has the signature `def validate_func(answers, current):` even if `answers` is not used. Return `True` for success, or raise `inquirer.errors.ValidationError('', reason='Your custom message')` for a custom error.Ensure your virtual environment is activated before running `pip install inquirer`. Verify that the Python interpreter being used is the one from the virtual environment.
Use descriptive variable names for question IDs that do not conflict with Python's built-in keywords or types. For example, instead of `list = [...]`, use `my_list_of_questions = [...]`.
Report any Windows-specific issues encountered on the GitHub repository. Consider testing your CLI application on a UNIX-like environment if consistent behavior is critical across platforms.
Install the library using pip: `pip install inquirer`
Ensure you are instantiating question objects from the `inquirer` module correctly. For example, to create a list question, use `inquirer.List(...)` after importing `inquirer`:
```python
import inquirer
questions = [
inquirer.List('size',
message='What size do you need?',
choices=['Jumbo', 'Large', 'Standard', 'Medium', 'Small', 'Micro'],
),
]
answers = inquirer.prompt(questions)
```In PyCharm, enable 'Emulate terminal in output console' in your Run/Debug Configuration. Alternatively, run your Python script directly from a system terminal (e.g., cmd, PowerShell, Bash) outside of the IDE.
Ensure that the variable you are calling `.items()` on is indeed a dictionary. If `inquirer.prompt()` has returned its expected dictionary, you can iterate over it directly. If you have a list of dictionaries, iterate through the list first and then call `.items()` on each dictionary within the loop.
```python
import inquirer
questions = [
inquirer.Text('name', message="What's your name"),
]
answers = inquirer.prompt(questions)
# Correct usage: answers is a dictionary
if answers:
for key, value in answers.items():
print(f"{key}: {value}")
# Incorrect usage (would cause the error if 'my_list_var' was a list):
# for key, value in my_list_var.items():
# print(f"{key}: {value}")
```