Skip to main content

Python API Reference

Classes

qb.QBObject

PurposeBase class for Qube Python API objects.
Prototypeclass QBObject(object)
ParametersBase for derived classes (Job, Subjob, Work, Host, etc.).
ResultInitialized object with automatic attribute handling.
CommentsProvides property access and automatic dictionary conversion.

Example

from qb import QBObject
class MyObj(QBObject): pass
o = MyObj({'field': 'value'})
print(o.field)

qb.Subjob

PurposeRepresents an individual subjob belonging to a parent job.
Prototypeclass Subjob(QBObject)
ParametersdataDictionary or Subjob instance for initialization.
ResultSubjob object.
CommentsContains fields such as id, status, work, agenda, etc.

Example

sub = qb.Subjob({'id': '250.0', 'status': 'running'})
print(sub.id, sub.status)

qb.Work

PurposeRepresents a single work item or frame.
Prototypeclass Work(QBObject)
ParametersdataDictionary or Work instance to initialize.
ResultWork object.
CommentsUsed to define tasks (frames) within a subjob agenda.

Example

work = qb.Work({'name': 'frame_1', 'status': 'pending'})
print(work.name, work.status)

qb.Host

PurposeRepresents a single worker host.
Prototypeclass Host(QBObject)
ParametersdataDictionary or Host instance to initialize.
ResultHost object.
CommentsContains fields such as name, address, state, cluster, groups, and resources.

Example

h = qb.Host({'name': 'worker01', 'state': 'running'})
print(h.name, h.state)

qb.Job

PurposeContainer class for Qube job properties. Represents jobs submitted by the user.
Prototypeclass Job(QBObject)
ParametersdataDictionary or existing Job used to initialize properties.
nameOptional job name.
prototypeOptional job type.
packageOptional package dictionary.
ResultJob object.
CommentsJobs contain fields like id, name, status, priority, package, requirements, hosts, subjobs, etc.

Example

from qb import Job
myjob = Job(name='example', prototype='cmdline', package={'cmdline': 'echo hello'})
qb.submit(myjob)

Functions

qb.archivejob

PurposeSaves a Job to a file in the specified format.
Prototypeqb.archivejob(filename, job, format=QB_API_XML)
ParametersfilenamePath to the output file.
jobJob object or dictionary to save.
formatFormat type. Options: QB_API_XML (default) or QB_API_BINARY.
ResultFile size in bytes (integer).
CommentsUse with qb.recoverjob() to reload saved jobs.

Example

myjob = qb.jobinfo(id=277)[0]
qb.archivejob('c:/myjob.xml', myjob)

qb.bannedworkers

PurposeRetrieves a list of banned worker hosts.
Prototypeqb.bannedworkers()
ParametersNone.
ResultList of Host objects with limited info (MAC, IP, hostname).

Example

banned = qb.bannedworkers()
for w in banned:
print(f"name={w['name']}, mac={w['macaddress']}, ip={w['address']}")

qb.block

PurposeSets job state to blocked.
Prototypeqb.block(jobid, *extraJobids)
ParametersjobidPrimary job ID to block. Additional IDs may be specified.
ResultList of affected subjob IDs (['jobid.subjobid']).
CommentsSee also qb.unblock().

Example

qb.block(250)

qb.blockwork

PurposeSets specified pending frames or tasks to a blocked state.
Prototypeqb.blockwork(workid, *extraWorkids)
ParametersworkidWork identifier in format 'jobid:workname'. Additional IDs may be specified.
ResultList of affected work items (['jobid:workname']).
CommentsSee also qb.unblockwork().

Example

qb.blockwork('250:0', '250:1')

qb.bottom

PurposeMoves specified jobs to the end of the execution queue.
Prototypeqb.bottom(jobid, *extraJobids)
ParametersjobidPrimary job ID to affect. Additional IDs may be specified.
ResultList of affected job IDs.
CommentsSee also qb.top() and qb.joborder().

Example

qb.bottom(250)

qb.Callback

