Skip to content

select

Source

Hook for PyInquirer 'list' type prompts, a single selector that returns a string. Takes in two forms of choices inputs, list of string or list of maps with the key as the question and the value as the output. Source example

Inputs

Name Type Default Required Description
message str None False String message to show when prompting.
choices Union[List[str], List[dict]] True List of strings or dicts with keys as output and values as display.
index bool False True Boolean to return the index instead of the answer

Arguments

Position Argument Type
1 message str

Returns

Any

Examples

The basic versions of the select can be called in these ways

compact->: select "What do you want?" ['stuff','things']
expanded:
  ->: select
  choices:
    - stuff
    - things
? What do you want?  stuff
? expanded >>>  (Use arrow keys)
   stuff
  things

compact: stuff
expanded: things

Other versions can use custom prompts for the choices

selection:
  ->: checkbox
  message: What you do?
  checked: true
  choices:
    - I do stuff: stuff
    - I do things: things

? What you do?  (<up>, <down> to move, <space> to select, <a> to toggle, <i> to invert)
 ❯● I do stuff
  ● I do things

Can also take the APIs normal form

selection:
  ->: checkbox
  message: What you do?
  choices:
    - name: stuff
    - name: things
      checked: true

? What you do?  (<up>, <down> to move, <space> to select, <a> to toggle, <i> to invert)
 ❯○ stuff
  ● things