CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-inquirerpy

Python port of Inquirer.js providing interactive command-line user interfaces with extensive customization options.

Pending
Overview
Eval results
Files

selection.mddocs/

Selection Prompts

Single and multi-selection list prompts with navigation, customizable display options, and support for complex choice structures.

Capabilities

Select (List) Prompt

Single-selection list prompt with keyboard navigation and customizable display options.

def select(
    message: InquirerPyMessage,
    choices: InquirerPyListChoices,
    default: InquirerPyDefault = None,
    qmark: str = "?",
    amark: str = "?",
    pointer: str = "❯",
    instruction: str = "",
    long_instruction: str = "",
    transformer: Optional[Callable[[Any], Any]] = None,
    filter: Optional[Callable[[Any], Any]] = None,
    height: Optional[Union[int, str]] = None,
    max_height: Optional[Union[int, str]] = None,
    border: bool = False,
    validate: Optional[InquirerPyValidate] = None,
    invalid_message: str = "Invalid input",
    keybindings: Optional[InquirerPyKeybindings] = None,
    show_cursor: bool = True,
    cycle: bool = True,
    wrap_lines: bool = True,
    mandatory: bool = True,
    mandatory_message: str = "Mandatory prompt",
    style: Optional[InquirerPyStyle] = None,
    vi_mode: bool = False,
    raise_keyboard_interrupt: bool = True,
    session_result: Optional[InquirerPySessionResult] = None,
    **kwargs
) -> Any

Parameters:

  • choices: List of choices or callable returning choices
  • pointer: Symbol indicating current selection (default: ❯)
  • height/max_height: Control visible list height
  • border: Add border around choices
  • show_cursor: Show selection cursor
  • cycle: Allow cycling from last to first choice

Usage Examples:

Basic selection:

from InquirerPy import inquirer

# Simple choice selection
framework = inquirer.select(
    message="Choose web framework:",
    choices=["Flask", "Django", "FastAPI", "Tornado"],
    default="FastAPI"
).execute()

Complex choices with values:

# Choices with display names and actual values
database = inquirer.select(
    message="Select database:",
    choices=[
        {"name": "PostgreSQL (Recommended)", "value": "postgresql"},
        {"name": "MySQL", "value": "mysql"}, 
        {"name": "SQLite", "value": "sqlite"},
        {"name": "MongoDB", "value": "mongodb"}
    ]
).execute()

With separators and height control:

from InquirerPy import inquirer
from InquirerPy.separator import Separator

environment = inquirer.select(
    message="Choose deployment environment:",
    choices=[
        "development",
        "testing", 
        Separator("--- Production ---"),
        "staging",
        "production",
        Separator("--- Cloud ---"),
        "aws",
        "gcp",
        "azure"
    ],
    height="50%",
    border=True
).execute()

Checkbox (Multi-select) Prompt

Multi-selection prompt allowing users to select multiple options with checkboxes.

def checkbox(
    message: InquirerPyMessage,
    choices: InquirerPyListChoices,
    default: Any = None,
    qmark: str = "?",
    amark: str = "?",
    pointer: str = "❯",
    enabled_symbol: str = "●",
    disabled_symbol: str = "○",
    border: bool = False,
    instruction: str = "",
    long_instruction: str = "",
    transformer: Optional[Callable[[Any], Any]] = None,
    filter: Optional[Callable[[Any], Any]] = None,
    height: Optional[Union[int, str]] = None,
    max_height: Optional[Union[int, str]] = None,
    validate: Optional[InquirerPyValidate] = None,
    invalid_message: str = "Invalid input",
    keybindings: Optional[InquirerPyKeybindings] = None,
    show_cursor: bool = True,
    cycle: bool = True,
    wrap_lines: bool = True,
    mandatory: bool = True,
    mandatory_message: str = "Mandatory prompt",
    style: Optional[InquirerPyStyle] = None,
    vi_mode: bool = False,
    raise_keyboard_interrupt: bool = True,
    session_result: Optional[InquirerPySessionResult] = None,
    **kwargs
) -> List[Any]

Parameters:

  • enabled_symbol: Symbol for selected items (default: ●)
  • disabled_symbol: Symbol for unselected items (default: ○)
  • default: List of default selected values or callable

Returns: List of selected values (empty list if none selected)

Usage Examples:

Basic multi-selection:

# Multiple technology selection
technologies = inquirer.checkbox(
    message="Select technologies:",
    choices=["Python", "JavaScript", "Java", "Go", "Rust", "C++"],
    default=["Python", "JavaScript"]
).execute()

