Skip to content
Kevin Zhuang edited this page Oct 5, 2021 · 10 revisions

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.

demo

Install

InquirerPy require Python3.7+.

pip3 install InquirerPy

Basic Usage

Classic Syntax (PyInquirer)

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

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()

Detailed Usage

Prompts

Above links are also available on the sidebar ⟶ ⟶ ⟶

Running Examples

You could also just copy the code snippet from documentation and run locally.

  1. Clone the repository

    git clone https://github.com/kazhala/InquirerPy.git
    cd InquirerPy
  2. Create a Virtual Environment (Optional)

    python -m venv venv
    source venv/bin/activate
  3. Install dependencies

    pip install -r requirements.txt
  4. View all available examples

    ls examples/example_*.py

    Note: the example_demo.py is not available to run unless you install boto3 and setup AWS credentials.

  5. Edit and run any examples of your choice

    python -m examples.example_rawlist
    python -m examples.example_pizza