PurposeContainer for Qube Callback properties. Executes an action when triggered by an event.
Prototypeclass Callback(QBObject)
ParametersdataDictionary or Callback instance with initialization properties (optional).
ResultCallback object.
CommentsTriggers execute on job or work events such as complete, failed, killed, running, waiting, etc.

Example

from qb import Callback

cb = Callback({
"triggers": ["complete-job-self"],
"code": "print('Job complete!')",
"language": "python",
"user": "admin"
})

qb.genchunks

PurposeGenerates a work agenda divided into chunks based on a frame range.
Prototypeqb.genchunks(chunksize, range, *extraRanges, **kwargs)
ParameterschunksizeNumber of frames per chunk.
rangeFrame range string (e.g., "1-100").
binarySort(Keyword) Perform binary sort of frames. Default: False.
ResultList of Work objects.
CommentsAutomatically removes duplicate frames.

Example

import qb
frames = qb.genchunks(10, '1-100')
frames = qb.genchunks(5, '-100--10')

qb.genframes

PurposeGenerates a work agenda of individual frames based on a range list.
Prototypeqb.genframes(range, *extraRanges, **kwargs)
ParametersrangeFrame range string (e.g., "1-10x2").
binarySort(Keyword) Perform binary sort of frames. Default: False.
removeDuplicates(Keyword) Remove duplicates. Default: True.
ResultList of Work objects.
CommentsEquivalent to qb.genchunks() but without chunk grouping.

Example

import qb
frames = qb.genframes('1-10x2')
frames = qb.genframes('-10--1x2')

qb.genpartitions

PurposeSplits frame ranges into a specified number of partitions.
Prototypeqb.genpartitions(numPartitions, range, *extraRanges, **kwargs)
ParametersnumPartitionsNumber of partitions to create.
rangeFrame range string.
binarySort(Keyword) Perform binary sort. Default: False.
ResultList of Work objects.
CommentsAutomatically removes duplicate frames.

Example

qb.genpartitions(2, '1-10')
qb.genpartitions(3, '-100--1')

qb.hist

PurposeRetrieves job or subjob history.
Prototypeqb.hist(jobid, *extraJobids)
ParametersjobidJob ID or 'jobid.subjobid' format.
ResultList of history dictionaries with fields: comment, stamp, jobid, subid, workid.
CommentsWorks for both jobs and subjobs.

Example

qb.hist(250)      # all history for job 250
qb.hist('250.0') # history for subjob 0 of job 250

qb.hostinfo

PurposeRetrieves information from specified hosts.
Prototypeqb.hostinfo(fields=[], filters={}, name=None, state=None, subjobs=False)
ParametersfieldsList of additional info to retrieve.
filtersDictionary of host filters.
nameHost name or list of names.
stateHost state or list of states.
subjobsWhether to include subjob info.
ResultList of Host objects.
CommentsHost info won�t include subjobs unless requested.

Example

hosts = qb.hostinfo()
hosts = qb.hostinfo(name='myhost')
hosts = qb.hostinfo(state='down')
hosts = qb.hostinfo(subjobs=True)

qb.hostorder

PurposeLists hosts in the order likely to run a given job.
Prototypeqb.hostorder(id=None)
ParametersidJob ID of interest.
ResultList of Host objects in dispatch order.

Example

hosts = qb.hostorder(id=1234)

qb.JobTallyValidator

PurposeValidates a job�s todotally and cpustally dictionaries.
Prototypeclass JobTallyValidator(dict)
Parameterstally_dictDictionary to validate.
ResultBoolean.
CommentsEnsures all tally counts are non-negative integers.

Example

valid = qb.JobTallyValidator.validate(job['cpustally'])

qb.JobValidator

PurposeEnsures a qb.Job instance is well-formed.
Prototypeclass JobValidator(object)
ParametersjobDictionary representing a job.
agendaIf True, validate agenda items.
subjobsIf True, validate subjobs.
verbosePrint names of invalid fields if True.
ResultBoolean.
CommentsStops at the first invalid field. Provides per-type validation (int, str, dict, list).

Example

qb.JobValidator.validate(job, agenda=True, verbose=True)

qb.kill

