-
Notifications
You must be signed in to change notification settings - Fork 18
Home
This page is deprecated, documentation moved to: https://inquirerpy.readthedocs.io/
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 customization options.
InquirerPy
require Python3.7+.
pip3 install InquirerPy
The prompt
function takes in a list of questions and return the result.
Each question is a dictionary, depending on the type, require slight different keys to be present,
checkout detailed usage for explanation.
Rule of thumb: each question require a type
(type of prompt) and message
(question to ask). For any prompt
involving lists, a choices
(list of available choices) key is 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.
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 directly interact with individual prompt classes. It's more flexible, easier to customize and it provides IDE type hintings.
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()
- prompt
- ConfirmPrompt
- InputPrompt
- SecretPrompt
- FilepathPrompt
- ListPrompt
- RawlistPrompt
- ExpandPrompt
- CheckboxPrompt
- FuzzyPrompt
Above links are also available on the sidebar ⟶ ⟶ ⟶
You could also just copy the code snippet from documentation and run locally.
-
Clone the repository
git clone https://github.com/kazhala/InquirerPy.git cd InquirerPy
-
Create a Virtual Environment (Optional)
python -m venv venv source venv/bin/activate
-
Install dependencies
pip install -r requirements.txt
-
View all available examples
ls examples/example_*.py
Note: the
example_demo.py
is not available to run unless you installboto3
and setup AWS credentials. -
Edit and run any examples of your choice
python -m examples.example_rawlist python -m examples.example_pizza
Prompts