Hello world example

For simplicity we will start with a classical hello world example, implementing a very basic query extension.

  1. Add a file HelloWorldExample.py in the folder <root>\Query.

  2. Add the following content to the HelloWorldExample.py file:

import omnifi
from omnifi.data import *

class QueryPlugin:
    
    def __init__(self, system, user, password):
        pass

    def GetParameters(self):
        return (list());

    def GetMetadata(self, arguments):
        metadata = MetadataCollection()
        metadata.add(Metadata("hello_world", "Hello World", DataType.string))
        return (metadata);

    def ExecuteQuery(self, arguments, columnSchema):
        schema = self.GetMetadata(None).ToColumnSchema()
        queryResultWriter = QueryResultWriter(schema.Datasets)
        row = list()
        row.append("I am here!");
        queryResultWriter.AddRowValues(row)
        return (queryResultWriter.GetQueryResult())

if __name__ == "__main__":
    plugin = QueryPlugin("system", "user", "pass")
    wrapper = QueryPluginWrapper(plugin)
    schema = plugin.GetMetadata(None).ToColumnSchema();
    jsonResult = wrapper.ExecuteQuery("[]", ColumnSchema_(many=False).dumps(schema))
    print(jsonResult)

1.Add a file HelloWorldExample.pyplugin in the folder <root>\Query.

  1. Add the following content to the pyplugin file:
Name=Hello World
Comment=My first plugin
Module=HelloWorldExample
PythonEnv=default
  1. The new extension is now available when configuring a new extension query in OmniFi, and we can use it to create a report!
605