Outputs API

This module contains class that will be used by the measure decorator or the Measurement.export method to export recorded measurement

example with the measure decorator:

output_instance = pyRAPL.outputs.XXXOutput(...)

def foo():

example with the Measurement.export function:

measure = pyRAPL.Measurement('label')
output_instance = pyRAPL.outputs.XXXOutput(...)

You can define your one output by inherit from the Output class and implements the add method. This method will receive the measured energy consumption data as a Result instance and must handle it.

For example, the PrintOutput.add method will print the Result instance.

Abstract Class

class pyRAPL.outputs.Output

Abstract class that represent an output handler for the Measurement class


Handle the object Result


result (Result) – data to handle

class pyRAPL.outputs.BufferedOutput

Use a buffer to batch the output process

The method add add data to the buffer and the method save outputs each data in the buffer. After that, the buffer is flushed

Implement the abstract method _output_buffer to define how to output buffered data


Abstract method

Output all the data contained in the buffer


data – data to output


Add the given data to the buffer


result – data that must be added to the buffer

property buffer

Return the buffer content

Return type



a list of all the Result instances contained in the buffer


Output each data in the buffer and empty the buffer


class pyRAPL.outputs.PrintOutput(raw=False)

Output that print data on standard output


raw (bool) – if True, print the raw result class to standard output. Otherwise, print a fancier representation of result


print result on standard output


result (Result) – data to print

class pyRAPL.outputs.CSVOutput(filename, separator=', ', append=True)

Write the recorded measure in csv format on a file

if the file already exists, the result will be append to the end of the file, otherwise it will create a new file.

This instance act as a buffer. The method add add data to the buffer and the method save append each data in the buffer at the end of the csv file. After that, the buffer is flushed

  • filename (str) – file’s name were the result will be written

  • separator (str) – character used to separate columns in the csv file

  • append (bool) – Turn it to False to delete file if it already exist.

class pyRAPL.outputs.MongoOutput(uri, database, collection)

Store the recorded measure in a MongoDB database

This instance act as a buffer. The method add add data to the buffer and the method save store each data in the buffer in the MongoDB database. After that, the buffer is flushed

  • uri (str) – uri used to connect to the mongoDB instance

  • database (str) – database name to store the data

  • collection (str) – collection name to store the data

class pyRAPL.outputs.DataFrameOutput

Append recorded data to a pandas Dataframe


Append recorded data to the pandas Dataframe


result – data to add to the dataframe

property data

Return the dataframe that contains the recorded data

Return type



the dataframe