or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

autocomplete-paths.mdcore-classes.mdexecution-control.mdforms.mdindex.mdselection-prompts.mdtext-input.md
tile.json

tessl/pypi-questionary

Python library to build pretty command line user prompts with interactive forms and validation

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/questionary@2.1.x

To install, run

npx @tessl/cli install tessl/pypi-questionary@2.1.0

index.mddocs/

Questionary

Questionary 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.

Package Information

  • Package Name: questionary
  • Language: Python
  • Installation: pip install questionary
  • Version: 2.1.0

Core Imports

import questionary

For specific prompt types:

from questionary import text, select, confirm, checkbox, form

For advanced usage:

from questionary import Question, Choice, Separator, Style, Validator

Basic Usage

import 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()

Architecture

Questionary follows a prompt-centric architecture:

  • Question: Core class representing individual prompts with execution methods
  • Prompt Functions: Factory functions (text, select, etc.) that create configured Question instances
  • Form: Container for multi-question workflows with shared execution
  • Choice/Separator: Configuration objects for selection-based prompts
  • Validation: Input validation through Validator classes and custom functions

This design enables both simple single-question prompts and complex multi-step forms while maintaining consistent styling and behavior patterns across all prompt types.

Capabilities

Text Input Prompts

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: ...

Text Input

Selection Prompts

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: ...

Selection Prompts

Confirmation Prompts

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: ...

Autocomplete and Path Input

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: ...

Autocomplete and Paths

Forms and Multi-Question Workflows

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]: ...

Forms

Prompt Execution and Control

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]: ...

Execution Control

Core Classes and Configuration

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: ...

Core Classes

Utility Functions

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: ...

Type Definitions

# 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): ...