Skip to main content

A lightweight Python utility for executing shell commands with real-time or captured output.

Project description

funshell

A lightweight Python utility for executing shell commands, supporting real-time output streaming and captured output.

Installation

pip install funshell

Quick Start

from run import run_shell, run_shell_list

# Real-time output to terminal, returns exit code
exit_code = run_shell("echo hello world")
# hello world
# exit_code == "0"

# Capture output as string
output = run_shell("echo hello world", printf=False)
# output == "hello world"

API

run_shell(command, printf=True, *, cwd=None, timeout=None, encoding="utf-8")

Execute a shell command.

Parameter Type Default Description
command str required Shell command to execute
printf bool True True: stream to terminal; False: capture output
cwd str | None None Working directory for the command
timeout float | None None Timeout in seconds
encoding str "utf-8" Output encoding when capturing

Returns: Exit code as string when printf=True, stdout content when printf=False.

run_shell_list(command_list, printf=True, *, cwd=None, timeout=None, encoding="utf-8")

Execute multiple commands sequentially (joined with &&, stops on first failure).

Parameter Type Default Description
command_list list[str] required List of shell commands
printf bool True True: stream; False: capture
cwd str | None None Working directory
timeout float | None None Timeout for the entire command chain
encoding str "utf-8" Output encoding

Examples

from run import run_shell, run_shell_list

# Capture command output
result = run_shell("ls -la", printf=False)
print(result)

# Run in a specific directory
run_shell("git status", cwd="/path/to/repo")

# Set a timeout (seconds)
run_shell("sleep 100", timeout=5)
# Returns: "run shell error: command timed out"

# Execute a sequence of commands
run_shell_list(["mkdir -p build", "cd build", "cmake .."])

# Capture output of chained commands
output = run_shell_list(["echo hello", "echo world"], printf=False)
# output == "hello\nworld"

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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

funshell-1.0.19-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file funshell-1.0.19-py3-none-any.whl.

File metadata

  • Download URL: funshell-1.0.19-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.5 {"installer":{"name":"uv","version":"0.10.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for funshell-1.0.19-py3-none-any.whl
Algorithm Hash digest
SHA256 cae36e8a21218e69e450ce19407301bbf1c11304e93f70f9503a813b006e970c
MD5 e5b4dc0a601751543b806f119d4d7605
BLAKE2b-256 fb2b6b8ac073b8465b9a977ec68315b16715c832a533fb71a1cd5f74b410903a

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