Skip to main content

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_fn and output (and password takes getpass_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), and password (no echo).
  • Forgiving. Invalid input re-prompts with a helpful message instead of crashing.
  • Zero dependencies. No inquirer, no questionary, no prompt_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

larzprompt-0.1.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

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

larzprompt-0.1.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

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

Hashes for larzprompt-0.1.0.tar.gz
Algorithm Hash digest
SHA256 eb311cbe03095510e45952b2d538aee00a9d4dfde1ff3ee48fd3641d51c6730b
MD5 bc1858547cab245c1b9c18c8a2210407
BLAKE2b-256 cf0ca9704806a862d60c28cce940a9d4a5b53bcc3aee9ed7fab668246f4f3f89

See more details on using hashes here.

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

Hashes for larzprompt-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e0211aa83444a622df1e21134843246a1b795560bf3badda5ec7a2cace24a16d
MD5 7b4c7e94b9f5abf7da7c80250d70c3b8
BLAKE2b-256 53ef5630403c4149b6f769f02bef201d2c8ce35f727985232b6736d0bfc81de1

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page