Convenience one-liner functions for quick prompt creation without manual instantiation.
Quick text input prompt.
def prompt_text(message: str) -> str:
...message(str): The prompt text
str: The user's input text
RuntimeError- If not a TTY, IO error, or operation canceled
import pinq
name = pinq.prompt_text("What is your name? ")
print(f"Hello, {name}!")prompt = pinq.TextPrompt("What is your name? ")
name = prompt.prompt()Quick password/secret input prompt.
def prompt_secret(message: str) -> str:
...message(str): The prompt text (usually "Password: ")
str: The entered password/secret
RuntimeError- If not a TTY, IO error, or operation canceled
import pinq
password = pinq.prompt_secret("Enter password: ")
# Characters not echoed to terminalprompt = pinq.PasswordPrompt("Enter password: ")
password = prompt.prompt()Quick yes/no confirmation prompt.
def prompt_confirmation(message: str) -> bool:
...message(str): The yes/no question
bool:Truefor yes,Falsefor no
RuntimeError- If not a TTY, IO error, or operation canceled
import pinq
if pinq.prompt_confirmation("Continue? "):
print("Continuing...")
else:
print("Canceled.")prompt = pinq.ConfirmPrompt("Continue? ")
result = prompt.prompt()Quick integer input prompt.
def prompt_int(message: str) -> int:
...message(str): The prompt text
int: The parsed integer (64-bit signed)
RuntimeError- If not a TTY, IO error, operation canceled, or parse error
import pinq
count = pinq.prompt_int("How many items? ")
print(f"Processing {count} items...")prompt = pinq.IntPrompt("How many items? ")
count = prompt.prompt()- Parses as 64-bit signed integer (i64)
- Rejects non-numeric input
- No range validation (use custom validators for range checks)
Quick float input prompt.
def prompt_float(message: str) -> float:
...message(str): The prompt text
float: The parsed float (64-bit)
RuntimeError- If not a TTY, IO error, operation canceled, or parse error
import pinq
price = pinq.prompt_float("Enter price: $")
print(f"Total: ${price:.2f}")prompt = pinq.FloatPrompt("Enter price: $")
price = prompt.prompt()Quick unsigned 32-bit integer input prompt.
def prompt_u32(message: str) -> int:
...message(str): The prompt text
int: The parsed unsigned 32-bit integer (0 to 4,294,967,295)
RuntimeError- If not a TTY, IO error, operation canceled, or parse error
import pinq
port = pinq.prompt_u32("Enter port number: ")
print(f"Listening on port {port}")- Accepts 0 to 4,294,967,295
- Rejects negative numbers
- Rejects numbers > 4,294,967,295
Quick unsigned 64-bit integer input prompt.
def prompt_u64(message: str) -> int:
...message(str): The prompt text
int: The parsed unsigned 64-bit integer
RuntimeError- If not a TTY, IO error, operation canceled, or parse error
import pinq
timestamp = pinq.prompt_u64("Enter Unix timestamp: ")
print(f"Timestamp: {timestamp}")Quick 32-bit float input prompt.
def prompt_f32(message: str) -> float:
...message(str): The prompt text
float: The parsed 32-bit float
RuntimeError- If not a TTY, IO error, operation canceled, or parse error
import pinq
temperature = pinq.prompt_f32("Temperature (Β°C): ")
print(f"Temperature: {temperature:.1f}Β°C")- Lower precision than f64
- Useful for embedded or space-constrained applications
Quick 64-bit float input prompt.
def prompt_f64(message: str) -> float:
...message(str): The prompt text
float: The parsed 64-bit float
RuntimeError- If not a TTY, IO error, operation canceled, or parse error
import pinq
amount = pinq.prompt_f64("Enter amount: $")
print(f"Total: ${amount:.2f}")- Higher precision than f32
- Default choice for floating-point numbers
Quick date selection using interactive calendar.
def prompt_date(message: str) -> str:
...message(str): The prompt text
str: The selected date in YYYY-MM-DD format
RuntimeError- If not a TTY, IO error, or operation canceled
import pinq
from datetime import datetime
date_str = pinq.prompt_date("Select a date: ")
print(f"Selected: {date_str}")
# Parse for further use
date_obj = datetime.strptime(date_str, "%Y-%m-%d").date()prompt = pinq.DateSelectPrompt("Select a date: ")
date_str = prompt.prompt()Using one-liners:
import pinq
name = pinq.prompt_text("Name: ")
age = pinq.prompt_int("Age: ")
confirmed = pinq.prompt_confirmation("Continue? ")Using builder pattern:
import pinq
prompt = pinq.TextPrompt("Name: ")
name = prompt.prompt()
prompt = pinq.IntPrompt("Age: ")
age = prompt.prompt()
prompt = pinq.ConfirmPrompt("Continue? ")
confirmed = prompt.prompt()Using builder with configuration:
import pinq
prompt = pinq.TextPrompt("Username: ")
prompt.with_default("admin")
prompt.with_help_message("Default: admin")
username = prompt.prompt()- One-liners: Simple prompts without configuration
- Builder pattern: Complex prompts with defaults, help messages, etc.
All functions can raise RuntimeError with messages like:
"Input is not a TTY"- Not running in a terminal"IO Error: ..."- Operating system error"Operation canceled by user"- User pressed Ctrl+C or ESC"Invalid configuration: ..."- Invalid setup- Custom parsing errors for typed prompts
import pinq
try:
age = pinq.prompt_int("Your age: ")
except RuntimeError as e:
print(f"Error: {e}")
age = 0 # Default fallback| Function | Input Type | Return Type | Use Case |
|---|---|---|---|
prompt_text |
Free text | str | General text input |
prompt_secret |
Hidden text | str | Passwords, secrets |
prompt_confirmation |
Yes/No | bool | Confirmations |
prompt_int |
Integer | int | Whole numbers |
prompt_float |
Float | float | Decimal numbers (f64) |
prompt_u32 |
Unsigned 32-bit | int | Port numbers, IDs |
prompt_u64 |
Unsigned 64-bit | int | Large numbers, timestamps |
prompt_f32 |
Float 32-bit | float | Space-constrained floats |
prompt_f64 |
Float 64-bit | float | Precise decimals |
prompt_date |
Calendar | str | Date selection |
- Classes Reference - Detailed prompt class documentation
- Builders Reference - Builder pattern examples
- Examples - Real-world usage examples