Cache calculations in Gramex

It’s a bad idea to run calculations after loading cached data.

# This code is wrong:
data =, 'csv')
result = calculations(data)

There is no point re-computing the data unless data_file has changed. Instead, supports a transform= parameter. Do the following:

result =, 'csv', transform=calculations)

This will re-run calculations only if the data_file has changed.

You can return multiple calculations, including the dataset, either as a tuple or as a dict. For example:

# Return multiple calculations as a tuple
data, calc1, calc2 =, 'csv', transform=calculations)


# Return a dict of calculations
result =, 'csv', transform=calculations)
result['data']     # has the data
result['calc1']    # has the first calculation results, and so on