spur
raw JSON → 0.3.23 verified Fri May 01 auth: no python maintenance
A Python library for running commands and manipulating files locally or over SSH using the same interface. Current version: 0.3.23. Release cadence: sporadic, last release 2020.
pip install spur Common errors
error spur.spur.SshShell() TypeError: __init__() got an unexpected keyword argument 'ssh_key_file' ↓
cause Parameter is 'private_key_file' not 'ssh_key_file'.
fix
Use
private_key_file instead of ssh_key_file. error ModuleNotFoundError: No module named 'spur' ↓
cause Library not installed.
fix
Run
pip install spur error AttributeError: 'SshShell' object has no attribute 'run' ↓
cause Trying to use SshShell without opening connection first.
fix
Call
shell.open() or use context manager before running commands. Warnings
breaking spur 0.3.17 changed the default value of `store_pid` from True to False. If you rely on storing PID files, set store_pid=True. ↓
fix Explicitly pass store_pid=True when running commands if needed.
deprecated spur.SshShell.connect() is deprecated; use context manager (with statement) or open/close manually. ↓
fix Use `with SshShell(...) as shell:` or call `shell.open()` and `shell.close()`.
gotcha SshShell does not automatically close the connection; you must call close() or use a context manager. Forgetting to close can leave stale SSH connections. ↓
fix Always use `with SshShell(...) as shell:` pattern.
Imports
- spur
import spur - spur.SshShell wrong
import spur.SshShellcorrectfrom spur import SshShell
Quickstart
import spur
shell = spur.LocalShell()
result = shell.run(["echo", "hello"])
print(result.output)
ssh_shell = spur.SshShell(
hostname="localhost",
username="user",
password=os.environ.get('SSH_PASSWORD', ''),
)
with ssh_shell:
result = ssh_shell.run(["echo", "hello"])
print(result.output)