Skip to content

Using Siddhi from Python

Madhawa Vidanapathirana edited this page Aug 11, 2017 · 1 revision

Key Points

The PySiddhi API is a wrapper on Siddhi CEP Java Library, exposing it's core features to Python. It is important to keep following points in mind when using PySiddhi API.

  • It is a wrapper. Not a port. - Whenever you use the PySiddhi API, the Siddhi CEP Java Library is loaded in background using Java Virtual Machine.
  • The wrapper is focused on functionality provided by siddhi-core which is found in package org.wso2.siddhi.core. The future versions of API may have the ability to load Siddhi Extesions directly from Java Packages and use them in Siddhi Queries. However, the individual Java classes of extensions will not be wrapped.
  • Only the classes that are required for API users will be wrapped. Classes which are designed to be used by Siddhi CEP Java Library for its internal work will not be wrapped.
  • Python doesn't differentiate Integer from Long. But Siddhi do. Python 3 does not differentiate Integer and Long Data Types. All Python Integers fed into Siddhi (via InputHandler) are converted into Java Integers. To feed Java Long to Siddhi (via InputHandler), use DataTypes.LongType. All Long outputs received from Siddhi (via callbacks) will also be converted to DataTypes.LongType.
    • Example: inputHandler.send(["IBM",700.0,LongType(100)])
  • Clean up everything when you are done. Remember to call shutdown of SiddhiManager and SiddhiExecutionPlanRuntime (or SiddhiAppRuntime).

Python Mappings for Siddhi 4.0 (Development Version)

The wrapper is focused on functionality provided by siddhi-core. The classes in Java package org.wso2.siddhi.core are mapped to PySiddhi4.core using hand written logic. This is not an auto-generated wrapper. The follow table demonstrates major mappings of wrapper.

Java Class Python Import
org.wso2.siddhi.core.SiddhiManager from PySiddhi4.core.SiddhiManager import SiddhiManager
org.wso2.siddhi.core.ExecutionPlanRuntime from PySiddhi4.core.SiddhiAppRuntime import SiddhiAppRuntime
org.wso2.siddhi.core.event.Event from PySiddhi4.core.event.Event import Event
org.wso2.siddhi.core.event.ComplexEvent from PySiddhi4.core.event.ComplexEvent import ComplexEvent
org.wso2.siddhi.core.stream.input.InputHandler from PySiddhi4.core.stream.input.InputHandler import InputHandler
org.wso2.siddhi.core.stream.output.StreamCallback from PySiddhi4.core.stream.output.StreamCallback import StreamCallback
org.wso2.siddhi.core.query.output.callback.QueryCallback from PySiddhi4.core.query.output.callback.QueryCallback import QueryCallback
org.wso2.siddhi.core.debugger.SiddhiDebugger from PySiddhi4.core.debugger.SiddhiDebugger import SiddhiDebugger
org.wso2.siddhi.core.debugger.SiddhiDebuggerCallback from PySiddhi4.core.debugger.SiddhiDebuggerCallback import SiddhiDebuggerCallback
org.wso2.siddhi.core.util.EventPrinter import PySiddhi4.core.util.EventPrinter

Python Mappings for Siddhi 3.1

The wrapper is focused on functionality provided by siddhi-core. The classes in Java package org.wso2.siddhi.core are mapped to PySiddhi3.core using hand written logic. This is not an auto-generated wrapper. The follow table demonstrates major mappings of wrapper.

Java Class Python Import
org.wso2.siddhi.core.SiddhiManager from PySiddhi3.core.SiddhiManager import SiddhiManager
org.wso2.siddhi.core.ExecutionPlanRuntime from PySiddhi3.core.ExecutionPlanRuntime import ExecutionPlanRuntime
org.wso2.siddhi.core.event.Event from PySiddhi3.core.event.Event import Event
org.wso2.siddhi.core.event.ComplexEvent from PySiddhi3.core.event.ComplexEvent import ComplexEvent
org.wso2.siddhi.core.stream.input.InputHandler from PySiddhi3.core.stream.input.InputHandler import InputHandler
org.wso2.siddhi.core.stream.output.StreamCallback from PySiddhi3.core.stream.output.StreamCallback import StreamCallback
org.wso2.siddhi.core.query.output.callback.QueryCallback from PySiddhi3.core.query.output.callback.QueryCallback import QueryCallback
org.wso2.siddhi.core.util.EventPrinter import PySiddhi3.core.util.EventPrinter