Method signatures and types
Only methods which take arguments and return values which can be converted into EPL types can be used in an EPL plug-in written in Python. For each action, you must provide the EPL signature for the method to the EPLAction decorator. Typing is not strictly enforced by Python, but is enforced by EPL when being used as a plug-in. EPL method signatures take the following forms:
action<integer>
action<sequence<string>, integer>
action<> returns integer
action<dictionary<string, string>, string> returns string
EPL to Python type conversion
EPL type | Python type | Notes |
integer | integer | |
string | unicode | |
float | float | |
boolean | bool | |
decimal | decimal.Decimal | |
chunk | any type | Maps to an arbitrary Python object. |
dictionary<T> | dict | All keys must be the same type. All values must be the same type. |
sequence<T> | list | All elements must be the same type. |
context | apama.eplplugin.Context | |
Channel | unicode or apama.eplplugin.Context | |
optional<T> | T | May be None. |
location | apama.eplplugin.Location | |
EventType | apama.eplplugin.Event | All EPL event types are mapped to a single Python Event type. It has two fields. Type is the event name and fields is a dict of fieldname : fieldvalue. |
any | apama.eplplugin.Any | |
Methods using args/kwargs
You can either explicitly specify all the arguments that your plug-in methods take or you can rely on *args-type argument handling.
You can pass any number of EPL arguments into a Python function expecting *args. This functions in the same way as passing the arguments from within Python.
Expanding a sequence as function parameters is not supported. In this case, *args would contain a single parameter, of type list. It is possible to achieve this using a wrapper function from within Python. For example:
def funcThatUsesArgs(*args):
...
@EPLAction("action<sequence<any>>")
def foo(d):
funcThatUsesArgs(*d)
Apama does not invoke plug-in methods with argument names, so **kwargs patterns will not work. However, it is possible to use Python functions expecting **kwargs by using a wrapper function in the same way as with *args. For example:
def funcThatUsesKwargs(**kwargs):
...
@EPLAction("action<dictionary<string, any>>")
def foo(d):
funcThatUsesKwargs(**d)