YAPP (Yet Another Prompt Package) is a lightweight Python library that provides a robust, typed, and configurable way to handle interactive user input.
Project description
🧩 YAPP — Yet Another Prompt Package
YAPP is a lightweight Python library that provides a robust, typed, and configurable way to handle interactive user input.
It provides a unique prompt function capable of handling:
- default value
- custom validation
- type conversion (
cast) - predefined choices
- attempt limit management
- masked input (e.g., passwords, tokens, etc.) [
secret] - advanced typing via
typing.overload
🚀 Installation
pip install yapp-prompt
✨ Features
- ✅ Default value management
- ✅ Support for nullable inputs
- ✅ Custom validation
- ✅ Automatic type conversion
- ✅ Support for user selections
- ✅ Secure input (
getpass) - ✅ Limit on the number of attempts
- ✅ Explicit typing with
typing.overload
📦 Base usage
from yapp_prompt import prompt
name = prompt("What is your name?")
print(name)
🎯 Default value
age = prompt("Your age", default=18, cast=int)
print(age, type(age))
👉 If the user presses Enter, 18 will be returned.
🔁 Nullable
value = prompt("Optional value", nullable=True)
👉 Return None if the user presses Enter.
🔒 Hidden input (passwords, tokens, etc.)
password = prompt("Password", secret=True)
🔢 Type conversion (cast)
age = prompt("Your age", cast=int)
✔️ Custom validation
def is_valid(value: str) -> bool:
return value.isdigit()
age = prompt("Age", verification=is_valid, cast=int)
📋 Preset options
def verify(choices, value):
return value in choices
color = prompt(
"Choose a color",
choices=["red", "blue", "green"],
verification=verify
)
🎨 Custom formatter
def formatter(choices):
return "\nAvailable: " + ", ".join(choices)
color = prompt(
"Color",
choices=["red", "blue"],
formatter=formatter
)
🔁 Number of attempts
value = prompt("Enter value", max_attempt=3)
Infinite mode
value = prompt("Enter value", max_attempt="infinite")
⚙️ Paramètres
| Parameters | Type | Description | Special value |
|---|---|---|---|
message |
str |
Message displayed | |
choices |
Choices | None |
List of option | |
default |
T | None |
Default value | |
nullable |
bool |
Allows None |
|
formatter |
Callable |
Format of the options | |
verification |
Callable |
Validation function | |
cast |
Callable |
Type conversion | |
secret |
bool |
Masque la saisie | |
max_attempt |
int |
Max number of attempts | "infinite" |
console |
rich.console.Console |
Console used |
🧠 Advanced typing
YAPP uses typing.overload to provide accurate typing based on:
defaultnullablemax_attempt👉 Example :
value: int = prompt("Number", cast=int, default=0)
value: int | None = prompt("Number", cast=int, nullable=True)
⚠️ Important information
Empty value ("")
- If
defaultexist -> returndefault - Else if
nullable=True-> returnNone - Else -> requests another seizure until attempt maximum attempt.
🐞 Error Handling
- If
verificationfails -> try again - If
castfails -> try again - If
max_attemptsis reaching -> returndefaultif exist elseNone
🧪 Tests
Use pytest with monkeypatch to mock input :
pytest -v
⚠️ Dependencies
richfor console output
💡 Use cases
- Interactive CLIs
- Automation scripts
- Command-line tools
📄 License
👨💻 Auteur
BonjourBenjamin
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 yapp_prompt-0.1.0.tar.gz.
File metadata
- Download URL: yapp_prompt-0.1.0.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe084576679da027c8954f41051d54371aba33f1342bd32f5ce5ceac48ba5d27
|
|
| MD5 |
358985a1ef155f8bc0cd6ef0f04ab8c6
|
|
| BLAKE2b-256 |
a3abc10ef79f18e23211b3fb51ffcf0a6980f1713c65ce0b77694071d39b8b59
|
File details
Details for the file yapp_prompt-0.1.0-py3-none-any.whl.
File metadata
- Download URL: yapp_prompt-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6610f16f83662d96afe87f4cc026c8382468c482fa00e32997de21796543a5a9
|
|
| MD5 |
dda2fdb58801c33346dab0e60ae323f4
|
|
| BLAKE2b-256 |
fdcb78dae5526fc5728f66888b767cf7752c435e39d080a642d02bdf048670d9
|