promptpy
A Python command-line input and validation library.
promptpy prompts for and validates a range of different data types on the command line. Out of the box it supports limited character sets, integers, floats, dates, yes/no, choices, lists, passwords and single-character commands:
from promptpy import Prompt
prompt = Prompt()
choice = prompt.integer("Pick a number", min=1, max=10, default=7)
# Prompt is displayed as:
# Pick a number (1-10) [7]:
The user will be reprompted with context-specific error messages until a valid integer is entered.
It is easy to add other types of prompt and validation by creating custom validators.
For more detail see the documentation.
Installation
Requires Python 3.12 or later.
(.venv) $ pip install promptpy
Examples
Options
from promptpy import Prompt
prompt = Prompt()
options = {
's': 'to solve',
'p': 'to play',
'q': 'to quit',
}
choice = prompt.options(options, default='s')
# Prompt is displayed as:
# Enter S to solve, P to play, Q to quit [S]:
Yes/No
from promptpy import Prompt
prompt = Prompt()
choice = prompt.yes_no("Again", default="y")
# Prompt is displayed as:
# Again (Y/N)? [Y]:
Date
import datetime
from promptpy import Prompt
prompt = Prompt()
date = prompt.date('Enter a date (dd/mm/yyyy)', '%d/%m/%Y', default=datetime.date(2024, 1, 1))
# Prompt is displayed as:
# Enter a date (dd/mm/yyyy) [01/01/2024]:
Password
from promptpy import Prompt
from promptpy.validators import PasswordRulesValidator
prompt = Prompt()
password = prompt.password(
toggle_visibility=True,
confirm=True,
validators=[PasswordRulesValidator(min_length=12, digit=True)],
)
# Prompt is displayed as:
# Enter password (V to toggle visibility):
Commands
Single-letter commands are accepted in place of the main input and returned as upper-case strings, so check the type of the result:
from promptpy import Prompt
prompt = Prompt()
value = prompt.integer("Pick a number", min=1, max=10, commands="q")
# Prompt is displayed as:
# Pick a number (1-10):
if value == "Q":
print("Goodbye")
See the Usage section of the documentation for a full list of methods, or the prompt module for details of methods and parameters.
Metadata
Release files for promptpy 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| promptpy-0.3.0.tar.gz | 83.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| promptpy-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 98.1 kB
Release files / promptpy-0.3.0.tar.gz
| Download URL | promptpy-0.3.0.tar.gz |
|---|---|
| Size | 83.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1b7695cc7624aba11a549de903e8dcaf818ddf20f14e635902fcadb8dfc63ef2
|
|
BLAKE2b-256 checksum How to use checksums |
b46ae6008e1c75f1c4ded53482b019ca4d206afda12c92ca73fe8fc6c7ee1884
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / promptpy-0.3.0-py3-none-any.whl
| Download URL | promptpy-0.3.0-py3-none-any.whl |
|---|---|
| Size | 14.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f3e519a39c75fc1d3dbad277f758eae5b5943e1c833a1d703b0222269b972064
|
|
BLAKE2b-256 checksum How to use checksums |
94f5bb104d7cc1d755efbaa4581517c1548b569c4733357f713bb7387f884789
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|