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.1.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.1-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: yapp_prompt-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 f66a796d8f71b726f44830dec4a6ae487326cff82a5cbcc17f50e3e800cff661
MD5 94362c5a0ec848d6b9679f410a34ee32
BLAKE2b-256 3cc027af63283452f15e06d471d164dc84e0dd31b052cc358d32042dda4bf27b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: yapp_prompt-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b07437f462ecad4b60ceec998b1e625f23d2cd24f6ef218327471fcf292835da
MD5 8d1cd7f2e059395cb53d5e2fa7cfdb27
BLAKE2b-256 1e0f5c4d612c7b26f204ecd89ae5f8f85531bcb4c5adea4fa0285d6206b5db69

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