Skip to main content

A typed Python wrapper for the gum CLI tool.

Project description

gum-py

A typed Python wrapper for the gum CLI tool.

Build glamorous interactive shell scripts from Python — without writing a line of Go.

Requirements

Installation

pip install gum-py

Install gum itself via your package manager:

brew install gum          # macOS / Linux
winget install charmbracelet.gum  # Windows

Quick start

from gum import Gum

with Gum() as g:
    kind = g.choose(
        items=["fix", "feat", "docs", "chore"],
        header="Commit type",
    )
    scope   = g.input(placeholder="scope (optional)")
    summary = g.input(placeholder="Short summary", width=72)
    body    = g.write(placeholder="Extended description  (ctrl+d to finish)")

    if g.confirm(prompt="Commit?", default=False):
        import subprocess
        msg = f"{kind[0]}{f'({scope})' if scope else ''}: {summary}"
        subprocess.run(["git", "commit", "-m", msg, "-m", body])

Run the built-in demo:

python -m gum
# or, after pip install:
gum-demo

Two calling styles

Every method accepts either inline kwargs (a config model is built internally) or an explicit config object (validated before the call):

g = Gum()

# Style 1 — inline kwargs
selected = g.choose(items=["a", "b", "c"], height=5)

# Style 2 — config object
from gum import ChooseConfig
cfg = ChooseConfig(items=["a", "b", "c"], height=5)
selected = g.choose(cfg)

Styling

Pass a StyleOptions instance to any *_style parameter:

from gum import Gum, StyleOptions, BorderStyle, Align

g = Gum()
box = g.style(
    texts=["Bubble Gum (1¢)", "So sweet and so fresh!"],
    foreground="212",
    border=BorderStyle.DOUBLE,
    border_foreground="212",
    align=Align.CENTER,
    width=50,
    margin="1 2",
    padding="2 4",
)
print(box)

Environment variables

gum supports GUM_* environment variables. Pass them via the env parameter to have them apply to every call made through that instance:

g = Gum(env={"GUM_INPUT_CURSOR_FOREGROUND": "#FF0"})

Explicit flags set through config objects always take precedence over env vars.

Commands

Method gum command Returns
choose() gum choose list[str]
confirm() gum confirm bool
input() gum input str
write() gum write str
filter() gum filter list[str]
spin() gum spin str
style() gum style str
join() gum join str
format() gum format str
log() gum log None
file() gum file str
pager() gum pager None
table() gum table str

Error handling

from gum import Gum, GumNotFoundError, GumCommandError

try:
    g = Gum()
    name = g.input(placeholder="Your name")
except GumNotFoundError:
    print("gum is not installed — see https://github.com/charmbracelet/gum")
except GumCommandError as e:
    print(f"gum exited {e.returncode}: {e.stderr}")

License

MIT

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

gum_wrapper-0.1.1.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

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

gum_wrapper-0.1.1-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file gum_wrapper-0.1.1.tar.gz.

File metadata

  • Download URL: gum_wrapper-0.1.1.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for gum_wrapper-0.1.1.tar.gz
Algorithm Hash digest
SHA256 55888da6127695f5283a11a2c03d8c1eaee20248bb0778d85f0885c429fdbe55
MD5 b067a5a3c5320ff954c92e981fc94110
BLAKE2b-256 b790974472f2eaabd57133f36dee49d80a6f7efb0da0c2a291f0cad8c949d3f9

See more details on using hashes here.

File details

Details for the file gum_wrapper-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: gum_wrapper-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for gum_wrapper-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 797584c33391ee548fbc4ad0524cd6fcfad00fa1d618b0aa9b65288bcb43a36e
MD5 c3acb1a0280b4872e36a14c137ea3960
BLAKE2b-256 d0d437c08be499b19af55a75ca03a60b0cc34d25ab55cd6d3f1a522682566782

See more details on using hashes here.

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