Pick
Pick is a small Python library that simplifies creating interactive selection lists in the terminal. It provides a straightforward API for single and multi-select menus, making it easy to build command-line interfaces. The library is currently at version 2.6.0 and maintains an active, though not rapid, release cadence.
Warnings
- gotcha The default backend for `pick` is `curses`, which is primarily designed for Unix-like systems. On Windows, `curses` is not available by default and can lead to `ModuleNotFoundError` or `AttributeError`. For cross-platform compatibility, especially on Windows, consider installing `blessed` and specifying it as the backend.
- gotcha When using `multiselect=True` with `min_selection_count`, the user cannot exit the selection menu by pressing ENTER until they have selected at least the specified minimum number of items. This can be confusing if the user attempts to complete the selection prematurely.
- gotcha As `pick` relies on terminal capabilities, display issues or unexpected behavior can occur across different terminal emulators or operating systems, particularly with the default `curses` backend. Font rendering, color support, and keybindings can vary.
Install
-
pip install pick -
pip install "pick[blessed]"
Imports
- pick
from pick import pick
Quickstart
from pick import pick
# Single selection example
title = 'Please choose your favorite programming language: '
options = ['Python', 'JavaScript', 'C/C++', 'Java', 'Rust']
selected, index = pick(options, title)
print(f"You picked {selected} at index {index}")
# Multi-selection example
title_multiselect = 'Please choose all languages you like (press SPACE to select, ENTER to finish): '
min_selection = 1 # User must select at least 1 item
selected_multi, indices_multi = pick(options, title_multiselect, multiselect=True, min_selection_count=min_selection)
print(f"You picked {selected_multi} at indices {indices_multi}")