Python SDK

The Python SDK allows you to create your own module for AireInsights using python. AireInsights communicates with the modules using a message broker (by defualt this is RabbitMQ). Let’s assume we have a python function that does some fancy data processing called my_processing_function, the following snipped shows how this function can be used to create an AireInsights module.

from aireinsights import AireInsights

from my_package import my_processing_function

connection_string = "amqp://user:pass@localhost:5672/aireinsights"

ai = AireInsights(connection_string)

@ai.module('demo-module')
def my_module(step_name, body, context):
    return my_processing_function(body, context) 

if __name__ == '__main__':
    ai.run()
  1. The connection_string is the url to connect the module to the core AireInsights service. We recommend to pass this in as an environment variable as it includes the password for the AireInsights message broker.
  2. The we create an instance of the AireInsights class
  3. We then use the module() decorator to tell AireInsights about this module and under which name to find it.
  4. The function receives the name of the step that calls this module (step_name), the data sent to the module as a string in the second argument (body) and the module context (context). The module context can be defined as part of the step definition in the pipeline and allows to use the same module using a different configuration when called from different steps. This function will do all the processing of the data (in our casse it calls the my_processing_function to do that) and then it returns the module output as a string, in the step definition we can specify as what kind of data format this string should be interpreted as.

Related Articles