Runez Library

5.7.1 · active · verified Wed Apr 15

Runez is a friendly, pure Python convenience library offering utilities for common operations such as file manipulation, process execution, and logging that developers often find themselves rewriting. It stands alone without external dependencies, focusing on robust handling of edge cases and providing clear error reporting. The current version is 5.7.1, with a regular release cadence.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to execute shell commands and perform basic file operations using `runez`. It shows handling both successful and potentially failing commands, as well as writing to and reading from a file.

import runez
import os

# Example 1: Running a command
print("--- Running a command ---")
try:
    output = runez.run("echo", "Hello from runez!", capture_output=True)
    print(f"Command output: {output.strip()}")

    # Example of a command that might fail gracefully
    print("\n--- Running a command that might fail (fatal=False) ---")
    result = runez.run("this-command-does-not-exist", fatal=False, capture_output=True)
    if result is False:
        print("Command failed gracefully as expected.")
    else:
        print("Unexpected success or output:", result)

except Exception as e:
    print(f"Error running command: {e}")

# Example 2: File operations
print("\n--- File operations ---")
filename = "my_runez_file.txt"
if os.path.exists(filename):
    runez.delete(filename)

runez.write(filename, "First line\nSecond line\n")
print(f"Content written to {filename}")

content = runez.readlines(filename)
print(f"Content read from {filename}: {content}")

runez.delete(filename)
print(f"Deleted {filename}")

view raw JSON →