1. Process Data Streams
  2. Generic Runtime(Alpha)

Develop&Deploy Python Function

The following example shows how to create a Python kind generic runtime function on Streamnative Cloud using different tools.

Below is an example of the Python function, you can find more examples in here:

from pulsar import Function

# The classic ExclamationFunction that appends an exclamation at the end
# of the input
class ExclamationFunction(Function):
  def __init__(self):

  def process(self, input, context):
    logger = context.get_logger()
    for word in input.split(" "):
      context.incr_counter(word, 1)
      count = context.get_counter(word)
      logger.info("got word: %s for %d times" % (word, count.value))
    context.publish("persistent://public/default/test-py-package-serde-extra", input + '!!!')
    return input + '!'

Upload your function file to Pulsar

Please refer to: Upload Function Package

Create a Python kind generic runtime Pulsar function

pulsarctl functions create \
--tenant public \
--namespace default \
--name function1 \
--inputs persistent://public/default/test-python-input \
--output persistent://public/default/test-python-output \
--classname exclamation.ExclamationFunction \
--py function://public/default/[email protected]
--custom-runtime-options '{"genericKind": "python"}'

You should see something like this:

Created function1 successfully

For details about Pulsar function configurations, see Pulsar function configurations.

What’s next?

Develop&Deploy NodeJs Function