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()
- 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. - The we create an instance of the
AireInsights
class - We then use the
module()
decorator to tell AireInsights about this module and under which name to find it. - 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 themy_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.