Skip to content
Py Cluster Api

Py Cluster Api

github.com • November 24, 2026

A Python library for submitting and monitoring jobs on HPC clusters. Supports running arbitrary executables (Nextflow pipelines, Python scripts, Java tools, etc.) on clusters and taking action when jobs complete via async callbacks.

SLURM (requires slurmdbd accounting; see SLURM notes )

We will accept PRs that implement and test additional executors (SGE, PBS, etc.)

Async-first — built on asyncio for non-blocking job submission and monitoring

Local executor — run jobs as local subprocesses for development and testing, including array jobs

Job monitoring — polls the scheduler and fires callbacks on job completion, failure, or cancellation

Job arrays — submit array jobs with per-element log files

Zombie detection — jobs that disappear from the scheduler are marked as failed

YAML config with profiles — Nextflow-style config with per-environment profiles

Callback chaining — register on_success , on_failure , or on_exit handlers on any job

Job dependencies — chain jobs with depends_on ; dependents are auto-cancelled if an upstream job fails

Environment control — inherit_env and login_shell submit options control what environment a job runs with

Reconnect & external tracking — reconnect() rediscovers jobs after a restart; track() seeds a job from an external store (e.g. a database) into the executor

Requires Python 3.10+.

The array index environment variable depends on the executor: LSF uses $LSB_JOBINDEX , SLURM uses $SLURM_ARRAY_TASK_ID , and the local executor uses $ARRAY_INDEX .

Chain jobs so each stage starts only after the one succeeds:

depends_on accepts multiple jobs (fan-in). On LSF this uses native bsub -w "done(...)" -ti , so chains keep running if your process exits, and LSF terminates dependents whose upstream failed — no jobs stuck pending forever. When a dependent is cancelled this way, record.metadata["dependency_failed"] lists the failed upstream job ids. On SLURM the same chain uses sbatch --dependency=afterok:... --kill-on-invalid-dep=yes .

Reconnecting After Restart

If your process crashes or restarts, reconnect() rediscovers running jobs from the scheduler and resumes tracking them. Requires job_name_prefix to be set in config.

Tracking Jobs From External State

track() seeds the executor with a job ID from a persistent store (e.g. a database) without re-submitting it, so a later poll() or cancel() can act on jobs submitted by a process:

Configuration is loaded from YAML with optional profiles. The order is:

Explicit config_path argument

$CLUSTER_API_CONFIG environment variable

~/.config/cluster_api/config.yaml

Example cluster_api.yaml

Accounting required. Status comes from sacct , so the cluster must run slurmdbd. History is kept subject to the site's PurgeJobAfter setting.

No requeue. Every job is submitted with --no-requeue so preempted or node-failed jobs are reported as terminal. Sites that set PrologFlags=ForceRequeueOnFail or requeue_on_resume_failure can still requeue a job behind our back; the rerun is not tracked.

Exit codes. exit_code is the script's return code, or -signal when a signal terminated the job (e.g. -9 ), as for the local executor.

max_mem is not reported (sacct only has it on step rows).

cancel_by_name matches an exact job name; scancel has no globbing.

inherit_env=False uses --export=NONE , which SLURM documents as still loading the user's login environment on the node; env values are exported inside the script and SLURM_EXPORT_ENV=ALL is set so srun steps inside your command see them.

login_shell=True runs the script with #!/bin/bash -l ; shebangs of the form #!/usr/bin/env bash are left unchanged with a warning.

GPUs are requested with --gres=gpu:N ; use extra_directives for --gpus-per-node , --mem-per-cpu , --account and similar.

Multi-cluster ( -M , SLURM_CLUSTERS ) is unsupported.

See docs/API.md for the full API reference and error handling guide.

See docs/Development.md for build instructions, testing, and release process.

Extracted Entities

Platforms (2)