Inquirer3 Interactive CLI

0.6.1 · active · verified Thu Apr 16

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

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define a series of interactive questions using `inquirer3.Text` and `inquirer3.List` types, including input validation. The `inquirer3.prompt()` function collects user input and returns answers as a dictionary.

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.")

view raw JSON →