Apama 10.3.1 | Apama Documentation | Developing Apama Applications | Developing EPL Plug-ins | Writing EPL Plug-ins in Python | Using Python plug-ins
 
Using Python plug-ins
After you have created an EPL plug-in in Python, you must configure it in a Python-enabled correlator so that it is available for use in your Apama applications. Applications that use the plug-in also need to import the plug-in by name.
Enabling Python support in the correlator
To enable Python support in the correlator, you must use the --python command-line option of the correlator tool. See also Starting the correlator.
You can also enable Python support using the YAML configuration file for the correlator:
correlator:
pythonSupport: true
If you are using a standard Apama installation, a copy of Python is provided in your installation. This Python will be used by default. If you are using the core installer, or wish to use a different version of Python, then you will need to override the location of your Python installation. You can do this by setting the AP_PYTHONHOME environment variable.
Adding a Python plug-in to the correlator
EPL plug-ins written in Python are made available to EPL via the YAML configuration file for the correlator (see also Configuring the correlator).
To configure a specific Python plug-in once you have enabled Python support, you need to add an eplPlugins section to the configuration file:
eplPlugins:
myPluginName:
pythonFile: ${PARENT_DIR}/plugin.py
class: PluginClass
pythonPath:
- ${PARENT_DIR}/dependencies
config:
key: value
The plug-in name is an arbitrary string which will be used to refer to the plug-in from EPL. The following configuration options are available for each plug-in:
Configuration option
Description
pythonFile
Required. The path to the Python file which contains the plug-in.
class
Required. The name of the class in the file which exposes methods decorated with EPLAction.
pythonPath
Optional. A single string or list of strings containing locations to add to the Python path.
config
Optional. An arbitrary dictionary which will be available to the plug-in via the self.getConfig() method.
You can create multiple instance of the same plug-in with different names.
Importing a Python plug-in to EPL
Once a Python plug-in has been configured, it is available for import using the plug-in name defined in the configuration file. The correlator will make available all methods decorated with the EPLAction decorator to be called directly from EPL. For example, the following code imports a plug-in named TestPlugin and calls its dosomething method:
monitor m {
import "TestPlugin" as test;
action onload()
{
test.dosomething();
}
}
If the plug-in has been incorrectly configured, the correlator will try to load the plug-in as a C++ plug-in and may give an error such as Error opening plug-in library libTestPlugin.so: libTestPlugin.so: cannot open shared object file: No such file or directory. If this happens and you were trying to load a plug-in written in Python, then check the name in your configuration file and make sure that it matches the name you are trying to import.

Copyright © 2013-2019 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.