Sarge

0.1.8 · active · verified Thu Apr 16

Sarge is a Python library that wraps the standard `subprocess` module, providing enhanced cross-platform functionality for running shell commands and pipelines. It simplifies common tasks such as command chaining, robust output capture, and secure command formatting to prevent shell injection, aiming to make interactions with external programs easier than direct `subprocess` usage. The current stable version is 0.1.8, released recently in 2026, and the project actively maintains its documentation.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `sarge.run` to execute single commands and pipelines, capture output, and inspect return codes. The `Capture()` object is used to collect stdout for later access.

import sarge

# Run a simple command and get its output
p = sarge.run('echo "Hello from Sarge!"', stdout=sarge.Capture())
print(p.stdout.text.strip())

# Run a command pipeline
p = sarge.run('ls -l | grep .py', stdout=sarge.Capture())
print(p.stdout.text)

# Check return codes
p = sarge.run('false || echo success', stdout=sarge.Capture())
print(f"Return code: {p.returncode}")
print(f"Output: {p.stdout.text.strip()}")

view raw JSON →