1. Home
  2. Docs
  3. Functions
  4. Adding a function
  5. Adding Python functions

Adding Python functions

Python functions can be added by loading a Python file (.py) or a zipped Python file (.zip). When adding Python files, the Class Name is specified as the name of the Python file without the extension plus the class you want to execute. For example, if the Python file is called function.py and the class is exclamation, then the class name would be “function.exclamation”. The file can contain multiple classes, but only one will be used. If there is no class in the Python file, for example when using a basic function, just specify the filename without the extension (ex. function).

When loading a Python script in a py file or a zipped py file, the UI will attempt to extract the Python code. If successful, it will display a the code and fill in most of the field on the Functions Add screen with values that match the code.

Adding a Python function file

  1. From the left sidebar menu, select Functions/Add.
  2. Click on the Choose File button from the Function File field.
  3. Using the dialog box, select the Python script containing the function code. This should be a file with a .py extension or a zip file containing a file with a .py extension. The UI will load the code and display it in the Code Preview section.
  4. If the Python file has more than one class, then the Class Name drop-down will contain all the classes. Choose the class you want to execute as the function.
  5. Enter the function name in the Function Name field. The name will default to the filename without the extension.
  6. Select the namespace where you want to create the function in the Namespace field. Note that all topics (input, output, logs) must be in the same namespace as the function.
  7. If the Runtime field did not default to Python, set it to Python.
  8. Specify the input topic for the function in the Input Topic field. This the topic that the function will connect to and process messages from. If the input topic doesn’t exist when the function is added, it will be automatically created.
  9. Optionally, specify the output topic in the Output Topic field. If the function returns a value, you specify an output topic for this value to be published to. If the output topic doesn’t exist it will be created automatically when the function executes.
  10. Optionally, specify the log topic in the Log Topic field. If the function generates logs, you should specify a log topic. If the log topic doesn’t exist, it will be created when the function generates a log message.
  11. Specify the number of instances of this function to run in the Instances field. If the input topic receives a high rate of messages, you may need multiple function instances to keep up with the load. Note that the number of instances you can create will be limited by your Plan.
  12. Select the processing guarantee in the Processing Guarantee field. This field specifies how many times the function will be executed successfully for each message on the input topic.
  13. If the processing guarantee is At Least Once, enter the function timeout in milliseconds in the Time Out In Ms field.
  14. If you want the message to be automatically acknowledged when the function runs successfully, click on the Auto Ack checkbox. If you disable automatic acknowledgment, you must explicitly acknowledge the message in your function.
  15. If your function uses configurations keys as input, click on Click For Config Keys to display the key settings. Enter the key and value the Add Key button. To remove a key you have added, click on the X beside the key name.
  16. To add the function, click on the Add button. If the function is successfully added you will see the Function Details screen for the function.
Was this article helpful to you? Yes No

How can we help?