click-prompt
raw JSON → 0.7.1 verified Sat May 09 auth: no python
Click-prompt provides enhanced interactive prompts for the Click library, offering styled input, confirmation, and selection prompts with color and validation. Current version 0.7.1, released March 2024, with occasional updates.
pip install click-prompt Common errors
error ImportError: cannot import name 'Prompt' from 'click' ↓
cause Trying to import Prompt from the wrong module (click instead of click_prompt).
fix
Use 'from click_prompt import Prompt'.
error NameError: name 'prompt' is not defined ↓
cause Using the old function-style API (prompt()) which was removed after version 0.5.x.
fix
Use the new class-based API: Prompt(...).ask() or from click_prompt import prompt if using older version.
Warnings
gotcha The Prompt class is not imported from 'click'. It must be imported from 'click_prompt'. ↓
fix Use 'from click_prompt import Prompt'.
deprecated In version 0.6.0, the API changed: 'prompt()' function was replaced by the 'Prompt' class. Old code using 'prompt()' will break. ↓
fix Use 'Prompt(...).ask()' instead of 'prompt(...)'.
gotcha If click is not installed, importing click_prompt will raise an ImportError because click is a dependency. ↓
fix Install both: 'pip install click click-prompt'.
Imports
- Prompt wrong
from click.prompt import Promptcorrectfrom click_prompt import Prompt
Quickstart
from click_prompt import Prompt
name = Prompt('Enter your name', default='World').ask()
print(f'Hello, {name}!')