questionary

2.1.1 · active · verified Sun Apr 05

Questionary is a Python library for effortlessly building elegant command line user prompts. It simplifies querying users for input in CLI applications, offering various question types like text, password, select, checkbox, and confirmation prompts. As of its current version 2.1.1, it is actively maintained with regular updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `questionary.text` for free-form input and `questionary.select` for choosing from a list. It also includes basic handling for `Ctrl+C` which causes `ask()` to return `None`.

import questionary

def main():
    name = questionary.text("What's your name?").ask()
    if name is None: # User pressed Ctrl+C
        print("Operation cancelled.")
        return

    choice = questionary.select(
        "What do you want to do?",
        choices=['Order a pizza', 'Make a reservation', 'Ask for opening hours']
    ).ask()
    if choice is None:
        print("Operation cancelled.")
        return

    print(f"Hello, {name}!")
    print(f"You chose: {choice}")

if __name__ == "__main__":
    main()

view raw JSON →