InquirerPy¶
Introduction¶
InquirerPy
is a Python port of the famous Inquirer.js (A collection of common interactive command line user interfaces).
This project is a re-implementation of the PyInquirer project, with bug fixes of known issues, new prompts, backward compatible APIs
as well as more customisation options.
Install¶
Requirements
python >= 3.7
pip3 install InquirerPy
Basic Usage¶
InquirerPy
provides two types of syntax that you can choose to use: Classic syntax and Alternate Syntax.
Tip
For any new users, Alternate Syntax is recommended as its more flexible and extensible.
Note
Checkout the sidebar on the left for detailed explanation and usage.
Classic Syntax (PyInquirer)¶
Note
Syntax ported from PyInquirer which allows easy transition between the two projects. Checkout migration guide.
The prompt function takes a list of questions and return the result.
Each question should be an instance of dict
. Different types of prompt could require different keys, please
refer to individual prompt documentation for detailed explanation.
As a rule of thumb, each question requires a type
(type of prompt) and message
(question to ask) key. For any prompt
involving lists, a choices
(list of available choices) key is also required.
Optionally provide a name
key, prompt
will store the result under the provided name key in the final result. If
no name
key is provided, the index of the question will be used.
from InquirerPy import prompt
questions = [
{"type": "input", "message": "What's your name:", "name": "name"},
{
"type": "list",
"message": "What's your favourite programming language:",
"choices": ["Go", "Python", "Rust", "JavaScript"],
},
{"type": "confirm", "message": "Confirm?"},
]
result = prompt(questions)
name = result["name"]
fav_lang = result[1]
confirm = result[2]
Alternate Syntax¶
Alternate syntax directly interact with individual prompt
classes. It’s more flexible, easier to customise
and also provides IDE type hintings/completions.
from InquirerPy import inquirer
name = inquirer.text(message="What's your name:").execute()
fav_lang = inquirer.select(
message="What's your favourite programming language:",
choices=["Go", "Python", "Rust", "JavaScript"],
).execute()
confirm = inquirer.confirm(message="Confirm?").execute()
Detailed Usage¶
Info
Please visit the sidebar on the left.
Running Examples¶
InquirerPy
provides several examples that you can run and play around.
Clone the repository
git clone https://github.com/kazhala/InquirerPy.git
cd InquirerPy
Create a Virtual Environment (Recommended)
python3 -m venv venv
source venv/bin/activate
Install dependencies
pip3 install -r examples/requirements.txt
View all available examples
Warning
demo_alternate.py
and demo_classic.py
requires boto3 package and setup AWS credentials.
ls examples/*.py
ls examples/classic/*.py
ls examples/alternate/*.py
Edit and run any examples of your choice
python3 -m examples.classic.rawlist
# or
python3 examples/classic/rawlist
Migrating from PyInquirer¶
Most APIs from PyInquirer should be compatible with InquirerPy
. If you have discovered more incompatible APIs, please
create an issue or directly update README via a pull request.
EditorPrompt¶
InquirerPy
does not support editor prompt as of now.
CheckboxPrompt¶
The following table contains the mapping of incompatible parameters.
PyInquirer |
InquirerPy |
---|---|
pointer_sign |
pointer |
selected_sign |
enabled_symbol |
unselected_sign |
disabled_symbol |
Style¶
Every style keys from PyInquirer is present in InquirerPy
except the ones in the following table.
PyInquirer |
InquirerPy |
---|---|
selected |
pointer |
Although InquirerPy
support all the keys from PyInquirer, the styling works slightly different.
Please refer to the Style documentation for detailed information.