PurposeKills specified jobs or subjobs.
Prototypeqb.kill(jobid, *extraJobids)
ParametersjobidJob ID or jobid.subjobid string.
ResultList of affected subjobs.
CommentsUse to terminate jobs immediately.

Example

qb.kill(250)
qb.kill('250.0')

qb.killwork

PurposeKills specific frames or tasks.
Prototypeqb.killwork(workid, *extraWorkids)
ParametersworkidWork specifier like '250:0'.
ResultList of affected tasks/work items.
CommentsSimilar to qb.kill(), but operates on frames.

Example

qb.killwork('250:0')
qb.killwork('250:0', '250:1')

qb.migrate

PurposeInterrupts running jobs and forces them to run on a different host.
Prototypeqb.migrate(jobid, *extraJobids)
ParametersjobidJob ID or 'jobid.subjobid'.
ResultList of affected subjobs.

Example

qb.migrate(250)
qb.migrate('250.1')

qb.modify

PurposeModifies parameters of active jobs.
Prototypeqb.modify(modifyParamDict, jobid, *extraJobids)
ParametersmodifyParamDictDictionary of parameters to change.
jobidJob ID(s) to modify.
ResultList of affected job IDs.
CommentsOnly incomplete/active jobs can be modified.

Example

qb.modify({'priority': 123}, 250)

qb.preempt

PurposeForces running jobs back to pending state after completing their current agenda item.
Prototypeqb.preempt(jobid, *extraJobids)
ParametersjobidJob ID or subjob ID(s) to preempt.
ResultList of affected subjob IDs.
CommentsReleases hosts gracefully if the job type supports an agenda.

Example

qb.preempt(250)

qb.rangechunk

PurposeSplits frame ranges into chunks of a specified length.
Prototypeqb.rangechunk(chunksize, range, *extraRanges, **kwargs)
ParameterschunksizeNumber of frames per chunk.
rangeFrame range string (e.g., "1-100").
binarySort(Keyword) Perform binary sort. Default: False.
ResultList of range strings.

Example

qb.rangechunk(5, '1-20')
qb.rangechunk(5, '-100--1', binarySort=True)

qb.rangejoin

PurposeConverts a list of frame numbers into a range format string.
Prototypeqb.rangejoin(frames)
ParametersframesList of integers.
ResultRange string (e.g., "1-10x2").

Example

qb.rangejoin([1, 2, 3, 4, 5])
# Returns "1-5"
qb.rangejoin([1, 3, 5, 7, 9, 11, 13])
# Returns "1-13x2"

qb.rangeorder

PurposeConverts frame ranges into a list of frame numbers ordered by a mode.
Prototypeqb.rangeorder(mode, range)
ParametersmodeSort order mode: binary, reverse, rawbinary, ascend, descend.
rangeFrame range string.
ResultList of frame numbers.

Example

qb.rangeorder('ascend', '1-10')
qb.rangeorder('binary', '1-10x2')

qb.rangesplit

PurposeExpands frame ranges into a list of individual frame numbers.
Prototypeqb.rangesplit(range, *extraRanges, **kwargs)
ParametersrangeFrame range string.
binarySort(Keyword) Perform binary sort. Default: False.
removeDuplicates(Keyword) Remove duplicates. Default: True.
ResultList of frame numbers.

Example

qb.rangesplit("1-10x2")
qb.rangesplit("1-5x2,10-12")

qb.remove

PurposeRemoves specified jobs from the Supervisor database cache.
Prototypeqb.remove(jobid, *extraJobids)
ParametersjobidJob ID or IDs to remove.
ResultList of affected job IDs.

Example

qb.remove(250)

qb.requeue

PurposeResets failed, complete, or killed jobs to an initial blocked state.
Prototypeqb.requeue(jobid, *extraJobids)
ParametersjobidJob ID(s) to requeue.
ResultList of affected subjob IDs.
CommentsSimilar to qb.retry(), but requeues to a blocked state instead of pending.

Example

qb.requeue(250)

qb.requeuework

PurposeResets terminal frames or tasks (failed, killed, etc.) to a blocked state.
Prototypeqb.requeuework(workid, *extraWorkids)
ParametersworkidWork specifier like '250:0'.
ResultList of affected work items.

