inquirer¶
Attention
This document is irrelevant if you intend to use the Classic Syntax (PyInquirer).
See also
This page documents the usage of inquirer
.
Servers as another entry point for InquirerPy.
See also
inquirer directly interact with individual prompt classes. It’s more flexible, easier to customise and also provides IDE type hintings/completions.
An example using inquirer
which incorporate multiple different types of prompts:
from InquirerPy import inquirer
from InquirerPy.validator import NumberValidator
age = inquirer.text(
message="Enter your age:",
validate=NumberValidator(),
default="18",
filter=lambda result: int(result),
transformer=lambda result: "Adult" if int(result) >= 18 else "Youth",
).execute()
drinks = ["Soda", "Cidr", "Water", "Milk"] if age < 18 else ["Wine", "Beer"]
drink = inquirer.rawlist(
message="What drinks would you like to buy:", default=2, choices=drinks
).execute()
if drink in {"Wine", "Beer"}:
bag = inquirer.select(
message="Would you like a bag:", choices=["Yes", "No"]
).execute()
confirm = inquirer.confirm(message="Confirm?", default=True).execute()
Important
The inquirer
module serves as an entry point to each prompt classes. Refer to
individual prompt documentation for prompt specific usage.
Synchronous execution¶
Each prompt contains a function execute
to start the prompt.
from InquirerPy import inquirer
def main():
result = inquirer.text(message="Name:").execute()
if __name__ == "__main__":
main()
Asynchronous execution¶
Each prompt contains a function execute_async
to start the prompt asynchronously.
import asyncio
from InquirerPy import inquirer
async def main():
result = await inquirer.text(message="Name:").execute_async()
if __name__ == "__main__":
asyncio.run(main())