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
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

index.mddocs/

InquirerPy

A comprehensive Python library that provides interactive command-line user interfaces, serving as a modern port of the popular Inquirer.js library. InquirerPy offers a rich collection of customizable prompts built on top of prompt-toolkit, providing cross-platform compatibility with extensive customization options for styling, key bindings, and modern Python type hinting.

Package Information

  • Package Name: InquirerPy
  • Language: Python
  • Installation: pip install InquirerPy
  • Python Requirements: >= 3.7

Core Imports

Classic syntax (PyInquirer compatible):

from InquirerPy import prompt

Alternate syntax with type hints:

from InquirerPy import inquirer

Individual prompt classes:

from InquirerPy.prompts import InputPrompt, ConfirmPrompt, ListPrompt

Basic Usage

Classic Syntax

from InquirerPy import prompt

questions = [
    {"type": "input", "message": "What's your name:", "name": "name"},
    {"type": "confirm", "message": "Confirm?", "name": "confirm", "default": True},
    {"type": "list", "message": "Choose option:", "choices": ["Option 1", "Option 2"], "name": "choice"}
]

result = prompt(questions)
print(f"Hello {result['name']}, you chose {result['choice']}")

Alternate Syntax

from InquirerPy import inquirer

name = inquirer.text(message="What's your name:").execute()
confirm = inquirer.confirm(message="Confirm?", default=True).execute()
choice = inquirer.select(message="Choose option:", choices=["Option 1", "Option 2"]).execute()

print(f"Hello {name}, you chose {choice}")

Architecture

InquirerPy is built on a hierarchical architecture:

  • Entry Points: Two main APIs - classic prompt() function and alternate inquirer module
  • Prompt Classes: Specialized classes for different input types inheriting from base classes
  • Base Classes: BaseSimplePrompt, BaseComplexPrompt, and BaseListPrompt providing common functionality
  • Components: Validators, separators, styling utilities, and UI containers
  • Integration: Built on prompt-toolkit for cross-platform terminal handling

Capabilities

Text Input Prompts

Basic text input, password/secret input, and file path selection with auto-completion and validation support.

def text(message, default="", validate=None, **kwargs): ...
def secret(message, default="", validate=None, **kwargs): ...  
def filepath(message, default="", only_files=False, only_directories=False, **kwargs): ...

Text Input

Confirmation Prompts

Yes/no confirmation prompts with customizable confirm/reject letters and single keypress operation.

def confirm(message, default=False, confirm_letter="y", reject_letter="n", **kwargs): ...

Confirmation

Selection Prompts

Single and multi-selection list prompts with navigation, searching, and customizable display options.

def select(message, choices, default=None, **kwargs): ...
def checkbox(message, choices, default=None, **kwargs): ...
def rawlist(message, choices, default=None, separator=") ", **kwargs): ...

Selection

Advanced Prompts

Specialized prompts including fuzzy search, expandable choices, and numeric input with validation.

def fuzzy(message, choices, default="", match_exact=False, **kwargs): ...
def expand(message, choices, default="", help_msg="Help, list all choices", **kwargs): ...
def number(message, default=0, float_allowed=False, min_allowed=None, max_allowed=None, **kwargs): ...

Advanced Prompts

Classic API Functions

PyInquirer-compatible prompt functions supporting question dictionaries and async operations.

def prompt(questions, style=None, vi_mode=False, keybindings=None, **kwargs): ...
def prompt_async(questions, style=None, vi_mode=False, keybindings=None, **kwargs): ...

Classic API

Utilities and Customization

Styling, validation, separators, and utility functions for prompt customization and enhanced functionality.

def get_style(style=None, style_override=True): ...
class Separator(line="---------------"): ...
class NumberValidator(message="Input should be a number", float_allowed=False): ...

Utilities

Common Types

# Session result type
InquirerPySessionResult = Dict[Union[str, int], Optional[Union[str, bool, List[Any]]]]

# Type aliases for flexible parameter types
InquirerPyMessage = Union[str, Callable[[InquirerPySessionResult], str]]
InquirerPyDefault = Union[Any, Callable[[InquirerPySessionResult], Any]]
InquirerPyChoice = Union[List[Any], List["Choice"], List[Dict[str, Any]]]
InquirerPyListChoices = Union[
    Callable[[InquirerPySessionResult], InquirerPyChoice], 
    InquirerPyChoice
]
InquirerPyValidate = Union[Callable[[Any], bool], "Validator"]
InquirerPyKeybindings = Dict[str, List[Dict[str, Union[str, "FilterOrBool", List[str]]]]]
InquirerPyQuestions = Union[List[Dict[str, Any]], Dict[str, Any]]

# Style configuration
class InquirerPyStyle(NamedTuple):
    dict: Dict[str, str]

# Choice classes for prompts
@dataclass
class Choice:
    value: Any
    name: Optional[str] = None
    enabled: bool = False

@dataclass  
class ExpandChoice(Choice):
    key: Optional[str] = None

@dataclass
class ExpandHelp:
    key: str = "h"
    message: str = "Help, list all choices"

docs

advanced-prompts.md

classic-api.md

confirmation.md

index.md

selection.md

text-input.md

utilities.md

tile.json