0
# Shortcuts
1
2
Simplified interface for single questions without creating question objects. These functions provide immediate input collection for quick interactions and scripting scenarios, returning the answer directly rather than requiring a prompt() call.
3
4
## Capabilities
5
6
### Text Input Shortcut
7
8
Quick text input function that immediately prompts for input and returns the result.
9
10
```python { .api }
11
def text(
12
message: str,
13
autocomplete: list | None = None,
14
render: ConsoleRender | None = None,
15
default: str | callable | None = None,
16
validate: callable | bool = True,
17
ignore: bool | callable = False,
18
show_default: bool = False,
19
hints: str | None = None,
20
other: bool = False
21
) -> str:
22
"""
23
Quick text input prompt.
24
25
Args:
26
message: Prompt message to display
27
autocomplete: List of completion options for tab completion
28
render: Custom render engine (defaults to ConsoleRender())
29
default: Default value (string, callable, or None)
30
validate: Validation function or boolean
31
ignore: Skip question if True or callable returns True
32
show_default: Display default value in prompt
33
hints: Help text to display
34
other: Allow "Other" option for custom input
35
36
Returns:
37
User's text input as string
38
"""
39
```
40
41
**Usage Examples:**
42
43
```python
44
import inquirer
45
46
# Simple text input
47
name = inquirer.text("What's your name?")
48
print(f"Hello, {name}!")
49
50
# With validation
51
def validate_length(answers, current):
52
if len(current) < 3:
53
raise inquirer.errors.ValidationError(current, reason="Minimum 3 characters")
54
return True
55
56
username = inquirer.text(
57
"Enter username (min 3 chars)",
58
default="user",
59
validate=validate_length
60
)
61
62
# With autocompletion
63
city = inquirer.text(
64
"Enter city",
65
autocomplete=['New York', 'Los Angeles', 'Chicago', 'Houston']
66
)
67
```
68
69
### Password Input Shortcut
70
71
Quick password input with masked display.
72
73
```python { .api }
74
def password(
75
message: str,
76
render: ConsoleRender | None = None,
77
echo: str = "*",
78
default: str | callable | None = None,
79
validate: callable | bool = True,
80
ignore: bool | callable = False,
81
show_default: bool = False,
82
hints: str | None = None,
83
other: bool = False
84
) -> str:
85
"""
86
Quick password input prompt with masked display.
87
88
Args:
89
message: Prompt message to display
90
render: Custom render engine (defaults to ConsoleRender())
91
echo: Character to display instead of actual input
92
default: Default value (string, callable, or None)
93
validate: Validation function or boolean
94
ignore: Skip question if True or callable returns True
95
show_default: Display default value in prompt
96
hints: Help text to display
97
other: Allow "Other" option for custom input
98
99
Returns:
100
User's password input as string
101
"""
102
```
103
104
**Usage Example:**
105
106
```python
107
# Basic password input
108
pwd = inquirer.password("Enter your password:")
109
110
# Custom echo character
111
secret = inquirer.password("Enter secret key:", echo="•")
112
```
113
114
### List Selection Shortcut
115
116
Quick single-choice selection from a list of options.
117
118
```python { .api }
119
def list_input(
120
message: str,
121
render: ConsoleRender | None = None,
122
choices: list | callable | None = None,
123
default: any = None,
124
validate: callable | bool = True,
125
ignore: bool | callable = False,
126
show_default: bool = False,
127
hints: str | None = None,
128
carousel: bool = False,
129
other: bool = False,
130
autocomplete: list | None = None
131
):
132
"""
133
Quick list selection prompt.
134
135
Args:
136
message: Prompt message to display
137
render: Custom render engine (defaults to ConsoleRender())
138
choices: List of options (strings, (tag, value) tuples, or callable)
139
default: Default selection (can be callable)
140
validate: Validation function or boolean
141
ignore: Skip question if True or callable returns True
142
show_default: Display default value in prompt
143
hints: Help text to display
144
carousel: Enable wraparound navigation at list ends
145
other: Allow "Other" option for custom input
146
autocomplete: Autocompletion options for filtering
147
148
Returns:
149
Selected choice value
150
"""
151
```
152
153
**Usage Examples:**
154
155
```python
156
# Simple list selection
157
color = inquirer.list_input(
158
"Pick a color",
159
choices=['Red', 'Green', 'Blue']
160
)
161
162
# With tagged values
163
size = inquirer.list_input(
164
"Select size",
165
choices=[
166
('Small (up to 10 items)', 'small'),
167
('Medium (up to 100 items)', 'medium'),
168
('Large (unlimited)', 'large')
169
],
170
default='medium'
171
)
172
173
# With carousel navigation
174
option = inquirer.list_input(
175
"Navigate options",
176
choices=['Option 1', 'Option 2', 'Option 3', 'Option 4'],
177
carousel=True # Wrap around at ends
178
)
179
```
180
181
### Checkbox Selection Shortcut
182
183
Quick multiple-choice selection with checkboxes.
184
185
```python { .api }
186
def checkbox(
187
message: str,
188
render: ConsoleRender | None = None,
189
choices: list | callable | None = None,
190
locked: list | None = None,
191
default: list | callable | None = None,
192
validate: callable | bool = True,
193
ignore: bool | callable = False,
194
show_default: bool = False,
195
hints: str | None = None,
196
carousel: bool = False,
197
other: bool = False,
198
autocomplete: list | None = None
199
) -> list:
200
"""
201
Quick checkbox selection prompt.
202
203
Args:
204
message: Prompt message to display
205
render: Custom render engine (defaults to ConsoleRender())
206
choices: List of options (strings, (tag, value) tuples, or callable)
207
locked: Choices that cannot be deselected (always checked)
208
default: Initially selected choices (list or callable)
209
validate: Validation function or boolean
210
ignore: Skip question if True or callable returns True
211
show_default: Display default value in prompt
212
hints: Help text to display
213
carousel: Enable wraparound navigation at list ends
214
other: Allow "Other" option for custom input
215
autocomplete: Autocompletion options for filtering
216
217
Returns:
218
List of selected choice values
219
"""
220
```
221
222
**Usage Examples:**
223
224
```python
225
# Basic multiple selection
226
features = inquirer.checkbox(
227
"Select features to enable",
228
choices=['Authentication', 'Database', 'Caching', 'Logging']
229
)
230
231
# With locked options and defaults
232
components = inquirer.checkbox(
233
"Select components",
234
choices=['Core', 'UI', 'API', 'Tests'],
235
locked=['Core'], # Cannot be deselected
236
default=['Core', 'UI']
237
)
238
239
# With validation
240
def validate_at_least_one(answers, current):
241
if not current:
242
raise inquirer.errors.ValidationError(current, reason="Select at least one option")
243
return True
244
245
selected = inquirer.checkbox(
246
"Choose services (minimum 1)",
247
choices=['Web Server', 'Database', 'Cache', 'Queue'],
248
validate=validate_at_least_one
249
)
250
```
251
252
### Confirmation Shortcut
253
254
Quick yes/no confirmation prompt.
255
256
```python { .api }
257
def confirm(
258
message: str,
259
render: ConsoleRender | None = None,
260
default: bool | callable = False,
261
validate: callable | bool = True,
262
ignore: bool | callable = False,
263
show_default: bool = False,
264
hints: str | None = None,
265
other: bool = False
266
) -> bool:
267
"""
268
Quick confirmation prompt.
269
270
Args:
271
message: Prompt message to display
272
render: Custom render engine (defaults to ConsoleRender())
273
default: Default boolean value (bool or callable)
274
validate: Validation function or boolean
275
ignore: Skip question if True or callable returns True
276
show_default: Display default value in prompt
277
hints: Help text to display
278
other: Allow "Other" option for custom input
279
280
Returns:
281
Boolean confirmation result
282
"""
283
```
284
285
**Usage Examples:**
286
287
```python
288
# Simple confirmation
289
proceed = inquirer.confirm("Do you want to continue?")
290
if proceed:
291
print("Continuing...")
292
293
# With default value
294
delete_files = inquirer.confirm(
295
"Delete all files? This cannot be undone!",
296
default=False # Default to "No" for destructive actions
297
)
298
299
# With validation
300
def confirm_understanding(answers, current):
301
if not current:
302
raise inquirer.errors.ValidationError(
303
current,
304
reason="You must confirm to proceed"
305
)
306
return True
307
308
understood = inquirer.confirm(
309
"I understand the risks and want to proceed",
310
validate=confirm_understanding
311
)
312
```
313
314
### Editor Input Shortcut
315
316
Quick multi-line text input using external editor.
317
318
```python { .api }
319
def editor(
320
message: str,
321
render: ConsoleRender | None = None,
322
default: str | callable | None = None,
323
validate: callable | bool = True,
324
ignore: bool | callable = False,
325
show_default: bool = False,
326
hints: str | None = None,
327
other: bool = False
328
) -> str:
329
"""
330
Quick editor input prompt using external editor.
331
332
Args:
333
message: Prompt message to display
334
render: Custom render engine (defaults to ConsoleRender())
335
default: Default text content (string, callable, or None)
336
validate: Validation function or boolean
337
ignore: Skip question if True or callable returns True
338
show_default: Display default value in prompt
339
hints: Help text to display
340
other: Allow "Other" option for custom input
341
342
Returns:
343
Multi-line text content from editor
344
"""
345
```
346
347
**Usage Examples:**
348
349
```python
350
# Basic editor input
351
description = inquirer.editor("Enter project description")
352
print("Description:", description)
353
354
# With default content
355
config = inquirer.editor(
356
"Edit configuration",
357
default="# Default configuration\nkey=value\n"
358
)
359
360
# The editor uses $VISUAL or $EDITOR environment variables,
361
# falling back to vim -> emacs -> nano based on availability
362
```
363
364
### Path Input Shortcut
365
366
Quick file or directory path input with validation.
367
368
```python { .api }
369
def path(
370
message: str,
371
render: ConsoleRender | None = None,
372
default: str | callable | None = None,
373
path_type: str = "any",
374
exists: bool | None = None,
375
validate: callable | bool = True,
376
ignore: bool | callable = False,
377
show_default: bool = False,
378
hints: str | None = None,
379
other: bool = False
380
) -> str:
381
"""
382
Quick path input prompt with validation.
383
384
Args:
385
message: Prompt message to display
386
render: Custom render engine (defaults to ConsoleRender())
387
default: Default path value (string, callable, or None)
388
path_type: Path type ("any", "file", "directory")
389
exists: Require path to exist (True), not exist (False), or ignore (None)
390
validate: Additional validation function or boolean
391
ignore: Skip question if True or callable returns True
392
show_default: Display default value in prompt
393
hints: Help text to display
394
other: Allow "Other" option for custom input
395
396
Returns:
397
Validated file or directory path
398
"""
399
```
400
401
**Usage Examples:**
402
403
```python
404
# Basic path input
405
file_path = inquirer.path("Enter file path")
406
407
# Directory only
408
log_dir = inquirer.path(
409
"Select log directory",
410
path_type=inquirer.Path.DIRECTORY,
411
exists=True # Must exist
412
)
413
414
# File that may not exist yet
415
output_file = inquirer.path(
416
"Output file path",
417
path_type=inquirer.Path.FILE,
418
exists=False, # Can be new file
419
default="./output.txt"
420
)
421
422
# Existing file requirement
423
config_file = inquirer.path(
424
"Select configuration file",
425
path_type=inquirer.Path.FILE,
426
exists=True # Must exist
427
)
428
```
429
430
## Shortcut vs Question Class Usage
431
432
**Use shortcuts when:**
433
- Asking single questions
434
- Quick scripting or interactive sessions
435
- Simple validation requirements
436
- No need for complex question chaining
437
438
**Use question classes with prompt() when:**
439
- Multiple related questions
440
- Complex validation dependencies between questions
441
- Dynamic question generation
442
- Need to maintain question state
443
- Advanced features like conditional questions
444
445
**Combined usage example:**
446
447
```python
448
import inquirer
449
450
# Use shortcuts for standalone questions
451
project_name = inquirer.text("Project name?")
452
use_database = inquirer.confirm("Include database support?")
453
454
# Use question classes for related questions
455
questions = []
456
if use_database:
457
questions.extend([
458
inquirer.List('db_type', message="Database type?",
459
choices=['postgresql', 'mysql', 'sqlite']),
460
inquirer.Text('db_name', message="Database name?",
461
default=f"{project_name}_db"),
462
inquirer.Text('db_user', message="Database user?", default="admin")
463
])
464
465
if questions:
466
db_config = inquirer.prompt(questions)
467
print("Database configuration:", db_config)
468
```
469
470
## Custom Render Engines
471
472
All shortcut functions accept a custom render parameter for specialized rendering:
473
474
```python
475
from inquirer.render.console import ConsoleRender
476
from inquirer.themes import GreenPassion
477
478
# Custom render with theme
479
custom_render = ConsoleRender(theme=GreenPassion())
480
481
name = inquirer.text(
482
"Your name?",
483
render=custom_render
484
)
485
```