Example

qb.requeuework('250:0')
qb.requeuework('250:25-29')

qb.resource

PurposeQueries the Supervisor for resource states.
Prototypeqb.resource(resources)
ParametersresourcesDictionary describing resource keys and values.
ResultDictionary of resource state information.

Example

resources = qb.resource({'memory': '>=16GB', 'cpus': '>=4'})

qb.resume

PurposeResumes suspended jobs.
Prototypeqb.resume(jobid, *extraJobids)
ParametersjobidJob ID(s) to resume.
ResultList of affected subjob IDs.

Example

qb.resume(250)

qb.retry

PurposeResets terminal jobs (failed, killed, etc.) to a pending state.
Prototypeqb.retry(jobid, *extraJobids)
ParametersjobidJob ID(s) to retry.
ResultList of affected subjob IDs.
CommentsSimilar to qb.requeue(), but moves jobs to pending instead of blocked.

Example

qb.retry(250)

qb.retrywork

PurposeResets terminal frames or tasks to a pending state.
Prototypeqb.retrywork(workid, *extraWorkids)
ParametersworkidWork specifier like '250:0'.
ResultList of affected work items.

Example

qb.retrywork('250:0')
qb.retrywork('250:0', '250:1')

qb.stderr

PurposeRetrieves job STDERR log output.
Prototypeqb.stderr(jobid, *extraJobids)
ParametersjobidJob ID or subjob ID(s).
ResultList of dictionaries with keys: data, jobid, subid.
CommentsEach dictionary contains the stderr log text for the specified subjob(s).

Example

logs = qb.stderr(250)
for entry in logs:
print(entry['data'])

qb.stdout

PurposeRetrieves job STDOUT log output.
Prototypeqb.stdout(jobid, *extraJobids)
ParametersjobidJob ID or subjob ID(s).
ResultList of dictionaries with keys: data, jobid, subid.
CommentsSimilar to qb.stderr() but returns standard output logs.

Example

logs = qb.stdout(250)
for entry in logs:
print(entry['data'])

qb.submit

PurposeSubmits a new job to the Supervisor.
Prototypeqb.submit(job)
ParametersjobJob object or dictionary containing job parameters. Must include "prototype".
ResultJob dictionary with ID assigned.
CommentsReturns a reference to the submitted job with an assigned ID.

Example

job = {
"name": "myjob",
"priority": 12433,
"cluster": "/project/rnd",
"requirements": "host.name == qb003 and host.os eq Linux",
"prototype": "cmdline",
"package": {"cmdline": "sleep 100"}
}
qb.submit(job)

qb.submitcallback

PurposeSubmits a job callback to execute when a specific event occurs.
Prototypeqb.submitcallback(callback)
ParameterscallbackDictionary or Callback object with callback data.
ResultList of callback IDs.
CommentsUse to register event-driven actions such as email alerts or post-job scripts.

Example

cb = {
"triggers": ["complete-job-self"],
"code": "print('Job completed!')",
"language": "python",
"user": "admin"
}
qb.submitcallback(cb)

qb.suspend

PurposeSends the suspend signal to running jobs.
Prototypeqb.suspend(jobid, *extraJobids)
ParametersjobidJob ID(s) to suspend.
ResultList of affected subjob IDs.

Example

qb.suspend(250)

qb.top

PurposeMoves jobs to the top of the execution queue.
Prototypeqb.top(jobid, *extraJobids)
ParametersjobidJob ID(s) to move.
ResultList of affected job IDs.

Example

qb.top(250)

qb.unblock

PurposeUnblocks jobs so they can

qb.ping

PurposeTests connectivity to the Qube Supervisor and optionally returns host details.
Prototypeqb.ping(host=None, port=None, timeout=10)
ParametershostHostname or IP address of the Supervisor. Defaults to value from environment (QB_SUPERVISOR).
portTCP port number (optional). Defaults to Supervisor�s configured port.
timeoutTimeout in seconds (default: 10).
ResultBoolean True if Supervisor responds; False otherwise.
CommentsUse this to verify Supervisor status before submitting or querying jobs.

