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 executable. 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 instances 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.
Python plug-ins and correlator persistence
Since Python plug-ins provide no way to persist data stored inside the plug-in, or in chunks from a Python plug-in, it is not permitted to import a Python plug-in from a persistent monitor or to use an event which imports a Python plug-in from a persistent monitor. You can use Python plug-ins from non-persistent monitors in a persistent correlator.