A Python command line input and validation library
Project description
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, lists 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
(.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]:
See the Usage section of the documentation for a full list of methods, or the prompt module for details of methods and parameters.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file promptpy-0.2.0.tar.gz.
File metadata
- Download URL: promptpy-0.2.0.tar.gz
- Upload date:
- Size: 57.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
196e4fd73e721e895fcff02ccb4cc32a2d2f938c8bd6a52e18e95bbda3be9974
|
|
| MD5 |
4c8a4836c8315216f11917ae54936cb3
|
|
| BLAKE2b-256 |
4dd077de9ac0f43ac318cb665e11d8948e6145c8eda4178d3aeb3d4d00bd04b1
|
File details
Details for the file promptpy-0.2.0-py3-none-any.whl.
File metadata
- Download URL: promptpy-0.2.0-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4dcb39027a6f551a2100634251923139d110ca12b4d4b662f6ad4b4a255b4105
|
|
| MD5 |
e835deca39f47692453d9cf28b32fac9
|
|
| BLAKE2b-256 |
ef671702ca2dab740e9f21b6aaf90dbb7158e1a8aaf18558f597dec1be19504f
|