kennethreitz.org / Software / Delegator

delegator

Delegator is a Python library that allows you to define and execute shell commands in a more readable and maintainable way. It is a wrapper around the subprocess module and provides a more high-level interface for running shell commands.

Key Features

Installation

You can install Delegator using uv or pip:

$ uv pip install delegator.py

Usage

Here's a simple example of how you can use Delegator to run a shell command:

import delegator

c = delegator.run('ls -l')
print(c.out)

In this example, we use the run function to execute the ls -l command and print the output to the console.

Command Chaining

Delegator allows you to chain multiple commands together using the | operator. Here's an example:

import delegator

c = delegator.chain('ls -l | grep .py')
print(c.out)

In this example, we use the chain function to run the ls -l | grep .py command, which lists all Python files in the current directory.

Predecessor — Envoy

envoy is a similar library that provides a high-level interface for subprocess management in Python. Delegator is a more modern and feature-rich alternative to Envoy, with additional functionality and improved performance. It has also been battle–tested in production environments and is used by pipenv for shell command execution.

Read More

The project was gifted to Amit Tripathi and is available on GitHub: