API Reference¶
prompt¶
This module contains the classic entrypoint for creating prompts.
A PyInquirer compatible entrypoint prompt()
.
- InquirerPy.resolver.prompt(questions, style=None, vi_mode=False, raise_keyboard_interrupt=True, keybindings=None, style_override=True)[source]¶
Classic syntax entrypoint to create a prompt session.
Resolve user provided list of questions, display prompts and get the results.
- Parameters
questions (Union[List[Dict[str, Any]], Dict[str, Any]]) – A list of question to ask. Refer to documentation for more info.
style (Optional[Dict[str, str]]) – A
dict
containing the style specification for the prompt. Refer to Style for more info.vi_mode (bool) – Use vim keybindings for the prompt instead of the default emacs keybindings. Refer to keybindings for more info.
raise_keyboard_interrupt (bool) – Raise the
KeyboardInterrupt
exception when ctrl-c is pressed. If false, the result will be None and the question is skiped.keybindings (Optional[Dict[str, List[Dict[str, Union[str, FilterOrBool, List[str]]]]]]) – List of custom keybindings to apply. Refer to documentation for more info.
style_override (bool) – Override all default styles. When providing any style customisation, all default styles are removed when this is True.
- Returns
A dictionary containing all of the question answers. The key is the name of the question and the value is the user answer. If the name key is not present as part of the question, then the question index will be used as the key.
- Raises
RequiredKeyNotFound – When the question is missing required keys.
InvalidArgument – When the provided questions argument is not a type of
list
nordictionary
.
- Return type
Dict[Union[str, int], Optional[Union[str, bool, List[Any]]]]
Examples
>>> from InquirerPy import prompt >>> from InquirerPy.validator import NumberValidator >>> questions = [ ... { ... "type": "input", ... "message": "Enter your age:", ... "validate": NumberValidator(), ... "invalid_message": "Input should be number.", ... "default": "18", ... "name": "age", ... "filter": lambda result: int(result), ... "transformer": lambda result: "Adult" if int(result) >= 18 else "Youth", ... }, ... { ... "type": "rawlist", ... "message": "What drinks would you like to buy:", ... "default": 2, ... "choices": lambda result: ["Soda", "Cidr", "Water", "Milk"] ... if result["age"] < 18 ... else ["Wine", "Beer"], ... "name": "drink", ... }, ... { ... "type": "list", ... "message": "Would you like a bag:", ... "choices": ["Yes", "No"], ... "when": lambda result: result["drink"] in {"Wine", "Beer"}, ... }, ... {"type": "confirm", "message": "Confirm?", "default": True}, ... ] >>> result = prompt(questions=questions)
- async InquirerPy.resolver.prompt_async(questions, style=None, vi_mode=False, raise_keyboard_interrupt=True, keybindings=None, style_override=True)[source]¶
Classic syntax entrypoint to create a prompt session via asynchronous method.
Refer to
InquirerPy.resolver.prompt()
for detailed documentations.
input¶
Module contains the class to create an input prompt.
- class InquirerPy.prompts.input.InputPrompt(message, style=None, vi_mode=False, default='', qmark='?', amark='?', instruction='', long_instruction='', completer=None, multicolumn_complete=False, multiline=False, validate=None, invalid_message='Invalid input', transformer=None, filter=None, keybindings=None, wrap_lines=True, raise_keyboard_interrupt=True, is_password=False, mandatory=True, mandatory_message='Mandatory prompt', session_result=None, input=None, output=None)[source]¶
Create a text prompt that accepts user input.
A wrapper class around
PromptSession
.- Parameters
message (Union[str, Callable[[InquirerPySessionResult], str]]) – The question to ask the user. Refer to message documentation for more details.
style (Optional[InquirerPy.utils.InquirerPyStyle]) – An
InquirerPyStyle
instance. Refer to Style documentation for more details.vi_mode (bool) – Use vim keybinding for the prompt. Refer to keybindings documentation for more details.
default (Union[Any, Callable[[InquirerPySessionResult], Any]]) – Set the default text value of the prompt. Refer to default documentation for more details.
qmark (str) – Question mark symbol. Custom symbol that will be displayed infront of the question before its answered.
amark (str) – Answer mark symbol. Custom symbol that will be displayed infront of the question after its answered.
instruction (str) – Short instruction to display next to the question.
long_instruction (str) – Long instructions to display at the bottom of the prompt.
completer (Optional[Union[Dict[str, Optional[str]], Completer]]) – Add auto completion to the prompt. Refer to Auto Completion documentation for more details.
multicolumn_complete (bool) – Change the auto-completion UI to a multi column display.
multiline (bool) – Enable multiline edit. While multiline edit is active, pressing enter won’t complete the answer. and will create a new line. Use esc followd by enter to complete the question.
validate (Optional[Union[Callable[[Any], bool], Validator]]) – Add validation to user input. Refer to Validator documentation for more details.
invalid_message (str) – Error message to display when user input is invalid. Refer to Validator documentation for more details.
transformer (Optional[Callable[[str], Any]]) – A function which performs additional transformation on the value that gets printed to the terminal. Different than filter parameter, this is only visual effect and won’t affect the actual value returned by
execute()
. Refer to transformer documentation for more details.filter (Optional[Callable[[str], Any]]) – A function which performs additional transformation on the result. This affects the actual value returned by
execute()
. Refer to filter documentation for more details.keybindings (Optional[Dict[str, List[Dict[str, Union[str, FilterOrBool, List[str]]]]]]) – Customise the builtin keybindings. Refer to keybindings for more details.
wrap_lines (bool) – Soft wrap question lines when question exceeds the terminal width.
raise_keyboard_interrupt (bool) – Raise the
KeyboardInterrupt
exception when ctrl-c is pressed. If false, the result will be None and the question is skiped.is_password (bool) – Used internally for
SecretPrompt
.mandatory (bool) – Indicate if the prompt is mandatory. If True, then the question cannot be skipped.
mandatory_message (str) – Error message to show when user attempts to skip mandatory prompt.
session_result (Optional[Dict[Union[str, int], Optional[Union[str, bool, List[Any]]]]]) – Used internally for Classic Syntax (PyInquirer).
input (Optional[Input]) – Used internally and will be removed in future updates.
output (Optional[Output]) – Used internally and will be removed in future updates.
- Return type
None
Examples
>>> from InquirerPy import inquirer >>> result = inquirer.text(message="Enter your name:").execute() >>> print(f"Name: {result}") Name: Michael
secret¶
Module contains the class to create a secret prompt.
- class InquirerPy.prompts.secret.SecretPrompt(message, style=None, default='', qmark='?', amark='?', instruction='', long_instruction='', vi_mode=False, validate=None, invalid_message='Invalid input', transformer=None, filter=None, keybindings=None, wrap_lines=True, raise_keyboard_interrupt=True, mandatory=True, mandatory_message='Mandatory prompt', session_result=None, input=None, output=None)[source]¶
Create a text prompt which transforms the input to asterisks while typing.
A wrapper class around
PromptSession
.- Parameters
message (Union[str, Callable[[InquirerPySessionResult], str]]) – The question to ask the user. Refer to message documentation for more details.
style (Optional[InquirerPy.utils.InquirerPyStyle]) – An
InquirerPyStyle
instance. Refer to Style documentation for more details.vi_mode (bool) – Use vim keybinding for the prompt. Refer to keybindings documentation for more details.
default (Union[Any, Callable[[InquirerPySessionResult], Any]]) – Set the default text value of the prompt. Refer to default documentation for more details.
qmark (str) – Question mark symbol. Custom symbol that will be displayed infront of the question before its answered.
amark (str) – Answer mark symbol. Custom symbol that will be displayed infront of the question after its answered.
instruction (str) – Short instruction to display next to the question.
long_instruction (str) – Long instructions to display at the bottom of the prompt.
validate (Optional[Union[Callable[[Any], bool], Validator]]) – Add validation to user input. Refer to Validator documentation for more details.
invalid_message (str) – Error message to display when user input is invalid. Refer to Validator documentation for more details.
transformer (Optional[Callable[[str], Any]]) – A function which performs additional transformation on the value that gets printed to the terminal. Different than filter parameter, this is only visual effect and won’t affect the actual value returned by
execute()
. Refer to transformer documentation for more details.filter (Optional[Callable[[str], Any]]) – A function which performs additional transformation on the result. This affects the actual value returned by
execute()
. Refer to filter documentation for more details.keybindings (Optional[Dict[str, List[Dict[str, Union[str, FilterOrBool, List[str]]]]]]) – Customise the builtin keybindings. Refer to keybindings for more details.
wrap_lines (bool) – Soft wrap question lines when question exceeds the terminal width.
raise_keyboard_interrupt (bool) – Raise the
KeyboardInterrupt
exception when ctrl-c is pressed. If false, the result will be None and the question is skiped.mandatory (bool) – Indicate if the prompt is mandatory. If True, then the question cannot be skipped.
mandatory_message (str) – Error message to show when user attempts to skip mandatory prompt.
session_result (Optional[Dict[Union[str, int], Optional[Union[str, bool, List[Any]]]]]) – Used internally for Classic Syntax (PyInquirer).
input (Optional[Input]) – Used internally and will be removed in future updates.
output (Optional[Output]) – Used internally and will be removed in future updates.
- Return type
None
Examples
>>> from InquirerPy import inquirer >>> result = inquirer.secret(message="Password:").execute() >>> print(f"Password: {result}") Password: asdf123
filepath¶
Module contains the class to create filepath prompt and filepath completer class.
- class InquirerPy.prompts.filepath.FilePathPrompt(message, style=None, vi_mode=False, default='', qmark='?', amark='?', instruction='', long_instruction='', multicolumn_complete=False, validate=None, invalid_message='Invalid input', only_directories=False, only_files=False, transformer=None, filter=None, keybindings=None, wrap_lines=True, raise_keyboard_interrupt=True, mandatory=True, mandatory_message='Mandatory prompt', session_result=None, input=None, output=None)[source]¶
Create a prompt that provides auto completion for system filepaths.
A wrapper class around
PromptSession
.- Parameters
message (Union[str, Callable[[InquirerPySessionResult], str]]) – The question to ask the user. Refer to message documentation for more details.
style (Optional[InquirerPy.utils.InquirerPyStyle]) – An
InquirerPyStyle
instance. Refer to Style documentation for more details.vi_mode (bool) – Use vim keybinding for the prompt. Refer to keybindings documentation for more details.
default (Union[Any, Callable[[InquirerPySessionResult], Any]]) – Set the default text value of the prompt. Refer to default documentation for more details.
qmark (str) – Question mark symbol. Custom symbol that will be displayed infront of the question before its answered.
amark (str) – Answer mark symbol. Custom symbol that will be displayed infront of the question after its answered.
instruction (str) – Short instruction to display next to the question.
long_instruction (str) – Long instructions to display at the bottom of the prompt.
multicolumn_complete (bool) – Change the auto-completion UI to a multi column display.
validate (Optional[Union[Callable[[Any], bool], Validator]]) – Add validation to user input. Refer to Validator documentation for more details.
invalid_message (str) – Error message to display when user input is invalid. Refer to Validator documentation for more details.
transformer (Optional[Callable[[str], Any]]) – A function which performs additional transformation on the value that gets printed to the terminal. Different than filter parameter, this is only visual effect and won’t affect the actual value returned by
execute()
. Refer to transformer documentation for more details.filter (Optional[Callable[[str], Any]]) – A function which performs additional transformation on the result. This affects the actual value returned by
execute()
. Refer to filter documentation for more details.keybindings (Optional[Dict[str, List[Dict[str, Union[str, FilterOrBool, List[str]]]]]]) – Customise the builtin keybindings. Refer to keybindings for more details.
wrap_lines (bool) – Soft wrap question lines when question exceeds the terminal width.
only_directories (bool) – Only complete directories.
only_files (bool) – Only complete files.
raise_keyboard_interrupt (bool) – Raise the
KeyboardInterrupt
exception when ctrl-c is pressed. If false, the result will be None and the question is skiped.mandatory (bool) – Indicate if the prompt is mandatory. If True, then the question cannot be skipped.
mandatory_message (str) – Error message to show when user attempts to skip mandatory prompt.
session_result (Optional[Dict[Union[str, int], Optional[Union[str, bool, List[Any]]]]]) – Used internally for Classic Syntax (PyInquirer).
input (Optional[Input]) – Used internally and will be removed in future updates.
output (Optional[Output]) – Used internally and will be removed in future updates.
- Return type
None
Examples
>>> from InquirerPy import inquirer >>> result = inquirer.filepath(message="Enter a path:").execute() >>> print(result) /home/ubuntu/README.md
- class InquirerPy.prompts.filepath.FilePathCompleter(only_directories=False, only_files=False)[source]¶
An auto completion class which generates system filepath.
See also
- Parameters
- get_completions(document, complete_event)[source]¶
Get a list of valid system paths.
- Return type
Generator[prompt_toolkit.completion.base.Completion, None, None]
confirm¶
Module contains the class to create a confirm prompt.
- class InquirerPy.prompts.confirm.ConfirmPrompt(message, style=None, default=False, vi_mode=False, qmark='?', amark='?', instruction='', long_instruction='', transformer=None, filter=None, keybindings=None, wrap_lines=True, confirm_letter='y', reject_letter='n', raise_keyboard_interrupt=True, mandatory=True, mandatory_message='Mandatory prompt', session_result=None, input=None, output=None)[source]¶
Create a prompt that provides 2 options (confirm/deny) and controlled via single keypress.
A wrapper class around
PromptSession
.- Parameters
message (Union[str, Callable[[InquirerPySessionResult], str]]) – The question to ask the user. Refer to message documentation for more details.
style (Optional[InquirerPy.utils.InquirerPyStyle]) – An
InquirerPyStyle
instance. Refer to Style documentation for more details.vi_mode (bool) – Used for compatibility .
default (Union[Any, Callable[[InquirerPySessionResult], Any]]) – Set the default value of the prompt, should be either True or False. This affects the value returned when user directly hit enter key. Refer to default documentation for more details.
qmark (str) – Question mark symbol. Custom symbol that will be displayed infront of the question before its answered.
amark (str) – Answer mark symbol. Custom symbol that will be displayed infront of the question after its answered.
instruction (str) – Short instruction to display next to the question.
long_instruction (str) – Long instructions to display at the bottom of the prompt.
transformer (Optional[Callable[[bool], Any]]) – A function which performs additional transformation on the value that gets printed to the terminal. Different than filter parameter, this is only visual effect and won’t affect the actual value returned by
execute()
. Refer to transformer documentation for more details.filter (Optional[Callable[[bool], Any]]) – A function which performs additional transformation on the result. This affects the actual value returned by
execute()
. Refer to filter documentation for more details.keybindings (Optional[Dict[str, List[Dict[str, Union[str, FilterOrBool, List[str]]]]]]) – Customise the builtin keybindings. Refer to keybindings for more details.
wrap_lines (bool) – Soft wrap question lines when question exceeds the terminal width.
confirm_letter (str) – Letter used to confirm the prompt. A keybinding will be created for this letter. Default is y and pressing y will answer the prompt with value True.
reject_letter (str) – Letter used to reject the prompt. A keybinding will be created for this letter. Default is n and pressing n will answer the prompt with value False.
raise_keyboard_interrupt (bool) – Raise the
KeyboardInterrupt
exception when ctrl-c is pressed. If false, the result will be None and the question is skiped.mandatory (bool) – Indicate if the prompt is mandatory. If True, then the question cannot be skipped.
mandatory_message (str) – Error message to show when user attempts to skip mandatory prompt.
session_result (Optional[Dict[Union[str, int], Optional[Union[str, bool, List[Any]]]]]) – Used internally for Classic Syntax (PyInquirer).
input (Optional[Input]) – Used internally and will be removed in future updates.
output (Optional[Output]) – Used internally and will be removed in future updates.
- Return type
None
Examples
>>> from InquirerPy import inquirer >>> result = inquirer.confirm(message="Confirm?").execute() >>> print(result) True
list¶
Module contains the class to create a list prompt.
- class InquirerPy.prompts.list.ListPrompt(message, choices, default=None, style=None, vi_mode=False, qmark='?', amark='?', pointer='❯', instruction='', long_instruction='', transformer=None, filter=None, height=None, max_height=None, multiselect=False, marker='❯', marker_pl=' ', border=False, validate=None, invalid_message='Invalid input', keybindings=None, show_cursor=True, cycle=True, wrap_lines=True, raise_keyboard_interrupt=True, mandatory=True, mandatory_message='Mandatory prompt', session_result=None)[source]¶
Create a prompt that displays a list of choices to select.
A wrapper class around
Application
.- Parameters
message (Union[str, Callable[[InquirerPySessionResult], str]]) – The question to ask the user. Refer to message documentation for more details.
choices (Union[Callable[[InquirerPySessionResult], Union[List[Any], List[Choice], List[Dict[str, Any]]]], List[Any], List[Choice], List[Dict[str, Any]]]) – List of choices to display and select. Refer to choices documentation for more details.
style (Optional[InquirerPy.utils.InquirerPyStyle]) – An
InquirerPyStyle
instance. Refer to Style documentation for more details.vi_mode (bool) – Use vim keybinding for the prompt. Refer to keybindings documentation for more details.
default (Union[Any, Callable[[InquirerPySessionResult], Any]]) – Set the default value of the prompt. This will be used to determine which choice is highlighted (current selection), The default value should be the value of one of the choices. Refer to default documentation for more details.
qmark (str) – Question mark symbol. Custom symbol that will be displayed infront of the question before its answered.
amark (str) – Answer mark symbol. Custom symbol that will be displayed infront of the question after its answered.
pointer (str) – Pointer symbol. Customer symbol that will be used to indicate the current choice selection.
instruction (str) – Short instruction to display next to the question.
long_instruction (str) – Long instructions to display at the bottom of the prompt.
validate (Optional[Union[Callable[[Any], bool], Validator]]) – Add validation to user input. The main use case for this prompt would be when multiselect is True, you can enforce a min/max selection. Refer to Validator documentation for more details.
invalid_message (str) – Error message to display when user input is invalid. Refer to Validator documentation for more details.
transformer (Optional[Callable[[Any], Any]]) – A function which performs additional transformation on the value that gets printed to the terminal. Different than filter parameter, this is only visual effect and won’t affect the actual value returned by
execute()
. Refer to transformer documentation for more details.filter (Optional[Callable[[Any], Any]]) – A function which performs additional transformation on the result. This affects the actual value returned by
execute()
. Refer to filter documentation for more details.height (Optional[Union[int, str]]) – Preferred height of the prompt. Refer to height documentation for more details.
max_height (Optional[Union[int, str]]) – Max height of the prompt. Refer to height documentation for more details.
multiselect (bool) – Enable multi-selection on choices. You can use validate parameter to control min/max selections. Setting to True will also change the result from a single value to a list of values.
marker (str) – Marker Symbol. Custom symbol to indicate if a choice is selected. This will take effects when multiselect is True.
marker_pl (str) – Marker place holder when the choice is not selected. This is empty space by default.
border (bool) – Create border around the choice window.
keybindings (Optional[Dict[str, List[Dict[str, Union[str, FilterOrBool, List[str]]]]]]) – Customise the builtin keybindings. Refer to keybindings for more details.
show_cursor (bool) – Display cursor at the end of the prompt. Set to False to hide the cursor.
cycle (bool) – Return to top item if hit bottom during navigation or vice versa.
wrap_lines (bool) – Soft wrap question lines when question exceeds the terminal width.
raise_keyboard_interrupt (bool) – Raise the
KeyboardInterrupt
exception when ctrl-c is pressed. If false, the result will be None and the question is skiped.mandatory (bool) – Indicate if the prompt is mandatory. If True, then the question cannot be skipped.
mandatory_message (str) – Error message to show when user attempts to skip mandatory prompt.
session_result (Optional[Dict[Union[str, int], Optional[Union[str, bool, List[Any]]]]]) – Used internally for Classic Syntax (PyInquirer).
- Return type
None
Examples
>>> from InquirerPy import inquirer >>> result = inquirer.select(message="Select one:", choices=[1, 2, 3]).execute() >>> print(result) 1
rawlist¶
Module contains the class to create a rawlist prompt.
- class InquirerPy.prompts.rawlist.RawlistPrompt(message, choices, default=None, separator=') ', style=None, vi_mode=False, qmark='?', amark='?', pointer=' ', instruction='', long_instruction='', transformer=None, filter=None, height=None, max_height=None, multiselect=False, marker='❯', marker_pl=' ', border=False, validate=None, invalid_message='Invalid input', keybindings=None, show_cursor=True, cycle=True, wrap_lines=True, raise_keyboard_interrupt=True, mandatory=True, mandatory_message='Mandatory prompt', session_result=None)[source]¶
Create a prompt that displays a list of choices with index number as shortcuts.
A wrapper class around
Application
.Each choice will have an index number infront of them with keybinding created for that index number. Enables user to use number to jump to different choices using number.
- Parameters
message (Union[str, Callable[[InquirerPySessionResult], str]]) – The question to ask the user. Refer to message documentation for more details.
choices (Union[Callable[[InquirerPySessionResult], Union[List[Any], List[Choice], List[Dict[str, Any]]]], List[Any], List[Choice], List[Dict[str, Any]]]) – List of choices to display and select. Refer to Choices documentation for more details.
style (Optional[InquirerPy.utils.InquirerPyStyle]) – An
InquirerPyStyle
instance. Refer to Style documentation for more details.vi_mode (bool) – Use vim keybinding for the prompt. Refer to keybindings documentation for more details.
default (Union[Any, Callable[[InquirerPySessionResult], Any]]) – Set the default value of the prompt. This will be used to determine which choice is highlighted (current selection), The default value should be the value of one of the choices. For
RawlistPrompt
specifically, default value can also be value between 0-9. Refer to default documentation for more details.separator (str) – Separator symbol. Custom symbol that will be used as a separator between the choice index number and the choices.
qmark (str) – Question mark symbol. Custom symbol that will be displayed infront of the question before its answered.
amark (str) – Answer mark symbol. Custom symbol that will be displayed infront of the question after its answered.
pointer (str) – Pointer symbol. Customer symbol that will be used to indicate the current choice selection.
instruction (str) – Short instruction to display next to the question.
long_instruction (str) – Long instructions to display at the bottom of the prompt.
validate (Optional[Union[Callable[[Any], bool], Validator]]) – Add validation to user input. The main use case for this prompt would be when multiselect is True, you can enforce a min/max selection. Refer to Validator documentation for more details.
invalid_message (str) – Error message to display when user input is invalid. Refer to Validator documentation for more details.
transformer (Optional[Callable[[Any], Any]]) – A function which performs additional transformation on the value that gets printed to the terminal. Different than filter parameter, this is only visual effect and won’t affect the actual value returned by
execute()
. Refer to transformer documentation for more details.filter (Optional[Callable[[Any], Any]]) – A function which performs additional transformation on the result. This affects the actual value returned by
execute()
. Refer to filter documentation for more details.height (Optional[Union[int, str]]) – Preferred height of the prompt. Refer to height documentation for more details.
max_height (Optional[Union[int, str]]) – Max height of the prompt. Refer to height documentation for more details.
multiselect (bool) – Enable multi-selection on choices. You can use validate parameter to control min/max selections. Setting to True will also change the result from a single value to a list of values.
marker (str) – Marker Symbol. Custom symbol to indicate if a choice is selected. This will take effects when multiselect is True.
marker_pl (str) – Marker place holder when the choice is not selected. This is empty space by default.
border (bool) – Create border around the choice window.
keybindings (Optional[Dict[str, List[Dict[str, Union[str, FilterOrBool, List[str]]]]]]) – Customise the builtin keybindings. Refer to keybindings for more details.
show_cursor (bool) – Display cursor at the end of the prompt. Set to False to hide the cursor.
cycle (bool) – Return to top item if hit bottom during navigation or vice versa.
wrap_lines (bool) – Soft wrap question lines when question exceeds the terminal width.
raise_keyboard_interrupt (bool) – Raise the
KeyboardInterrupt
exception when ctrl-c is pressed. If false, the result will be None and the question is skiped.mandatory (bool) – Indicate if the prompt is mandatory. If True, then the question cannot be skipped.
mandatory_message (str) – Error message to show when user attempts to skip mandatory prompt.
session_result (Optional[Dict[Union[str, int], Optional[Union[str, bool, List[Any]]]]]) – Used internally for Classic Syntax (PyInquirer).
- Return type
None
Examples
>>> from InquirerPy import inquirer >>> result = inquirer.rawlist(message="Select one:", choices=[1, 2, 3]).execute() >>> print(result) 1
expand¶
Module contains the class to create an expand prompt.
- class InquirerPy.prompts.expand.ExpandPrompt(message, choices, default='', style=None, vi_mode=False, qmark='?', amark='?', pointer=' ', separator=') ', help_msg='Help, list all choices', expand_help=None, expand_pointer='❯ ', instruction='', long_instruction='', transformer=None, filter=None, height=None, max_height=None, multiselect=False, marker='❯', marker_pl=' ', border=False, validate=None, invalid_message='Invalid input', keybindings=None, show_cursor=True, cycle=True, wrap_lines=True, raise_keyboard_interrupt=True, mandatory=True, mandatory_message='Mandatory prompt', session_result=None)[source]¶
Create a compact prompt with the ability to expand.
A wrapper class around
Application
.Contains a list of chocies binded to a shortcut letter. The prompt can be expanded using h key.
- Parameters
message (Union[str, Callable[[InquirerPySessionResult], str]]) – The question to ask the user. Refer to message documentation for more details.
choices (Union[Callable[[InquirerPySessionResult], Union[List[Any], List[Choice], List[Dict[str, Any]]]], List[Any], List[Choice], List[Dict[str, Any]]]) – List of choices to display and select. Refer to Choices documentation for more details.
style (Optional[InquirerPy.utils.InquirerPyStyle]) – An
InquirerPyStyle
instance. Refer to Style documentation for more details.vi_mode (bool) – Use vim keybinding for the prompt. Refer to keybindings documentation for more details.
default (Union[Any, Callable[[InquirerPySessionResult], Any]]) – Set the default value of the prompt. This will be used to determine which choice is highlighted (current selection), The default value should the value of one of the choices. For
ExpandPrompt
specifically, default value can also be a choice[“key”] which is the shortcut key for the choice. Refer to default documentation for more details.separator (str) – Separator symbol. Custom symbol that will be used as a separator between the choice index number and the choices.
help_msg (str) – This parameter is DEPRECATED. Use expand_help instead.
expand_help (Optional[InquirerPy.prompts.expand.ExpandHelp]) – The help configuration for the prompt. Must be an instance of
ExpandHelp
. If this value is None, the default help key will be binded to h and the default help message would be “Help, List all choices.”expand_pointer (str) – Pointer symbol before prompt expansion. Custom symbol that will be displayed to indicate the prompt is not expanded.
qmark (str) – Question mark symbol. Custom symbol that will be displayed infront of the question before its answered.
amark (str) – Answer mark symbol. Custom symbol that will be displayed infront of the question after its answered.
pointer (str) – Pointer symbol. Customer symbol that will be used to indicate the current choice selection.
instruction (str) – Short instruction to display next to the question.
long_instruction (str) – Long instructions to display at the bottom of the prompt.
validate (Optional[Union[Callable[[Any], bool], Validator]]) – Add validation to user input. The main use case for this prompt would be when multiselect is True, you can enforce a min/max selection. Refer to Validator documentation for more details.
invalid_message (str) – Error message to display when user input is invalid. Refer to Validator documentation for more details.
transformer (Optional[Callable[[Any], Any]]) – A function which performs additional transformation on the value that gets printed to the terminal. Different than filter parameter, this is only visual effect and won’t affect the actual value returned by
execute()
. Refer to transformer documentation for more details.filter (Optional[Callable[[Any], Any]]) – A function which performs additional transformation on the result. This affects the actual value returned by
execute()
. Refer to filter documentation for more details.height (Optional[Union[int, str]]) – Preferred height of the prompt. Refer to height documentation for more details.
max_height (Optional[Union[int, str]]) – Max height of the prompt. Refer to height documentation for more details.
multiselect (bool) – Enable multi-selection on choices. You can use validate parameter to control min/max selections. Setting to True will also change the result from a single value to a list of values.
marker (str) – Marker Symbol. Custom symbol to indicate if a choice is selected. This will take effects when multiselect is True.
marker_pl (str) – Marker place holder when the choice is not selected. This is empty space by default.
border (bool) – Create border around the choice window.
keybindings (Optional[Dict[str, List[Dict[str, Union[str, FilterOrBool, List[str]]]]]]) – Customise the builtin keybindings. Refer to keybindings for more details.
show_cursor (bool) – Display cursor at the end of the prompt. Set to False to hide the cursor.
cycle (bool) – Return to top item if hit bottom during navigation or vice versa.
wrap_lines (bool) – Soft wrap question lines when question exceeds the terminal width.
raise_keyboard_interrupt (bool) – Raise the
KeyboardInterrupt
exception when ctrl-c is pressed. If false, the result will be None and the question is skiped.mandatory (bool) – Indicate if the prompt is mandatory. If True, then the question cannot be skipped.
mandatory_message (str) – Error message to show when user attempts to skip mandatory prompt.
session_result (Optional[Dict[Union[str, int], Optional[Union[str, bool, List[Any]]]]]) – Used internally for Classic Syntax (PyInquirer).
- Return type
None
Examples
>>> from InquirerPy import inquirer >>> result = inquirer.expand(message="Select one:", choices[{"name": "1", "value": "1", "key": "a"}]).execute() >>> print(result) "1"
- class InquirerPy.prompts.expand.ExpandHelp(key='h', message='Help, list all choices')[source]¶
Help choice for the
ExpandPrompt
.
- class InquirerPy.prompts.expand.ExpandChoice(value, name=None, enabled=False, key=None)[source]¶
Choice class for
ExpandPrompt
.See also
- Parameters
value (Any) – The value of the choice when user selects this choice.
name (Optional[str]) – The value that should be presented to the user prior/after selection of the choice. This value is optional, if not provided, it will fallback to the string representation of value.
enabled (bool) – Indicates if the choice should be pre-selected. This only has effects when the prompt has multiselect enabled.
key (Optional[str]) – Char to bind to the choice. Pressing this value will jump to the choice, If this value is missing, the first char of the str(value) will be used as the key.
- Return type
None
checkbox¶
Module contains the class to create a checkbox prompt.
- class InquirerPy.prompts.checkbox.CheckboxPrompt(message, choices, default=None, style=None, vi_mode=False, qmark='?', amark='?', pointer='❯', enabled_symbol='◉', disabled_symbol='○', border=False, instruction='', long_instruction='', transformer=None, filter=None, height=None, max_height=None, validate=None, invalid_message='Invalid input', keybindings=None, show_cursor=True, cycle=True, wrap_lines=True, raise_keyboard_interrupt=True, mandatory=True, mandatory_message='Mandatory prompt', session_result=None)[source]¶
Create a prompt which displays a list of checkboxes to toggle.
A wrapper class around
Application
.User can toggle on/off on each checkbox.
Works very similar to
ListPrompt
with multiselect enabled, the main difference is visual/UI and also when not toggling anything, the result will be empty.- Parameters
message (Union[str, Callable[[InquirerPySessionResult], str]]) – The question to ask the user. Refer to message documentation for more details.
choices (Union[Callable[[InquirerPySessionResult], Union[List[Any], List[Choice], List[Dict[str, Any]]]], List[Any], List[Choice], List[Dict[str, Any]]]) – List of choices to display and select. Refer to choices documentation for more details.
style (Optional[InquirerPy.utils.InquirerPyStyle]) – An
InquirerPyStyle
instance. Refer to Style documentation for more details.vi_mode (bool) – Use vim keybinding for the prompt. Refer to keybindings documentation for more details.
default (Any) – Set the default value of the prompt. This will be used to determine which choice is highlighted (current selection), The default value should be the value of one of the choices. Refer to default documentation for more details.
separator – Separator symbol. Custom symbol that will be used as a separator between the choice index number and the choices.
qmark (str) – Question mark symbol. Custom symbol that will be displayed infront of the question before its answered.
amark (str) – Answer mark symbol. Custom symbol that will be displayed infront of the question after its answered.
pointer (str) – Pointer symbol. Customer symbol that will be used to indicate the current choice selection.
enabled_symbol (str) – Checkbox ticked symbol. Custom symbol which indicate the checkbox is ticked.
disabled_symbol (str) – Checkbox not ticked symbol. Custom symbol which indicate the checkbox is not ticked.
instruction (str) – Short instruction to display next to the question.
long_instruction (str) – Long instructions to display at the bottom of the prompt.
validate (Optional[Union[Callable[[Any], bool], Validator]]) – Add validation to user input. The main use case for this prompt would be when multiselect is True, you can enforce a min/max selection. Refer to Validator documentation for more details.
invalid_message (str) – Error message to display when user input is invalid. Refer to Validator documentation for more details.
transformer (Optional[Callable[[Any], Any]]) – A function which performs additional transformation on the value that gets printed to the terminal. Different than filter parameter, this is only visual effect and won’t affect the actual value returned by
execute()
. Refer to transformer documentation for more details.filter (Optional[Callable[[Any], Any]]) – A function which performs additional transformation on the result. This affects the actual value returned by
execute()
. Refer to filter documentation for more details.height (Optional[Union[int, str]]) – Preferred height of the prompt. Refer to height documentation for more details.
max_height (Optional[Union[int, str]]) – Max height of the prompt. Refer to height documentation for more details.
border (bool) – Create border around the choice window.
keybindings (Optional[Dict[str, List[Dict[str, Union[str, FilterOrBool, List[str]]]]]]) – Customise the builtin keybindings. Refer to keybindings for more details.
show_cursor (bool) – Display cursor at the end of the prompt. Set to False to hide the cursor.
cycle (bool) – Return to top item if hit bottom during navigation or vice versa.
wrap_lines (bool) – Soft wrap question lines when question exceeds the terminal width.
raise_keyboard_interrupt (bool) – Raise the
KeyboardInterrupt
exception when ctrl-c is pressed. If false, the result will be None and the question is skiped.mandatory (bool) – Indicate if the prompt is mandatory. If True, then the question cannot be skipped.
mandatory_message (str) – Error message to show when user attempts to skip mandatory prompt.
session_result (Optional[Dict[Union[str, int], Optional[Union[str, bool, List[Any]]]]]) – Used internally for Classic Syntax (PyInquirer).
- Return type
None
Examples
>>> from InquirerPy import inquirer >>> result = inquirer.checkbox(message="Select:", choices=[1, 2, 3]).execute() >>> print(result) [1]
fuzzy¶
Module contains the class to create a fuzzy prompt.
- class InquirerPy.prompts.fuzzy.FuzzyPrompt(message, choices, default='', pointer='❯', style=None, vi_mode=False, qmark='?', amark='?', transformer=None, filter=None, instruction='', long_instruction='', multiselect=False, prompt='❯', marker='❯', marker_pl=' ', border=False, info=True, match_exact=False, exact_symbol=' E', height=None, max_height=None, validate=None, invalid_message='Invalid input', keybindings=None, cycle=True, wrap_lines=True, raise_keyboard_interrupt=True, mandatory=True, mandatory_message='Mandatory prompt', session_result=None)[source]¶
Create a prompt that lists choices while also allowing fuzzy search like fzf.
A wrapper class around
Application
.Fuzzy search using
pfzy.match.fuzzy_match()
function.Override the default keybindings for up/down as j/k cannot be bind even if editing_mode is vim due to the input buffer.
- Parameters
message (Union[str, Callable[[InquirerPySessionResult], str]]) – The question to ask the user. Refer to message documentation for more details.
choices (Union[Callable[[InquirerPySessionResult], Union[List[Any], List[Choice], List[Dict[str, Any]]]], List[Any], List[Choice], List[Dict[str, Any]]]) – List of choices to display and select. Refer to choices documentation for more details.
style (Optional[InquirerPy.utils.InquirerPyStyle]) – An
InquirerPyStyle
instance. Refer to Style documentation for more details.vi_mode (bool) – Use vim keybinding for the prompt. Refer to keybindings documentation for more details.
default (Union[Any, Callable[[InquirerPySessionResult], Any]]) – Set the default value in the search buffer. Different than other list type prompts, the default parameter tries to replicate what fzf does and add the value in default to search buffer so it starts searching immediatelly. Refer to default documentation for more details.
qmark (str) – Question mark symbol. Custom symbol that will be displayed infront of the question before its answered.
amark (str) – Answer mark symbol. Custom symbol that will be displayed infront of the question after its answered.
pointer (str) – Pointer symbol. Customer symbol that will be used to indicate the current choice selection.
instruction (str) – Short instruction to display next to the question.
long_instruction (str) – Long instructions to display at the bottom of the prompt.
validate (Optional[Union[Callable[[Any], bool], Validator]]) – Add validation to user input. The main use case for this prompt would be when multiselect is True, you can enforce a min/max selection. Refer to Validator documentation for more details.
invalid_message (str) – Error message to display when user input is invalid. Refer to Validator documentation for more details.
transformer (Optional[Callable[[Any], Any]]) – A function which performs additional transformation on the value that gets printed to the terminal. Different than filter parameter, this is only visual effect and won’t affect the actual value returned by
execute()
. Refer to transformer documentation for more details.filter (Optional[Callable[[Any], Any]]) – A function which performs additional transformation on the result. This affects the actual value returned by
execute()
. Refer to filter documentation for more details.height (Optional[Union[int, str]]) – Preferred height of the prompt. Refer to height documentation for more details.
max_height (Optional[Union[int, str]]) – Max height of the prompt. Refer to height documentation for more details.
multiselect (bool) – Enable multi-selection on choices. You can use validate parameter to control min/max selections. Setting to True will also change the result from a single value to a list of values.
prompt (str) – Input prompt symbol. Custom symbol to display infront of the input buffer to indicate for input.
border (bool) – Create border around the choice window.
info (bool) – Display choice information similar to fzf –info=inline next to the prompt.
match_exact (bool) – Use exact sub-string match instead of using fzy fuzzy match algorithm.
exact_symbol (str) – Custom symbol to display in the info section when info=True.
marker (str) – Marker Symbol. Custom symbol to indicate if a choice is selected. This will take effects when multiselect is True.
marker_pl (str) – Marker place holder when the choice is not selected. This is empty space by default.
keybindings (Optional[Dict[str, List[Dict[str, Union[str, FilterOrBool, List[str]]]]]]) – Customise the builtin keybindings. Refer to keybindings for more details.
cycle (bool) – Return to top item if hit bottom during navigation or vice versa.
wrap_lines (bool) – Soft wrap question lines when question exceeds the terminal width.
raise_keyboard_interrupt (bool) – Raise the
KeyboardInterrupt
exception when ctrl-c is pressed. If false, the result will be None and the question is skiped.mandatory (bool) – Indicate if the prompt is mandatory. If True, then the question cannot be skipped.
mandatory_message (str) – Error message to show when user attempts to skip mandatory prompt.
session_result (Optional[Dict[Union[str, int], Optional[Union[str, bool, List[Any]]]]]) – Used internally for Classic Syntax (PyInquirer).
- Return type
None
Examples
>>> from InquirerPy import inquirer >>> result = inquirer.fuzzy(message="Select one:", choices=[1, 2, 3]).execute() >>> print(result) 1
- property content_control: InquirerPy.prompts.fuzzy.InquirerPyFuzzyControl¶
Override for type-hinting.
- Type
InquirerPyFuzzyControl
separator¶
Module contains the Separator
class.
- class InquirerPy.separator.Separator(line='---------------')[source]¶
A non selectable choice that can be used as part of the choices argument in list type prompts.
It can be used to create some visual separations between choices in list type prompts.
- Parameters
line (str) – Content to display as the separator.
- Return type
None
Example
>>> from InquirerPy import inquirer >>> choices = [1, 2, Separator(), 3] >>> inquirer.select(message="", choices=choices)
utils¶
Module contains shared utility functions and typing aliases.
- InquirerPy.utils.get_style(style=None, style_override=True)[source]¶
Obtain an
InquirerPyStyle
instance which can be consumed by the style parameter in prompts.Tip
This function supports ENV variables.
For all the color ENV variable names, refer to the ENV documentation.
Note
If no style is provided, then a default theme based on one dark color palette is applied.
Note
Priority: style parameter -> ENV variable -> default style
- Parameters
style (Optional[Dict[str, str]]) – The dictionary of style classes and their colors, If nothing is passed, the style will be resolved to the Default Style.
style_override (bool) – A boolean to determine if the supplied style parameter should be merged with the Default Style or override them. By default, the supplied style will overwrite the Default Style.
- Returns
An instance of
InquirerPyStyle
.- Return type
Examples
>>> from InquirerPy import get_style >>> from InquirerPy import inquirer >>> style = get_style({"questionmark": "#ffffff", "answer": "#000000"}, style_override=False) >>> result = inquirer.confirm(message="Confirm?", style=style).execute()
- InquirerPy.utils.calculate_height(height, max_height, height_offset=2)[source]¶
Calculate the height and max_height for the main question contents.
Tip
The parameter height/max_height can be specified by either a
string
orint
.- When height/max_height is
str
: It will set the height to a percentage based on the value provided. You can optionally add the ‘%’ sign which will be ignored while processing.
Example: “60%” or “60” (60% of the current terminal visible lines)
- When height/max_height is
int
: It will set the height to exact number of lines based on the value provided.
Example: 20 (20 lines in terminal)
Note
If max_height is not provided or is None, the default max_height will be configured to 70% for best visual presentation in the terminal.
- Parameters
- Returns
A
tuple
with the first value being the desired height and the second value being the maximum height.- Raises
InvalidArgument – The provided height/max_height is not able to to be converted to int.
- Return type
Examples
>>> calculate_height(height="60%", max_height="100%")
- When height/max_height is
- class InquirerPy.utils.InquirerPyStyle(dict)[source]¶
InquirerPy Style class.
Used as a helper class to enforce the method get_style to be used while also avoiding
dict
to be passed into prompts.Note
The class is an instance of
typing.NamedTuple
.Warning
You should not directly be using this class besides for type hinting purposes. Obtain an instance of this class using
get_style()
.
- InquirerPy.utils.patched_print(*values)[source]¶
Patched
print()
that can print values without interrupting the prompt.See also
- Parameters
*values – Refer to
print()
.- Return type
None
Examples
>>> patched_print("Hello World")
- InquirerPy.utils.color_print(formatted_text, style=None)[source]¶
Print colored text leveraging
print_formatted_text()
.This function automatically handles printing the text without interrupting the current prompt.
- Parameters
- Return type
None
Example
>>> color_print(formatted_text=[("class:aa", "hello "), ("class:bb", "world")], style={"aa": "red", "bb": "blue"}) >>> color_print([("red", "yes"), ("", " "), ("blue", "no")])
validator¶
Module contains pre-built validators.
- class InquirerPy.validator.PathValidator(message='Input is not a valid path', is_file=False, is_dir=False)[source]¶
Validator
to validate if input is a valid filepath on the system.- Parameters
- Return type
None
- validate(document)[source]¶
Check if user input is a filepath that exists on the system based on conditions.
This method is used internally by prompt_toolkit.
- Return type
None
- class InquirerPy.validator.EmptyInputValidator(message='Input cannot be empty')[source]¶
Validator
to validate if the input is empty.- Parameters
message (str) – Error message to display in the validatation toolbar when validation failed.
- Return type
None
- validate(document)[source]¶
Check if user input is empty.
This method is used internally by prompt_toolkit.
- Return type
None
- class InquirerPy.validator.PasswordValidator(message='Input is not compliant with the password constraints', length=None, cap=False, special=False, number=False)[source]¶
Validator
to validate password compliance.- Parameters
message (str) – Error message to display in the validatation toolbar when validation failed.
length (Optional[int]) – The minimum length of the password.
cap (bool) – Password should include at least one capital letter.
special (bool) – Password should include at least one special char “@$!%*#?&”.
number (bool) – Password should include at least one number.
- Return type
None
- validate(document)[source]¶
Check if user input is compliant with the specified password constraints.
This method is used internally by prompt_toolkit.
- Return type
None
- class InquirerPy.validator.NumberValidator(message='Input should be a number', float_allowed=False)[source]¶
Validator
to validate if input is a number.- Parameters
- Return type
None
- validate(document)[source]¶
Check if user input is a valid number.
This method is used internally by prompt_toolkit.
- Return type
None
Containers¶
spinner¶
Module contains spinner related resources.
Note
The spinner is not a standalone spinner to run in the terminal
but rather a prompt_toolkit Window
that displays a spinner.
Use library such as yaspin if you need a plain spinner.
- class InquirerPy.containers.spinner.SPINNERS[source]¶
Presets of spinner patterns.
This only contains some basic ones thats ready to use. For more patterns, checkout the URL above.
Examples
>>> from InquirerPy import inquirer >>> from InquirerPy.spinner import SPINNERS >>> inquirer.select(message="", choices=lambda _: [1, 2, 3], spinner_pattern=SPINNERS.dots)
- class InquirerPy.containers.spinner.SpinnerWindow(loading, redraw, pattern=None, delay=0.1, text='')[source]¶
Conditional prompt_toolkit
Window
that displays a spinner.- Parameters
loading (Filter) – A
Condition
to indicate if the spinner should be visible.redraw (Callable[[], None]) – A redraw function (i.e.
invalidate()
) to refresh the UI.pattern (Optional[Union[List[str], InquirerPy.containers.spinner.SPINNERS]]) – List of pattern to display as the spinner.
delay (float) – Spinner refresh frequency.
text (str) – Loading text to display.
- Return type
None
message¶
Module contains the main message window Container
.
- class InquirerPy.containers.message.MessageWindow(message, filter, wrap_lines=True, show_cursor=True, **kwargs)[source]¶
Main window to display question to the user.
- Parameters
message (AnyFormattedText) – The message to display in the terminal.
filter (FilterOrBool) – Condition that this message window should be displayed. Use a loading condition to only display this window while its not loading.
wrap_lines (bool) – Enable line wrapping if the message is too long.
show_cursor (bool) – Display cursor.
- Return type
None
validation¶
Module contains ValidationWindow
which can be used to display error.
- class InquirerPy.containers.validation.ValidationWindow(invalid_message, filter, **kwargs)[source]¶
Conditional prompt_toolkit
Window
that displays error.- Parameters
invalid_message (Optional[Union[str, MagicFormattedText, List[Union[Tuple[str, str], Tuple[str, str, Callable[[prompt_toolkit.mouse_events.MouseEvent], None]]]], Callable[[], Any]]]) – Error message to display when error occured.
filter (Union[prompt_toolkit.filters.base.Filter, bool]) – Condition to display the error window.
- Return type
None
- class InquirerPy.containers.validation.ValidationFloat(invalid_message, filter, left=None, right=None, bottom=None, top=None, **kwargs)[source]¶
Float
wrapper aroundValidationWindow
.- Parameters
invalid_message (Optional[Union[str, MagicFormattedText, List[Union[Tuple[str, str], Tuple[str, str, Callable[[prompt_toolkit.mouse_events.MouseEvent], None]]]], Callable[[], Any]]]) – Error message to display when error occured.
filter (Union[prompt_toolkit.filters.base.Filter, bool]) – Condition to display the error window.
- Return type
None
instruction¶
Module contains InstructionWindow
which can be used to display long instructions.
- class InquirerPy.containers.instruction.InstructionWindow(message, filter, **kwargs)[source]¶
Conditional prompt_toolkit
Window
that displays long instructions.- Parameters
message (str) – Long instructions to display.
filter (FilterOrBool) – Condition to display the instruction window.
- Return type
None
base¶
simple¶
Contains the base class BaseSimplePrompt
.
- class InquirerPy.base.simple.BaseSimplePrompt(message, style=None, vi_mode=False, qmark='?', amark='?', instruction='', validate=None, invalid_message='Invalid input', transformer=None, filter=None, default='', wrap_lines=True, raise_keyboard_interrupt=True, mandatory=True, mandatory_message='Mandatory prompt', session_result=None)[source]¶
The base class to create a simple terminal input prompt.
Note
No actual
Application
is created by this class. This class only creates some common interface and attributes that can be easily used by prompt_toolkit.To have a functional prompt, you’ll at least have to implement the
BaseSimplePrompt._run()
andBaseSimplePrompt._get_prompt_message()
.See also
- Parameters
message (Union[str, Callable[[InquirerPySessionResult], str]]) –
style (Optional[InquirerPy.utils.InquirerPyStyle]) –
vi_mode (bool) –
qmark (str) –
amark (str) –
instruction (str) –
validate (Optional[Union[Callable[[Any], bool], Validator]]) –
invalid_message (str) –
default (Any) –
wrap_lines (bool) –
raise_keyboard_interrupt (bool) –
mandatory (bool) –
mandatory_message (str) –
session_result (Optional[Dict[Union[str, int], Optional[Union[str, bool, List[Any]]]]]) –
- Return type
None
- property status: Dict[str, Any]¶
Get current prompt status.
- The status contains 3 keys: “answered” and “result”.
answered: If the current prompt is answered. result: The result of the user answer. skipped: If the prompt is skipped.
- Type
Dict[str, Any]
- register_kb(*keys, filter=True, **kwargs)[source]¶
Keybinding registration decorator.
This decorator wraps around the
prompt_toolkit.key_binding.KeyBindings.add()
with added feature to process alt realted keybindings.By default, prompt_toolkit doesn’t process alt related keybindings, it requires alt-ANY to escape + ANY.
- Parameters
keys (Union[prompt_toolkit.keys.Keys, str]) – The keys to bind that can trigger the function.
filter (Union[prompt_toolkit.filters.base.Filter, bool]) –
Condition
to indicate if this keybinding should be active.
- Returns
A decorator that should be applied to the function thats intended to be active when the keys are pressed.
- Return type
Callable[[Callable[[KeyPressEvent], Union[NotImplementedOrNone, Awaitable[NotImplementedOrNone]]]], Callable[[KeyPressEvent], Union[NotImplementedOrNone, Awaitable[NotImplementedOrNone]]]]
Examples
>>> @self.register_kb("alt-j") ... def test(event): ... pass
- execute(raise_keyboard_interrupt=None)[source]¶
Run the prompt and get the result.
- Parameters
raise_keyboard_interrupt (Optional[bool]) – Deprecated. Set this parameter on the prompt initialisation instead.
- Returns
Value of the user answer. Types varies depending on the prompt.
- Raises
KeyboardInterrupt – When ctrl-c is pressed and raise_keyboard_interrupt is True.
- Return type
- async execute_async()[source]¶
Run the prompt asynchronously and get the result.
- Returns
Value of the user answer. Types varies depending on the prompt.
- Raises
KeyboardInterrupt – When ctrl-c is pressed and raise_keyboard_interrupt is True.
- Return type
complex¶
Contains the interface class BaseComplexPrompt
for more complex prompts and the mocked document class FakeDocument
.
- class InquirerPy.base.complex.FakeDocument(text, cursor_position=0)[source]¶
A fake prompt_toolkit document class.
Work around to allow non-buffer type
UIControl
to useValidator
.
- class InquirerPy.base.complex.BaseComplexPrompt(message, style=None, border=False, vi_mode=False, qmark='?', amark='?', instruction='', long_instruction='', transformer=None, filter=None, validate=None, invalid_message='Invalid input', wrap_lines=True, raise_keyboard_interrupt=True, mandatory=True, mandatory_message='Mandatory prompt', session_result=None)[source]¶
A base class to create a more complex prompt that will involve
Application
.Note
This class does not create
Layout
norApplication
, it only contains the necessary attributes and helper functions to be consumed.Note
Use
BaseListPrompt
to create a complex list prompt which involves multiple choices. It has more methods and helper function implemented.See also
BaseListPrompt
FuzzyPrompt
- Parameters
message (Union[str, Callable[[Dict[Union[str, int], Optional[Union[str, bool, List[Any]]]]], str]]) –
style (Optional[InquirerPy.utils.InquirerPyStyle]) –
border (bool) –
vi_mode (bool) –
qmark (str) –
amark (str) –
instruction (str) –
long_instruction (str) –
validate (Optional[Union[Callable[[Any], bool], Validator]]) –
invalid_message (str) –
wrap_lines (bool) –
raise_keyboard_interrupt (bool) –
mandatory (bool) –
mandatory_message (str) –
session_result (Optional[Dict[Union[str, int], Optional[Union[str, bool, List[Any]]]]]) –
- Return type
None
- register_kb(*keys, filter=True)[source]¶
Decorate keybinding registration function.
Ensure that the invalid state is cleared on next keybinding entered.
- Parameters
keys (Union[prompt_toolkit.keys.Keys, str]) –
filter (Union[prompt_toolkit.filters.base.Filter, bool]) –
- Return type
Callable[[Callable[[KeyPressEvent], Union[NotImplementedOrNone, Awaitable[NotImplementedOrNone]]]], Callable[[KeyPressEvent], Union[NotImplementedOrNone, Awaitable[NotImplementedOrNone]]]]
- property application: prompt_toolkit.application.application.Application¶
Get the application.
BaseComplexPrompt
requiresBaseComplexPrompt._application
to be defined since this class doesn’t implementLayout
andApplication
.- Raises
NotImplementedError – When self._application is not defined.
- property extra_message_line_count: int¶
Get the extra lines created caused by line wrapping.
Minus 1 on the totoal message length as we only want the extra line. 24 // 24 will equal to 1 however we only want the value to be 1 when we have 25 char which will create an extra line.
- Type
list¶
Contains the base class BaseListPrompt
which can be used to create a prompt involving choices.
- class InquirerPy.base.list.BaseListPrompt(message, style=None, vi_mode=False, qmark='?', amark='?', instruction='', long_instruction='', border=False, transformer=None, filter=None, validate=None, invalid_message='Invalid input', multiselect=False, keybindings=None, cycle=True, wrap_lines=True, raise_keyboard_interrupt=True, mandatory=True, mandatory_message='Mandatory prompt', session_result=None)[source]¶
A base class to create a complex prompt involving choice selections (i.e. list) using prompt_toolkit Application.
Note
This class does not create
Layout
norApplication
, it only contains the necessary attributes and helper functions to be consumed.See also
- Parameters
message (Union[str, Callable[[InquirerPySessionResult], str]]) –
style (Optional[InquirerPy.utils.InquirerPyStyle]) –
vi_mode (bool) –
qmark (str) –
amark (str) –
instruction (str) –
long_instruction (str) –
border (bool) –
validate (Optional[Union[Callable[[Any], bool], Validator]]) –
invalid_message (str) –
multiselect (bool) –
keybindings (Optional[Dict[str, List[Dict[str, Union[str, FilterOrBool, List[str]]]]]]) –
cycle (bool) –
wrap_lines (bool) –
raise_keyboard_interrupt (bool) –
mandatory (bool) –
mandatory_message (str) –
session_result (Optional[Dict[Union[str, int], Optional[Union[str, bool, List[Any]]]]]) –
- Return type
None
- property content_control: InquirerPy.base.control.InquirerPyUIListControl¶
Get the content controller object.
Needs to be an instance of
InquirerPyUIListControl
.Each
BaseComplexPrompt
requires a content_control to display custom contents for the prompt.- Raises
NotImplementedError – When self._content_control is not found.
- property result_name: Any¶
Get the result value that should be printed to the terminal.
In multiselect scenario, return result as a list.
- property result_value: Any¶
Get the result value that should return to the user.
In multiselect scenario, return result as a list.
- property selected_choices: List[Any]¶
Get all user selected choices.
- Type
List[Any]
control¶
Contains the content control class InquirerPyUIListControl
.
- class InquirerPy.base.control.Choice(value, name=None, enabled=False)[source]¶
Class to create choices for list type prompts.
A simple dataclass that can be used as an alternate to using
dict
when working with choices.- Parameters
value (Any) – The value of the choice when user selects this choice.
name (Optional[str]) – The value that should be presented to the user prior/after selection of the choice. This value is optional, if not provided, it will fallback to the string representation of value.
enabled (bool) – Indicates if the choice should be pre-selected. This only has effects when the prompt has multiselect enabled.
- Return type
None
- class InquirerPy.base.control.InquirerPyUIListControl(choices, default=None, multiselect=False, session_result=None)[source]¶
A base class to create
UIControl
to display list type contents.- Parameters
choices (InquirerPyListChoices) – List of choices to display as the content. Can also be a callable or async callable that returns a list of choices.
default (Any) – Default value, this will affect the cursor position.
multiselect (bool) – Indicate if the current prompt has multiselect enabled.
session_result (Optional[Dict[Union[str, int], Optional[Union[str, bool, List[Any]]]]]) – Current session result.
- Return type
None
exceptions¶
Module contains exceptions that will be raised by InquirerPy.