Back to main.

Calmcode Shorts

questionary logoquestionary

Installation

If you want to use questionary you can install it via:

python -m pip install questionary

Usage

The following script will allow you to give questionary a quick spin.

import questionary

name = questionary.text("What is your username").ask()
secret = questionary.password("What's your secret?").ask()

print(f"Your {name=} and {secret=}")

amazed = questionary.confirm("Are you amazed?", default=False).ask()
choice = questionary.select("What do you want to do?", choices=["A", "B", "C"],).ask()
checks = questionary.checkbox("What do you like?", choices=["foo", "bar", "baz"]).ask()
print(f"{amazed=}, {choice=} and {checks=}")

req_file = questionary.path("What is the path to your requirements file?").ask()
print(req_file)

When you run this script, you'll see prompts appear in a nice user interface. You'll even noticed that the results are different between the questionary.text and questionary.password calls.

? What is your username Vincent
? What's your secret? ***********
Your name='Vincent' and secret='supersecret'

Questionary is a neat tool that allows you to add just that extra bit of interactivity to your command line apps. If you're curious to learn more, you can find it on Github but you can also read more on the documentation page.


Back to main.