Loading

Uli SDK

Python Binding

15.Python Binding

The app generator, described earlier, also generates comp app library and Python Binding to the comp app library. The generated Python class allows access to the comp app through the comp app library.

The app generator also generates demo Python app, that shows how the Python Binding can be used.

15.1 Python Class of the binding

The generated Python class name is in camel style of the app name with the first letter in upper case. The class has the following member functions:

  • __init__, takes one argument, working_dir, that specifies where to locate the .cfg, .json, and README files of this application.
  • initialize, initializes the runtime environment for this app, such as getting runtime options from the .cfg file and creating the logger.
  • Instantiate, creates needed services and comps.
  • set_up_action, loads parameters and setups services and comps.
  • get_params, saves parameters of services to the .json file.
  • start_up_action, starts up services and comps of this app.
  • shutdown, shuts down the services and comps of this app.
  • destroy, deletes services and comps of this app.
  • get_data, obtains data from this app. This function needs an url string, that specifies where to retrieve the data. Get_data returns string representing the JSON object of the retrieved data. The format is:

      {

      “name-of-the data”:

      {

      // JSON object

      }

      }

  • set_data, sets data in the comp app. This function needs two arguments, url string, that specifies the location of the data to set, and a JSON serialized string of data to set.

      {

      “name-of-the data”:

      {

      // JSON object

      }

      }

      The set_data function returns 1 if set data succeeded, otherwise 0.