Python library to build pretty command line user prompts with interactive forms and validation
npx @tessl/cli install tessl/pypi-questionary@2.1.0Questionary is a Python library for effortlessly building interactive command line interfaces with beautiful prompts. It provides a comprehensive collection of input prompt types including text input, selections, confirmations, file paths, and multi-question forms, all built on top of prompt_toolkit for cross-platform compatibility and rich styling.
pip install questionaryimport questionaryFor specific prompt types:
from questionary import text, select, confirm, checkbox, formFor advanced usage:
from questionary import Question, Choice, Separator, Style, Validatorimport questionary
# Simple text input
name = questionary.text("What's your name?").ask()
# Password input (hidden text)
secret = questionary.password("Enter password:").ask()
# Yes/no confirmation
confirmed = questionary.confirm("Are you sure?").ask()
# Single selection from list
choice = questionary.select(
"Choose an option:",
choices=["Option 1", "Option 2", "Option 3"]
).ask()
# Multiple selection with checkboxes
selected = questionary.checkbox(
"Select multiple:",
choices=["Item A", "Item B", "Item C"]
).ask()
# File path input with completion
path = questionary.path("Enter file path:").ask()Questionary follows a prompt-centric architecture:
This design enables both simple single-question prompts and complex multi-step forms while maintaining consistent styling and behavior patterns across all prompt types.
Basic text input functionality including single-line text, password input, and multiline text with optional validation and custom styling.
def text(message: str, default: str = "", validate: Any = None, qmark: str = "?",
style: Optional[Style] = None, multiline: bool = False,
instruction: Optional[str] = None, lexer: Optional[Lexer] = None,
**kwargs) -> Question: ...
def password(message: str, default: str = "", validate: Any = None,
qmark: str = "?", style: Optional[Style] = None,
**kwargs) -> Question: ...Single and multiple choice selection prompts with keyboard navigation, search filtering, and customizable display options.
def select(message: str, choices: Sequence[Union[str, Choice, Dict]],
default: Optional[Union[str, Choice, Dict]] = None, qmark: str = "?",
pointer: Optional[str] = "»", style: Optional[Style] = None,
use_shortcuts: bool = False, use_arrow_keys: bool = True,
**kwargs) -> Question: ...
def checkbox(message: str, choices: Sequence[Union[str, Choice, Dict]],
default: Optional[str] = None,
validate: Callable[[List[str]], Union[bool, str]] = lambda a: True,
**kwargs) -> Question: ...
def rawselect(message: str, choices: Sequence[Union[str, Choice, Dict]],
default: Optional[str] = None, qmark: str = "?",
**kwargs) -> Question: ...Yes/no confirmation dialogs with customizable default responses and automatic key handling.
def confirm(message: str, default: bool = True, qmark: str = "?",
style: Optional[Style] = None, auto_enter: bool = True,
instruction: Optional[str] = None, **kwargs) -> Question: ...Text input with intelligent completion including word completion for predefined choices and file system path completion.
def autocomplete(message: str, choices: List[str], default: str = "",
qmark: str = "?", completer: Optional[Completer] = None,
meta_information: Optional[Dict[str, Any]] = None,
ignore_case: bool = True, match_middle: bool = True,
**kwargs) -> Question: ...
def path(message: str, default: Union[Path, str] = "", qmark: str = "?",
validate: Any = None, completer: Optional[Completer] = None,
only_directories: bool = False, **kwargs) -> Question: ...Multi-question forms that execute a series of prompts and return consolidated results, supporting conditional logic and field validation.
def form(**kwargs: Question) -> Form: ...
class Form:
def ask(self, patch_stdout: bool = False,
kbi_msg: str = DEFAULT_KBI_MESSAGE) -> Dict[str, Any]: ...
def ask_async(self, patch_stdout: bool = False,
kbi_msg: str = DEFAULT_KBI_MESSAGE) -> Dict[str, Any]: ...Comprehensive prompt execution methods supporting both synchronous and asynchronous operation, with error handling and batch processing capabilities.
def prompt(questions: Union[Dict, Iterable[Mapping]],
answers: Optional[Mapping] = None, patch_stdout: bool = False,
true_color: bool = False, kbi_msg: str = DEFAULT_KBI_MESSAGE,
**kwargs) -> Dict[str, Any]: ...
def prompt_async(questions: Union[Dict, Iterable[Mapping]],
answers: Optional[Mapping] = None, **kwargs) -> Dict[str, Any]: ...Essential classes for building and customizing prompts, including choice configuration, styling, validation, and conditional logic.
class Question:
def ask(self, patch_stdout: bool = False,
kbi_msg: str = DEFAULT_KBI_MESSAGE) -> Any: ...
def ask_async(self, patch_stdout: bool = False,
kbi_msg: str = DEFAULT_KBI_MESSAGE) -> Any: ...
def skip_if(self, condition: bool, default: Any = None) -> Question: ...
class Choice:
def __init__(self, title: FormattedText, value: Optional[Any] = None,
disabled: Optional[str] = None, checked: Optional[bool] = False,
shortcut_key: Optional[Union[str, bool]] = True,
description: Optional[str] = None) -> None: ...
class Separator(Choice):
def __init__(self, line: Optional[str] = None) -> None: ...Additional utility functions for formatted output and prompt toolkit integration.
def print(text: str, style: Optional[str] = None, **kwargs) -> None: ...
def press_any_key_to_continue(message: Optional[str] = None,
style: Optional[Style] = None,
**kwargs) -> Question: ...# Core types
FormattedText = Union[str, List[Tuple[str, str]], List[Tuple[str, str, Callable]], None]
# Form field definition
class FormField(NamedTuple):
key: str
question: Question
# Re-exported from prompt_toolkit
class Style: ...
class Validator: ...
class ValidationError(Exception): ...