4. dxpy.utils Module

Utilities used in the DNAnexus execution environment and test harness.

dxpy.utils.exec_utils.run(function_name=None, function_input=None)[source]

Triggers the execution environment entry point processor.

Use this function in the program entry point code:

import dxpy

def hello(i):


This method may be used to invoke the program either in a production environment (inside the execution environment) or for local debugging (in the debug harness), as follows:

If the environment variable DX_JOB_ID is set, the processor retrieves the job with that ID from the API server. The job’s function field indicates the function name to be invoked. That function name is looked up in the table of all methods decorated with @dxpy.entry_point(‘name’) in the module from which run() was called, and the matching method is invoked (with the job’s input supplied as parameters). This is the mode of operation used in the DNAnexus execution environment.


The parameters function_name and function_input are disregarded in this mode of operation.

If the environment variable DX_JOB_ID is not set, the function name may be given in function_name; if not set, it is set by the environment variable DX_TEST_FUNCTION. The function input may be given in function_input; if not set, it is set by the local file job_input.json which is expected to be present.

The absence of DX_JOB_ID signals to run() that execution is happening in the debug harness. In this mode of operation, all calls to dxpy.bindings.dxjob.new_dxjob() (and higher level handler methods which use it) are intercepted, and run() is invoked instead with appropriate inputs.


Use this to decorate a DNAnexus execution environment entry point.


def hello(i):
class dxpy.utils.exec_utils.DXJSONEncoder(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, encoding='utf-8', default=None)[source]

Like json.JSONEncoder, but converts DXObject objects into dxlinks.

Constructor for JSONEncoder, with sensible defaults.

If skipkeys is false, then it is a TypeError to attempt encoding of keys that are not str, int, long, float or None. If skipkeys is True, such items are simply skipped.

If ensure_ascii is true (the default), all non-ASCII characters in the output are escaped with uXXXX sequences, and the results are str instances consisting of ASCII characters only. If ensure_ascii is False, a result may be a unicode instance. This usually happens if the input contains unicode strings or the encoding parameter is used.

If check_circular is true, then lists, dicts, and custom encoded objects will be checked for circular references during encoding to prevent an infinite recursion (which would cause an OverflowError). Otherwise, no such check takes place.

If allow_nan is true, then NaN, Infinity, and -Infinity will be encoded as such. This behavior is not JSON specification compliant, but is consistent with most JavaScript based encoders and decoders. Otherwise, it will be a ValueError to encode such floats.

If sort_keys is true, then the output of dictionaries will be sorted by key; this is useful for regression tests to ensure that JSON serializations can be compared on a day-to-day basis.

If indent is a non-negative integer, then JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0 will only insert newlines. None is the most compact representation. Since the default item separator is ‘, ‘, the output might include trailing whitespace when indent is specified. You can use separators=(‘,’, ‘: ‘) to avoid this.

If specified, separators should be a (item_separator, key_separator) tuple. The default is (‘, ‘, ‘: ‘). To get the most compact JSON representation you should specify (‘,’, ‘:’) to eliminate whitespace.

If specified, default is a function that gets called for objects that can’t otherwise be serialized. It should return a JSON encodable version of the object or raise a TypeError.

If encoding is not None, then all input strings will be transformed into unicode using that encoding prior to JSON-encoding. The default is UTF-8.

class dxpy.utils.exec_utils.DXExecDependencyInstaller(executable_desc, job_desc, logger=None)[source]

Installs dependencies specified by the job.

Dependencies are processed in the order specified in the bundledDepends, execDepends, and dependencies arrays of the runSpec hash (the former two are deprecated). Neighboring package dependencies of the same type are grouped.

  • executable_desc (dict) –

    The description of the executable of this job, which can be obtained in the response of the /executable-x/describe request. This dict must contain the following keys:

    • “runSpec”
  • job_desc (dict) –

    The description of this job, which can be obtained in the response of the /job-x/describe request. If executable_desc["runSpec"] has key “bundledDependsByRegion”, then this dict must contain the following keys:

    • “region”

Previous topic

3. dxpy.app_builder Module

Next topic

5. dxpy.api Module

This Page