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

text-input.mddocs/

Text Input Prompts

Basic text input capabilities for collecting user text, passwords, and file paths with extensive customization and validation options.

Capabilities

Text Input

General purpose text input prompt with support for multi-line input, auto-completion, and extensive validation.

def text(
    message: InquirerPyMessage,
    default: InquirerPyDefault = "",
    qmark: str = "?",
    amark: str = "?", 
    instruction: str = "",
    long_instruction: str = "",
    completer: Optional[Union[Dict[str, Optional[str]], Completer]] = None,
    multicolumn_complete: bool = False,
    multiline: bool = False,
    validate: Optional[InquirerPyValidate] = None,
    invalid_message: str = "Invalid input",
    transformer: Optional[Callable[[str], Any]] = None,
    filter: Optional[Callable[[str], Any]] = None,
    keybindings: Optional[InquirerPyKeybindings] = None,
    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
) -> str

Parameters:

  • message: The question text to display
  • default: Default text value
  • qmark/amark: Custom question/answer mark symbols
  • instruction/long_instruction: Help text (short/detailed)
  • completer: Auto-completion dictionary or Completer object
  • multicolumn_complete: Enable multi-column completion display
  • multiline: Allow multi-line input with Ctrl+J
  • validate: Validation function or Validator object
  • invalid_message: Error message for validation failures
  • transformer: Function to transform display value
  • filter: Function to transform result value
  • keybindings: Custom keybinding overrides
  • wrap_lines: Enable line wrapping
  • mandatory: Require non-empty input when True
  • mandatory_message: Error message for empty mandatory input

Usage Example:

from InquirerPy import inquirer

# Basic text input
name = inquirer.text(message="Enter your name:").execute()

# With validation and default
email = inquirer.text(
    message="Email address:",
    default="user@example.com",
    validate=lambda text: "@" in text,
    invalid_message="Please enter a valid email"
).execute()

# Multi-line input
description = inquirer.text(
    message="Description:",
    multiline=True,
    instruction="Press Ctrl+J for new line"
).execute()

Secret Input

Password or secret input prompt that masks typed characters for secure input collection.

def secret(
    message: InquirerPyMessage,
    default: InquirerPyDefault = "",
    qmark: str = "?",
    amark: str = "?",
    instruction: str = "",
    long_instruction: str = "",
    validate: Optional[InquirerPyValidate] = None,
    invalid_message: str = "Invalid input",
    transformer: Optional[Callable[[str], Any]] = None,
    filter: Optional[Callable[[str], Any]] = None,
    keybindings: Optional[InquirerPyKeybindings] = None,
    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
) -> str

Usage Example:

from InquirerPy import inquirer
from InquirerPy.validator import PasswordValidator

# Basic password input
password = inquirer.secret(message="Enter password:").execute()

# With validation
secure_password = inquirer.secret(
    message="Create password:",
    validate=PasswordValidator(
        length=8,
        cap=True,
        number=True,
        special=True
    ),
    invalid_message="Password must be 8+ chars with uppercase, number, and special character"
).execute()

File Path Input

File or directory path input with auto-completion and path validation for cross-platform file selection.

def filepath(
    message: InquirerPyMessage,
    default: InquirerPyDefault = "",
    qmark: str = "?",
    amark: str = "?",
    instruction: str = "",
    long_instruction: str = "",
    multicolumn_complete: bool = False,
    validate: Optional[InquirerPyValidate] = None,
    invalid_message: str = "Invalid input",
    only_directories: bool = False,
    only_files: bool = False,
    transformer: Optional[Callable[[str], Any]] = None,
    filter: Optional[Callable[[str], Any]] = None,
    keybindings: Optional[InquirerPyKeybindings] = None,
    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
) -> str

Parameters:

  • only_directories: Restrict to directories only
  • only_files: Restrict to files only

Usage Example:

from InquirerPy import inquirer
from InquirerPy.validator import PathValidator

# File selection with auto-completion
config_file = inquirer.filepath(
    message="Select config file:",
    default="./config.json",
    only_files=True,
    validate=PathValidator(is_file=True, message="File must exist")
).execute()

# Directory selection
output_dir = inquirer.filepath(
    message="Choose output directory:",
    only_directories=True,
    validate=PathValidator(is_dir=True, message="Directory must exist")
).execute()

Class-based Usage

Direct class instantiation for advanced customization:

from InquirerPy.prompts import InputPrompt, SecretPrompt, FilePathPrompt

# InputPrompt class
prompt = InputPrompt(
    message="Enter text:",
    default="default value",
    validate=lambda x: len(x) > 3,
    transformer=lambda x: x.upper()
)
result = prompt.execute()

# SecretPrompt class
secret_prompt = SecretPrompt(
    message="Password:",
    validate=lambda x: len(x) >= 8
)
password = secret_prompt.execute()

# FilePathPrompt class  
file_prompt = FilePathPrompt(
    message="Select file:",
    only_files=True
)
filepath = file_prompt.execute()

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