larzprompt
Interactive, testable command-line prompts. Pure Python, zero dependencies.
Ask the user questions and get validated answers, with defaults, re-prompting on bad input, and a numbered menu for choices. Everything takes an injectable input function and output stream, so prompts are unit-testable - which most prompt libraries make painful.
from larzprompt import text, confirm, select, integer
name = text("Your name?", default="Anon")
if confirm("Continue?", default=True):
color = select("Pick a color", ["red", "green", "blue"])
age = integer("Age?", min=0, max=150)
Why
- Testable prompts. Every function takes
input_fnandoutput(andpasswordtakesgetpass_fn), so you feed canned answers and capture output in a test - no subprocess, no pty. This repo's 15 tests do exactly that. - The prompts you need.
text(default +validate),confirm(y/n + default),select(numbered menu, plain values or(label, value)pairs),integer(parse +min/max), andpassword(no echo). - Forgiving. Invalid input re-prompts with a helpful message instead of crashing.
- Zero dependencies. No
inquirer, noquestionary, noprompt_toolkit.
Install
pip install larzprompt
Usage
from larzprompt import text, confirm, select, integer, password
text("Email?", validate=lambda s: None if "@" in s else "must contain @")
confirm("Delete everything?", default=False)
select("Environment", [("Production", "prod"), ("Staging", "stage")])
integer("Port", default=8080, min=1, max=65535)
password("Enter password")
Tests
python -m unittest discover -s tests -v # 15 tests (canned answers + captured output)
The Larz stack
One of 30+ pure-Python, zero-dependency libraries at github.com/larz-scripter - pairs with larzcli and larzcolor.
License
MIT (c) larz-scripter
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 larzprompt-0.1.0.tar.gz.
File metadata
- Download URL: larzprompt-0.1.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb311cbe03095510e45952b2d538aee00a9d4dfde1ff3ee48fd3641d51c6730b
|
|
| MD5 |
bc1858547cab245c1b9c18c8a2210407
|
|
| BLAKE2b-256 |
cf0ca9704806a862d60c28cce940a9d4a5b53bcc3aee9ed7fab668246f4f3f89
|
File details
Details for the file larzprompt-0.1.0-py3-none-any.whl.
File metadata
- Download URL: larzprompt-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0211aa83444a622df1e21134843246a1b795560bf3badda5ec7a2cace24a16d
|
|
| MD5 |
7b4c7e94b9f5abf7da7c80250d70c3b8
|
|
| BLAKE2b-256 |
53ef5630403c4149b6f769f02bef201d2c8ce35f727985232b6736d0bfc81de1
|