Skip to main content

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:

  • default
  • nullable
  • max_attempt 👉 Example :
value: int = prompt("Number", cast=int, default=0)
value: int | None = prompt("Number", cast=int, nullable=True)

⚠️ Important information

Empty value ("")

  • If default exist -> return default
  • Else if nullable=True -> return None
  • Else -> requests another seizure until attempt maximum attempt.

🐞 Error Handling

  • If verification fails -> try again
  • If cast fails -> try again
  • If max_attempts is reaching -> return default if exist else None

🧪 Tests

Use pytest with monkeypatch to mock input :

pytest -v

⚠️ Dependencies

  • rich for console output

💡 Use cases

  • Interactive CLIs
  • Automation scripts
  • Command-line tools

📄 License

MIT


👨‍💻 Auteur

BonjourBenjamin

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yapp_prompt-0.1.0.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yapp_prompt-0.1.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

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

Hashes for yapp_prompt-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fe084576679da027c8954f41051d54371aba33f1342bd32f5ce5ceac48ba5d27
MD5 358985a1ef155f8bc0cd6ef0f04ab8c6
BLAKE2b-256 a3abc10ef79f18e23211b3fb51ffcf0a6980f1713c65ce0b77694071d39b8b59

See more details on using hashes here.

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

Hashes for yapp_prompt-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6610f16f83662d96afe87f4cc026c8382468c482fa00e32997de21796543a5a9
MD5 dda2fdb58801c33346dab0e60ae323f4
BLAKE2b-256 fdcb78dae5526fc5728f66888b767cf7752c435e39d080a642d02bdf048670d9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page