# Using PYTHON With EPL

**URL:** <https://community.cumulocity.com/t/using-python-with-epl/7261>\
**Category:** Knowledge Base\
**Tags:** Streaming-Analytics-Apama, python\
**Created:** [November 9, 2018, 8:25am UTC](https://community.cumulocity.com/t/using-python-with-epl/7261 "2018-11-09T08:25:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/system/32/31990_2.png) [@system](https://community.cumulocity.com/u/system)\
**Post date:** [November 9, 2018, 8:25am UTC](https://community.cumulocity.com/t/using-python-with-epl/7261/1 "2018-11-09T08:25:23Z")

</div>

_In this article we introduce Python EPL plug-in. How to invoke the Python code from within Apama EPL. We demonstrate how to call Python code from EPL using sample code snippet that returns the reverse of a string from Python program_

## **Introduction :**

Now Customer can execute the machine Learning code developed in Python scripts as part of their Apama applications to make use use of Streaming analytics

A Python EPL plug-in allows developers to call Python code in an EPL application. The Python EPL plug-in will execute the python file.  
&nbsp;  
Current EPL plug-in supports Python 3.6.6

## **Prerequisite :**

Install Apama and Designer from Software AG Installer. Python 3 comes with the installation of Apama

 ![](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/5/8/58df648575230ebeb1f2484a211f204c23fd0d46.png)

## EPL In Action:

Following EPL and Python code snippet demonstrates how to call Python from EPL.

Python program from apama.eplplugin should import EPLAction, EPLPluginBase. Python class should have a constructor. For example:

| from apama.eplplugin import EPLAction, EPLPluginBase |

#### Sample Python Code :

class TestPluginClass(EPLPluginBase):

| `   def __init__ (self,init):
         super(TestPluginClass,self). __init__ (init)
         self.getLogger().info("TestPluginClass initialised")` |

Member functions that can be accessed by EPL needs to be declared with signature. For example:

| &nbsp; 

`   @EPLAction("action<string> returns string ")
     def reverse(self,s):
         rev = ""
         for i in s:
             rev = i + rev
         return rev`

 |

In the CorrelatorConfig.yaml file, user needs to configure the plug-ins:

| 

`eplPlugins:
   TestPlugin:
     pythonFile: "${PARENT_DIR}/../plugins/TestPlugin.py"
     class: TestPluginClass`

 |

#### Sample Apama Code :

| 

`package apamax.testpluginsample;`

`monitor TestPluginMonitor {`

`    import "TestPlugin" as plugin;`

`    action onload()
     {
         string originalstr := "malayalam";
         string rev := plugin.reverse(originalstr);
         log "Reverse of the string is: " + rev at INFO;
     }`

`}`

 |

&nbsp;

Apama Project folder structure exhibiting the CorrelatorConfig.yaml, TestPlugin.mon inside the monitor and TestPlugin.py inside plugins folder

 ![](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/e/8/e822f883e05cd44aeae87f23b1380e12d390164c.png)

## Conclusion :

In this article, we just demonstrated how to use Python EPL plug-in. User can create a complex Python application using NumPy, SciPy, Pandas, Matplotlib,Keras, TensorFlow etc and make use of these in Apama directly.

Please see the attachement section for working python and Apama mon.

[SimplePlugin.py](https://community.cumulocity.com/uploads/short-url/jWEO6wfDPr26NwcfFdDkry6V4Vy.py) (810 Bytes)

[SimplePlugin.mon](https://community.cumulocity.com/uploads/short-url/5OX30od1XuJuu2xVASEJR5RnPRq.mon) (671 Bytes)

---

<div class="post-metadata">

**Author:** ![Samirjain](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/samirjain/32/10027_2.png) [@Samirjain](https://community.cumulocity.com/u/Samirjain)\
**Post date:** [July 5, 2022, 6:33am UTC](https://community.cumulocity.com/t/using-python-with-epl/7261/2 "2022-07-05T06:33:43Z")

</div>

Extremely helpful! Thank you, it was easy to understand as a beginner.
