extensions

This module hosts all the extension functions and classes created via SDK.

The function graphlab.extensions.ext_import() is used to import a toolkit module (shared library) into the workspace. The shared library can be directly imported from a remote source, e.g. http, s3, or hdfs. The imported module will be under namespace graphlab.extensions.

Alternatively, if the shared library is local, it can be directly imported using the python import statement. Note that graphlab must be imported first.

graphlab.extensions.ext_import(soname, module_subpath='')

Loads a graphlab toolkit module (a shared library) into the gl.extensions namespace.

Toolkit module created via SDK can either be directly imported, e.g. import example or via this function, e.g. graphlab.ext_import("example.so"). Use ext_import when you need more namespace control, or when the shared library is not local, e.g. in http, s3 or hdfs.

Parameters:

soname : string

The filename of the shared library to load. This can be a URL, or a HDFS location. For instance if soname is somewhere/outthere/toolkit.so The functions in toolkit.so will appear in gl.extensions.toolkit.*

module_subpath : string, optional

Any additional module paths to prepend to the toolkit module after it is imported. For instance if soname is somewhere/outthere/toolkit.so, by default the functions in toolkit.so will appear in gl.extensions.toolkit.*. However, if I module_subpath=”somewhere.outthere”, the functions in toolkit.so will appear in gl.extensions.somewhere.outthere.toolkit.*

Returns:

out : a list of functions and classes loaded.

Examples

For instance, given a module which implements the function “square_root”,

#include <cmath>
#include <graphlab/sdk/toolkit_function_macros.hpp>
double square_root(double a) {
  return sqrt(a);
}

BEGIN_FUNCTION_REGISTRATION
REGISTER_FUNCTION(square_root, "a");
END_FUNCTION_REGISTRATION

compiled into example.so

>>> graphlab.ext_import('example1.so')
['example1.square_root']
>>> graphlab.extensions.example1.square_root(9)
3.0

We can customize the import location with module_subpath which can be used to avoid namespace conflicts when you have multiple toolkits with the same filename.

>>> graphlab.ext_import('example1.so', 'math')
['math.example1.square_root']
>>> graphlab.extensions.math.example1.square_root(9)
3.0

The module can also be imported directly, but graphlab must be imported first. graphlab will intercept the module loading process to load the toolkit.

>>> import graphlab
>>> import example1 #searches for example1.so in all the python paths
>>> example1.square_root(9)
3.0