With validation:

# Require at least one selection
features = inquirer.checkbox(
    message="Select features to enable:",
    choices=["Authentication", "Database", "Caching", "Logging", "Monitoring"],
    validate=lambda result: len(result) >= 1,
    invalid_message="Please select at least one feature"
).execute()

Rawlist (Numbered) Prompt

Numbered list selection limited to 9 choices with keyboard shortcuts.

def rawlist(
    message: InquirerPyMessage,
    choices: InquirerPyListChoices,
    default: InquirerPyDefault = None,
    separator: str = ") ",
    qmark: str = "?",
    amark: str = "?",
    pointer: str = " ",
    instruction: str = "",
    long_instruction: str = "",
    transformer: Optional[Callable[[Any], Any]] = None,
    filter: Optional[Callable[[Any], Any]] = None,
    height: Optional[Union[int, str]] = None,
    max_height: Optional[Union[int, str]] = None,
    border: bool = False,
    validate: Optional[InquirerPyValidate] = None,
    invalid_message: str = "Invalid input",
    keybindings: Optional[InquirerPyKeybindings] = None,
    show_cursor: bool = True,
    cycle: bool = True,
    wrap_lines: bool = True,
    mandatory: bool = True,
    mandatory_message: str = "Mandatory prompt",
    style: Optional[InquirerPyStyle] = None,
    vi_mode: bool = False,
    raise_keyboard_interrupt: bool = True,
    session_result: Optional[InquirerPySessionResult] = None,
    **kwargs
) -> Any

Parameters:

  • separator: Text between number and choice (default: ") ")
  • Maximum 9 choices: Limited by keyboard number keys 1-9

Usage Example:

# Quick numbered selection  
priority = inquirer.rawlist(
    message="Select priority level:",
    choices=["Low", "Medium", "High", "Critical"],
    default="Medium"
).execute()
# Displays as: 1) Low  2) Medium  3) High  4) Critical

Advanced Choice Structures

Choice Objects

Choices can be strings, dictionaries, or Choice objects:

# String choices (simple)
choices = ["Option 1", "Option 2", "Option 3"]

# Dictionary choices (name/value pairs)
choices = [
    {"name": "Development Server", "value": "dev"},
    {"name": "Production Server", "value": "prod"}
]

# Choice objects with additional properties
from InquirerPy.base.control import Choice

choices = [
    Choice("item1", name="First Item", enabled=True),
    Choice("item2", name="Second Item", enabled=False),
    Choice("item3", name="Third Item")
]

Dynamic Choices

Choices can be generated dynamically based on previous answers:

from InquirerPy import prompt

questions = [
    {
        "type": "select",
        "message": "Choose category:",
        "choices": ["Frontend", "Backend", "DevOps"],
        "name": "category"
    },
    {
        "type": "checkbox", 
        "message": "Select tools:",
        "choices": lambda answers: {
            "Frontend": ["React", "Vue", "Angular"],
            "Backend": ["Django", "Flask", "FastAPI"], 
            "DevOps": ["Docker", "Kubernetes", "Terraform"]
        }.get(answers["category"], []),
        "name": "tools"
    }
]

result = prompt(questions)

Class-based Usage

from InquirerPy.prompts import ListPrompt, CheckboxPrompt, RawlistPrompt

# ListPrompt class
list_prompt = ListPrompt(
    message="Choose option:",
    choices=["A", "B", "C"],
    height=10,
    border=True
)
selection = list_prompt.execute()

# CheckboxPrompt class
checkbox_prompt = CheckboxPrompt(
    message="Select multiple:",
    choices=["X", "Y", "Z"],
    default=["X"]
)
selections = checkbox_prompt.execute()

# RawlistPrompt class
rawlist_prompt = RawlistPrompt(
    message="Pick one:",
    choices=["First", "Second", "Third"],
    separator=" -> "
)
pick = rawlist_prompt.execute()

Keyboard Navigation

  • Up/Down Arrows: Navigate choices
  • Space: Toggle selection (checkbox) or select (list)
  • Enter: Confirm selection
  • Tab: Move to next choice (in some modes)
  • Numbers 1-9: Quick selection (rawlist)
  • Ctrl+A: Select all (checkbox)
  • Ctrl+I: Invert selection (checkbox)

Install with Tessl CLI

npx tessl i tessl/pypi-inquirerpy

docs

advanced-prompts.md

classic-api.md

confirmation.md

index.md

selection.md

text-input.md

utilities.md

tile.json