Example

# Check connectivity using default Supervisor
if qb.ping():
print("Supervisor is alive")

# Ping a specific host and port
if qb.ping(host='qubesup.local', port=5001):
print("Supervisor responded on port 5001")

qb.info

PurposeReturns detailed information about the Qube Supervisor.
Prototypeqb.info()
ParametersNone.
ResultDictionary containing Supervisor information such as version, platform, license status, database connection, and configuration paths.
CommentsUseful for diagnostics or environment verification.

Example

info = qb.info()
print(f"Supervisor: {info['supervisor']}, Version: {info['version']}")

qb.jobinfo

PurposeRetrieves job information from the Supervisor.
Prototypeqb.jobinfo(fields=[], filters={}, id=None, status=None, agenda=False, subjobs=False, callbacks=False, updatedAfter=None, updatedBefore=None, submittedAfter=None, submittedBefore=None, minid=None, maxid=None, limit=None, orderby=None)
ParametersfieldsAdditional fields to include (agenda, subjobs, callbacks).
filtersDictionary of job filters (id, name, user, status, priority, cluster, prototype, etc.).
idFilter shortcut for job ID(s).
statusFilter shortcut for job status (complete, failed, running, etc.).
agenda, subjobs, callbacksBoolean flags to include detailed info.
updatedAfter / updatedBeforeFilter by last update time (epoch).
submittedAfter / submittedBeforeFilter by submission time (epoch).
limitMaximum number of results.
orderbySort order string (e.g., "id DESC").
ResultList of Job dictionaries.
CommentsEquivalent to qb.jobinfo() in Perl. Returns all jobs if no filters are specified.

Example

jobs = qb.jobinfo(status='running')
for j in jobs:
print(j['id'], j['name'])

qb.joborder

PurposeReturns a list of jobs eligible to run on a specified host.
Prototypeqb.joborder(host)
ParametershostHost name.
ResultList of Job dictionaries sorted by dispatch order.
CommentsUse to test which jobs would run on a given worker.

Example

eligible = qb.joborder('worker01')
for j in eligible:
print(j['id'], j['priority'])

qb.log

PurposeRetrieves combined job log output (stdout and stderr).
Prototypeqb.log(jobid, *extraJobids)
ParametersjobidJob ID or list of job IDs.
ResultList of dictionaries with keys: data, jobid, subid.
CommentsCombines both STDOUT and STDERR for convenience.

Example

logs = qb.log(250)
for l in logs:
print(l['data'])

qb.ping

PurposeTests connectivity to the Qube Supervisor and optionally returns host details.
Prototypeqb.ping(host=None, port=None, timeout=10)
ParametershostHostname or IP of Supervisor (defaults to QB_SUPERVISOR).
portTCP port number. Defaults to configured port.
timeoutTimeout in seconds (default: 10).
ResultBoolean True if Supervisor responds, False otherwise.
CommentsUse to check Supervisor availability before making API calls.

Example

if qb.ping():
print("Supervisor is alive")

qb.version

PurposeReturns the version of the Qube Supervisor and API.
Prototypeqb.version()
ParametersNone.
ResultDictionary with version strings for API, Supervisor, and database schema.

Example

v = qb.version()
print(f"API: {v['api']}, Supervisor: {v['supervisor']}")

qb.workerinfo

PurposeRetrieves information about worker hosts registered with the Supervisor.
Prototypeqb.workerinfo(fields=[], filters={}, name=None, state=None)
ParametersfieldsAdditional data fields to include.
filtersDictionary of filters.
nameFilter by host name(s).
stateFilter by host state(s).
ResultList of Host dictionaries.

Example

workers = qb.workerinfo(state='running')
for w in workers:
print(w['name'], w['state'])

qb.workorder

PurposeReturns the works scheduled to run on a specific host.
Prototypeqb.workorder(host)
ParametershostHost name.
ResultList of work dictionaries.
CommentsUse to view queued or pending tasks for a worker.

Example

work = qb.workorder('worker01')
for w in work:
print(w['jobid'], w['agenda'])