Skip to main content

CLIs with prompts, shell runs, and testable flows

Project description

ask-shell

PyPI GitHub codecov Docs

Python library for CLIs that use interactive prompts, subprocess runs with Rich output, and test helpers so the same flows run in tests without a TTY.

  • Install: uv add ask-shell or pip install ask-shell (Python 3.13+)
  • Docs: GitHub Pages

What it provides

  • ask: Prompts (confirm, text, select list/dict, single and multiple choice) built on questionary, with Rich styling
  • shell: Run shell commands via run, run_and_wait, and run_pool; prefixed live output, optional log dirs, retries, and interrupt handling
  • console: Rich console and progress utilities; configure_logging(app) wires a Typer app to Rich logging (handler, command decorator, optional secret hiding)
  • shell_events: Callbacks for run lifecycle (before/after, stdout/stderr) for custom handling
  • AskShellSettings: Paths and options (e.g. run log directory); plug into your config or env

Quick example

from ask_shell import ask, shell

if ask.confirm("Run the script?", default=True):
    name = ask.text("Name:", default="world")
    shell.run_and_wait(f"echo Hello, {name}")

Testing

Use question_patcher to feed fixed responses to prompts, or raise_on_question to fail fast when a prompt is hit. Both are context managers; see the ask API docs for details.

from ask_shell import ask
from ask_shell.ask import question_patcher

with question_patcher(responses=["y", "myname"]):
    assert ask.confirm("Run?")
    assert ask.text("Name:") == "myname"

License

MIT. See LICENSE.

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

ask_shell-0.6.0.tar.gz (31.9 kB view details)

Uploaded Source

Built Distribution

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

ask_shell-0.6.0-py3-none-any.whl (39.1 kB view details)

Uploaded Python 3

File details

Details for the file ask_shell-0.6.0.tar.gz.

File metadata

  • Download URL: ask_shell-0.6.0.tar.gz
  • Upload date:
  • Size: 31.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ask_shell-0.6.0.tar.gz
Algorithm Hash digest
SHA256 25d0a72d5d61528dc9b3fcfa88ce053f19ec96d12c16daa24a3a3f6ef12b0898
MD5 c8b5ec86a0c87e952d9fea33b2a51c8b
BLAKE2b-256 c2a54b5b4b8954a9ddc6c383e85045126c0e2ce7eb94be2b6cbe219d1e7be5b1

See more details on using hashes here.

Provenance

The following attestation bundles were made for ask_shell-0.6.0.tar.gz:

Publisher: release.yaml on EspenAlbert/ask-shell

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

File details

Details for the file ask_shell-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: ask_shell-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 39.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ask_shell-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 803e19c254c1b50d539fa563bd9fc60f6939975b663788711a4e55d322b53e84
MD5 875877593c9d82eaba1376edc8cc66d0
BLAKE2b-256 2a2e2ada89e3a85cc190692836abb238f98b278c15773a154a40c671df8f90d6

See more details on using hashes here.

Provenance

The following attestation bundles were made for ask_shell-0.6.0-py3-none-any.whl:

Publisher: release.yaml on EspenAlbert/ask-shell

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