API exchange mechanism

Pyrame provides an API exchange mechanism between modules in order to determine the existence of functions and list of their parameters on any module. The module_makefile Makefile provided on the root of Pyrame sources generates, at installation time a .api file for each Python module through the script gen_api.py. This file contains a list of the public functions of the module (as declared on the XML file), and their respective parameters.

Two Python modules are provided:

  1. getapi eases the implementation of the standard getapi_MODULE(). This is a function that sends a serialized API back as return value. It can be implemented, like:

    import getapi
    def init():
        global api; api = getapi.load_api(submod.getmyfile())
        def getapi_th_apt():

The code is inside the init() function to prevent gen_api.py from trying to read the .api file while generating it (gen_api imports the module).

The serialized API is a semicolon-separated string with the prototypes of the public functions in the module. Each function must be composed of its name, a colon and list comma-separated arguments. For example

  1. The apipools module allows to keep a pool of APIs in memory and to parse the serialized API. The pool provides functions like: get_api (from the pool) and is_present (in the pool). See the its API below. A JavaScript implementation of apipools also exists.

apipools API

class apipools.api_pool[source]

API pool

add_api_from_string(module_name, str_api)[source]

Add API to pool from string. semicolons between functions; colon between function name and parameters; comma between parameters. Example:



Add API to pool from another module

add_api_from_file(module_name, file_name)[source]

Add API to pool from file. newlines or semicolons between functions; colon between function name and parameters; comma between parameters. Example:

get_voltage_ps:ps_id,channel get_current_ps:ps_id,channel ...

get_api(module_name, func_name)[source]

Find func_name of module_name in pool and return a dictionary with keys model, function and args, where the two first are strings and the latter is a list of strings. If not found, return -1


Check if the API of module_name is present in the pool