Macros#

class dataikuapi.dss.macro.DSSMacro(client, project_key, runnable_type, definition=None)

A macro on the DSS instance.

Important

Do not instantiate directly, use dataikuapi.dss.project.DSSProject.get_macro()

get_definition()

Get the macro definition.

Note

The adminParams field is empty unless the authentication of the API client covers admin rights.

Returns:

the definition (read-only), as a dict. The fields mimic the contents of the runnable.json file of the macro.

Return type:

dict

run(params=None, admin_params=None, wait=True)

Run the macro from the project

Note

If the authentication of the api client does not have admin rights, admin params are ignored.

Usage example:

# list all datasets on a connection.            
connection_name = 'filesystem_managed'
macro = project.get_macro('pyrunnable_builtin-macros_list-datasets-using-connection')
run_id = macro.run(params={'connection': connection_name}, wait=True)
# the result of this builtin macro is of type RESULT_TABLE
result = macro.get_result(run_id, as_type="json")
for record in result["records"]:
    print("Used by %s" % record[0])
Parameters:
  • params (dict) – parameters to the macro run (defaults to {})

  • admin_params (dict) – admin parameters to the macro run (defaults to {})

  • wait (boolean) – if True, the call blocks until the run is finished

Returns:

a run identifier to use with abort(), get_status() and get_result()

Return type:

string

abort(run_id)

Abort a run of the macro.

Parameters:

run_id (string) – a run identifier, as returned by run()

get_status(run_id)

Poll the status of a run of the macro.

Note

Once the run is done, when get_result() is called, the run ceases to exist. Afterwards get_status() will answer that the run doesn’t exist.

Parameters:

run_id (string) – a run identifier, as returned by run()

Returns:

the status, as a dict. Whether the run is still ongoing can be assessed with the running field.

Return type:

dict

get_result(run_id, as_type=None)

Retrieve the result of a run of the macro.

Note

If the macro is still running, an Exception is raised.

The type of the contents of the result to expect can be checked using get_definition(), in particular the “resultType” field.

Parameters:
  • run_id (string) – a run identifier, as returned by run() method

  • as_type (string) – if not None, one of ‘string’ or ‘json’. Use ‘json’ when the type of result advertised by the macro is RESULT_TABLE or JSON_OBJECT.

Returns:

the contents of the result of the macro run, as a file-like is as_type is None; as a str if as_type is “string”; as an object if as_type is “json”.

Return type:

file-like, or string