Skip to content

Advanced Concepts of PySiddhi

Key Points

The PySiddhi API is a wrapper on Siddhi 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 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 io.siddhi.core. The future versions of API may have the ability to load Siddhi Extensions 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 are wrapped. Classes which are designed to be used by Siddhi 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 SiddhiAppRuntime.

Java Siddhi to PySiddhi Mappings

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

Java Class Python Import
io.siddhi.core.SiddhiManager from PySiddhi.core.SiddhiManager import SiddhiManager
io.siddhi.core.ExecutionPlanRuntime from PySiddhi.core.SiddhiAppRuntime import SiddhiAppRuntime
io.siddhi.core.event.Event from PySiddhi.core.event.Event import Event
io.siddhi.core.event.ComplexEvent from PySiddhi.core.event.ComplexEvent import ComplexEvent from import InputHandler from import StreamCallback
io.siddhi.core.query.output.callback.QueryCallback from PySiddhi.core.query.output.callback.QueryCallback import QueryCallback
io.siddhi.core.debugger.SiddhiDebugger from PySiddhi.core.debugger.SiddhiDebugger import SiddhiDebugger
io.siddhi.core.debugger.SiddhiDebuggerCallback from PySiddhi-3.core.debugger.SiddhiDebuggerCallback import SiddhiDebuggerCallback
io.siddhi.core.util.EventPrinter import PySiddhi.core.util.EventPrinter