Plumbum: Shell Combinators Library

1.10.0 · active · verified Thu Apr 09

Plumbum is a Python library for writing shell scripts in a Pythonic manner. It allows you to invoke external commands, chain them using pipes, redirect I/O, and build command-line applications programmatically. The current version is 1.10.0, and it maintains an active release cadence with minor versions and patch releases addressing bug fixes and Python version support.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to run external commands, chain them with pipes, access local machine context (like current working directory), and execute commands within specific directories using `plumbum`.

from plumbum import cmd
from plumbum.cmd import ls, grep
from plumbum import local

# Run a simple command and capture output
output = ls("-a")
print(f"ls -a output:\n{output}")

# Pipe commands together
pipe_output = (ls["-a"] | grep["-i", "py"])()
print(f"ls -a | grep -i py output:\n{pipe_output}")

# Access local machine paths and environment
print(f"Current directory: {local.cwd}")
print(f"User home: {local.home}")

# Execute a command in a specific directory
with local.cwd(local.tempdir):
    temp_dir_files = ls()
    print(f"Files in temporary directory: {temp_dir_files}")

view raw JSON →