PythonResult

class hailtop.batch.resource.PythonResult(value, source)

Bases: hailtop.batch.resource.Resource, str

Class representing a result from a Python job.

Examples

Add two numbers and then square the result:

def add(x, y):
    return x + y

def square(x):
    return x ** 2

b = Batch()
j = b.new_python_job(name='add')
result = j.call(add, 3, 2)
result = j.call(square, result)
b.write_output(result.as_str(), 'output/squared.txt')
b.run()

Notes

All PythonResult are temporary Python objects and must be written to a permanent location using Batch.write_output() if the output needs to be saved. In most cases, you’ll want to convert the PythonResult to a JobResourceFile in a human-readable format.

Methods

as_json

Convert a Python result to a file with a JSON representation of the object.

as_repr

Convert a Python result to a file with the repr representation of the object.

as_str

Convert a Python result to a file with the str representation of the object.

source

Get the job that created the Python result.

as_json()

Convert a Python result to a file with a JSON representation of the object.

Examples

def add(x, y):
    return {'result': x + y}

b = Batch()
j = b.new_python_job(name='add')
result = j.call(add, 3, 2)
b.write_output(result.as_json(), 'output/add.json')
b.run()
Return type

JobResourceFile

Returns

JobResourceFile – A new resource file where the contents are a Python object that has been converted to JSON.

as_repr()

Convert a Python result to a file with the repr representation of the object.

Examples

def add(x, y):
    return x + y

b = Batch()
j = b.new_python_job(name='add')
result = j.call(add, 3, 2)
b.write_output(result.as_repr(), 'output/add.txt')
b.run()
Return type

JobResourceFile

Returns

JobResourceFile – A new resource file where the contents are the repr representation of a Python object.

as_str()

Convert a Python result to a file with the str representation of the object.

Examples

def add(x, y):
    return x + y

b = Batch()
j = b.new_python_job(name='add')
result = j.call(add, 3, 2)
b.write_output(result.as_str(), 'output/add.txt')
b.run()
Return type

JobResourceFile

Returns

JobResourceFile – A new resource file where the contents are the str representation of a Python object.

source()

Get the job that created the Python result.

Return type

PythonJob