A lightweight Python wrapper for Slurm sbatch/srun with robust subprocess handling and optional logging.
Project description
quickslurm
A lightweight Python wrapper around Slurm for:
- Submitting batch jobs (sbatch)
- Running commands (srun)
- Cancelling jobs (scancel)
It focuses on safe subprocess handling, simple ergonomics, and sensible defaults.
Full documentation can be found here: Quickslurm Docs
Features
- sbatch and srun helpers with consistent argument handling
- Optional built-in logging (file and stderr)
- Pass-through environment variables (base and per-call overrides)
- Convenience for inline sbatch scripts
- Optional wait for job completion after sbatch submission
Installation
- Requires Python 3.8+
- Requires Slurm 23.02+ be installed on the system
- Assumes Slurm binaries (sbatch, srun, scancel, sacct if using wait) are on PATH
pip install quickslurm
Quick start
from quickslurm import Slurm, SlurmError
slurm = Slurm(enable_logging=True)
# Submit an existing script
submit = slurm.sbatch(
script_path="train.sh",
sbatch_options={
"job-name": "trainA",
"time": "00:30:00",
"partition": "short",
"cpus-per-task": 4,
"mem": "8G",
"output": "slurm-%j.out",
},
script_args=["--epochs", "10"],
)
print("Job ID:", submit.job_id)
# Submit an inline command (temp script will be generated)
submit2 = slurm.submit_inline(
command=["python", "train.py", "--epochs", "5"],
sbatch_options={"time": "00:10:00", "job-name": "quick-train"},
)
print("Inline Job ID:", submit2.job_id)
# Run something via srun (non-interactive)
res = slurm.run(["hostname"], srun_options={"ntasks": 1})
print("Hostname:", res.stdout.strip())
# Cancel a job
slurm.cancel(submit2.job_id)
Sample output:
Job ID: 12300008
Inline Job ID: 12300009
Hostname: testnode1
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file quickslurm-0.2.5.tar.gz.
File metadata
- Download URL: quickslurm-0.2.5.tar.gz
- Upload date:
- Size: 13.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
210d2b819e54dd4a7d6c3e6490b627e1c24526f238e97c3fbcd654810521f1f5
|
|
| MD5 |
5d52f7303f94fae5a5415aac4881958e
|
|
| BLAKE2b-256 |
88d31189acdf47113014de0b931a8a2292aecba52df09ffba5d7a3dde505a0a9
|
File details
Details for the file quickslurm-0.2.5-py3-none-any.whl.
File metadata
- Download URL: quickslurm-0.2.5-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b43196106ddc30aea249649b24554d23391c2ebea266910f61466542f5f7399
|
|
| MD5 |
37796e543117585583d55fd2fbdbe7fd
|
|
| BLAKE2b-256 |
84d4dca18e14c5572a54702c6f9a4a428c5f4ef02aaf694ca57e731c260d62ec
|