Python port of Inquirer.js providing interactive command-line user interfaces with extensive customization options.
—
Basic text input capabilities for collecting user text, passwords, and file paths with extensive customization and validation options.
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
) -> strParameters:
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()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
) -> strUsage 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 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
) -> strParameters:
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()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