Skip to main content

Multiplexed user input via console, GUI, and web, depending on availability.

Project description

dworshak-prompt

A Python utility that ensures you can always get user input by falling back through multiple interfaces. dworshak-prompt is a CI-safe, shell-friendly prompting engine that integrates with persistent config and secret storage.

How it works

It captures input by cycling through modes based on environment availability:

  1. Console (CLI)
  2. GUI (Tkinter)
  3. Web (Local Browser Server)

Automatically skips incompatible modes (e.g., GUI on WSL) via pyhabitat.

Usage

Obtain

Leverage dworshak-config, dworshak-config, and dworshak-env to automatically handle values.

from dworshak_prompt import Obtain

obtain = Obtain()

obtain.config(service, item, message)
obtain.secret(service, item, message)
obtain.env(key, message)

Ask

Prompt the user then handle values manually.

from dworshak_prompt import DworshakPrompt, PromptMode

# Basic
val = DworshakPrompt().ask("Enter value")

# Options
val = DworshakPrompt().ask(
    message = "Secure Key",
    hide_input=True,
    priority = [PromptMode.CONSOLE, PromptMode.GUI]
    avoid = {PromptMode.WEB}

)

Another example, for handling CI:

from dworshak_prompt import DworshakPrompt, PromptMode

# If this runs in GitHub Actions, it returns "staging" immediately.
# If it runs on a laptop, it pops up a GUI or Console prompt.
val = DworshakPrompt().ask(
    message = "Target Environment",
    suggestion="production",  # What the human sees
    default="staging"         # What the CI/Headless system uses
)

Leveraging dworshak-prompt for calling and adding configured values.

from dworshak_prompt import Obtain

# Custom path for a specific project
obtain_mgr = Obtain(config_path="~/.pipeline-eds/config.json")
api_key = obtain_mgr.config("api_key", message="Enter EDS API Key")

The default config file path is "~/.dworshak/config.json".


CLI

The dworshak layer is the intended primary CLI entry point, but the dworshak-prompt CLI can be used directly.

pipx install "dworshak-prompt[typer]"
dworshak-prompt --version
dworshak-prompt --help
dworshak-prompt ask --message "Please state name" --interace web

dworshak-prompt is designed to be useful even without Python code. It can be used directly from shell scripts, CI pipelines, and ops tooling to safely obtain, persist, and reuse configuration values.

Piping and environment variable capture works, but will naturally fallback to GUI or Web input because in these cases stdout is not a TTY. However, you may continue to use console input and leverage dev/tty by using envionrmental variable DWORSHAK_FORCE_INTERACTIVE_TTY.

# Enable console input during wrapped or piped shell capture.
export DWORSHAK_FORCE_INTERACTIVE_TTY=1
VAR=$(dworshak-prompt obtain secret "special_api" "password" --emit)

See the dworshak-prompt Typer CLI structure.

dworshak-prompt helptree

Screenshot of the dworshak-prompt CLI helptree

helptree is utility funtion for Typer CLIs, imported from the typer-helptree library.


Add dworshak-prompt to Python project

When using uv for dependency management.

uv add dworshak-prompt --extra typer

Or, when using raw pip for dependency management.

pip install "dworshak-prompt[typer]"

Including the typer optional dependency group ensures that Typer and Rich are included as a dependencies. Without this, the CLI and console prompting functionality are still stable, due to Python standard library fallbacks.


More Information


Sister Projects in the Dworshak Ecosystem

pipx install dworshak
pip install dworshak-secret
pip install dworshak-config
pip install dworshak-env
pip install dworshak-prompt

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

dworshak_prompt-0.2.28.tar.gz (30.3 kB view details)

Uploaded Source

Built Distribution

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

dworshak_prompt-0.2.28-py3-none-any.whl (35.0 kB view details)

Uploaded Python 3

File details

Details for the file dworshak_prompt-0.2.28.tar.gz.

File metadata

  • Download URL: dworshak_prompt-0.2.28.tar.gz
  • Upload date:
  • Size: 30.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dworshak_prompt-0.2.28.tar.gz
Algorithm Hash digest
SHA256 4811776fb4535ac5db10c0a19dcd3a508d9f290fcfa46d2ff66a102eabc0132f
MD5 e373a3e575716358a83a00b62d69bc9d
BLAKE2b-256 563883bb38edf2dcc2a004314e62f7de20a29f71c6d816fbf0213b93f91052c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for dworshak_prompt-0.2.28.tar.gz:

Publisher: publish.yml on City-of-Memphis-Wastewater/dworshak-prompt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dworshak_prompt-0.2.28-py3-none-any.whl.

File metadata

File hashes

Hashes for dworshak_prompt-0.2.28-py3-none-any.whl
Algorithm Hash digest
SHA256 0cf7eba838d1701c6bb86cba95507812462349f9e42f77bd959d389732c81a8e
MD5 6b3e27312a7633d38902e55576ac6385
BLAKE2b-256 dc98aa4b5c3bdb48e9f06ab15ac31de9ceee4b0f1a162b777fee7b0f818a8826

See more details on using hashes here.

Provenance

The following attestation bundles were made for dworshak_prompt-0.2.28-py3-none-any.whl:

Publisher: publish.yml on City-of-Memphis-Wastewater/dworshak-prompt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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