Skip to main content

A lightweight Python wrapper for Slurm sbatch/srun with robust subprocess handling and optional logging.

Project description

quickslurm

Lint/Test Build/Publish Docs

PyPI Python versions License

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

quickslurm-0.2.0.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

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

quickslurm-0.2.0-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file quickslurm-0.2.0.tar.gz.

File metadata

  • Download URL: quickslurm-0.2.0.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for quickslurm-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3e19833186469cce4eb5add4ef4e5ba37d938e129c92121d40b2780c880ef388
MD5 bd677d6b627191874fb2e8d50a6635d1
BLAKE2b-256 6d8d3815bdee28dc0d359b2c0033878741915ec994f71e29c68071ad2b2ad944

See more details on using hashes here.

File details

Details for the file quickslurm-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: quickslurm-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for quickslurm-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9f253cddbc7e90a0450436dfdcd3f25ffd0d946ef80d6fed9c2b6e1d41d0309c
MD5 a3b3ff4ec652e2cfbca33bb1be134c8f
BLAKE2b-256 c49eeb7ef56d16e5f28617c11c3fecbb6db9e3accb320ea0e8b8e6d4f640414d

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