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.3.tar.gz (9.1 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.3-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file yapp_prompt-0.1.3.tar.gz.

File metadata

  • Download URL: yapp_prompt-0.1.3.tar.gz
  • Upload date:
  • Size: 9.1 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.3.tar.gz
Algorithm Hash digest
SHA256 5c86a3cb5d275440e7d8d9be9ddf9ec7e668116a8e26075bba3982a989abf648
MD5 e2c4f29cb92c8c682c25570bd867192f
BLAKE2b-256 0c63c9bbf0a4bed54ef34fb2e71f4e9a1f7da750a0821384ae9f6e0b34dbb848

See more details on using hashes here.

File details

Details for the file yapp_prompt-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: yapp_prompt-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 7.7 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9918ee206f9a6232e3da8f22acbf21b8753eee6b739de7c5e7a1d6d5d0e3e6da
MD5 386ea8f654eafc68552e84035d7aeeec
BLAKE2b-256 e84ef7ba8b5e7fba34a92dcf9a6129435b625cb5bc2be5d7422049401660a49e

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