Toolkits > com.ibm.streamsx.topology 1.5.13.__dev__ > com.ibm.streamsx.topology.python > Creating SPL Operators from Python code
SPL operators that call a Python function or callable class are created by decorators provided by this toolkit.
bin/spl-python-extract.py is a Python script that creates SPL operators from Python functions and classes contained in modules in a toolkit. The resulting operators embed the Python runtime to allow stream processing using Python.
To create SPL operators from Python functions or classes one or more Python modules are created in the opt/python/streams directory of an SPL toolkit.
Each module must import the streamsx.spl package which is located in the opt/packages directory of this toolkit. It contains the decorators use to create SPL operators from Python functions. The module must also define a function splNamespace that returns a string containing the SPL namespace the operators for that module will be placed in.
For example:
# Import the SPL decorators from streamsx.spl import spl # Defines the SPL namespace for any functions in this module # Multiple modules can map to the same namespace def splNamespace(): return "com.ibm.streamsx.topology.pysamples.mail"
Decorating a Python class produces a stateful SPL operator. The instance fields of the class are the state for the operator. Any parameters to the __init__ method (exluding the first self parameter) are mapped to operator parameters.
Decorating a Python function produces a stateless SPL operator. The function may reference variables in the module that are effectively state but such variables are shared by all invocations of the operator within the same processing element.
Any Python docstring for the function or class is copied into the SPL operator's description field in its operator model, providing a description for IDE developers using the toolkit.
Functions or classes in the modules that are not decorated, decorated with @spl.ignore or start with spl are ignored and will not result in any SPL operator.