Serverless Python Functions are in the beta phase of development and may not be available on your enrollment. Functionality may change during active development.
If serverless Python functions are not enabled on your environment, you must deploy your function. If serverless Python is enabled on your enrollment, deploying your function is optional and not required. If enabled, the serverless executor will be used by default.
This guide assumes you have already authored and published a Python function. Review the getting started with Python functions documentation for a tutorial. For examples of how to query the Ontology using the Python SDK, see the Python Ontology SDK documentation.
In Workshop, search for the Python function from the Variables tab to the left side of the module. Deployed functions will show an icon with one of three states for both the function and the function version:
Only one version of the function’s repository is hosted at a given time. To make changes to functions with limited downtime we recommend adding a new function (like function_v1
) with the changes and tagging as described here. From your published functions under tags and releases, select Open in Ontology Manager.
In Ontology Manager, select the version of the function repository you want to use in applications, then select Upgrade.
Update all downstream applications using functions from this repository to the new version you have deployed. Note that the previous deployment version will no longer be running so your applications will have a short downtime as you make this change. You will have function_v0
and function_v1
available at the same time so while you need to switch to the new deployment version, you do not have to change the function you are using. When function_v0
is no longer used, you can delete the function.
If your function is not working as expected in Workshop, first check if the issue is related to the logic or the responsiveness of the function. If there is an issue with the logic, inspect the source code in the backing code repository. If there is an issue with the function being unresponsive or throwing an error, follow the steps below:
Upgrading
, hover over the function’s information icon and select Configure. This will take you to Ontology Manager where you can select Start Deployment to get your function running again.Running
or you need more information about the deployment’s behavior, select Deployment from the left panel in Ontology Manager to view detailed logs. SLS logs are also available if you select View live.To create a function-backed column, you must publish a function that meets the following requirements:
The function's input parameters must include an object set parameter (imported from ontology_sdk.ontology.object_sets
) and can optionally include other input parameters. This object set parameter will enable the objects displayed in the table to be passed into the function to then generate the desired derived column. Note that a list[ObjectType]
parameter will also work here, but this less performant option is not recommended.
The function's return type must be dict[ObjectType, ColumnType]
, where ColumnType
is the desired type for the column, or dict[ObjectType, CustomType]
to return multiple columns from the function. Learn more about custom types.
Once a function that meets the above criteria is configured and published, you can configure a function-backed property column within the Object Table widget configuration.
An example of a function returning one column:
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
from functions.api import Date, Integer, String, function from ontology_sdk import FoundryClient from ontology_sdk.ontology.object_sets import myObjectTypeObjectSet from ontology_sdk.ontology.objects import myObjectType @function def function_backed_column_single_col( selected_objects: myObjectType ) -> dict[myObjectType, Integer]: final_dict = {} for curr_obj in selected_objects: final_dict[curr_obj] = 10 # The value can be defined for any arbitrary logic return final_dict
An example of a function returning multiple columns:
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
from dataclasses import dataclass @dataclass class CustomType: column_name_a: int column_name_b: int @function def function_backed_column_multiple_cols( selected_objects: myObjectTypeObjectSet, some_other_parametr: String ) -> dict[myObjectType, CustomType]: final_dict = {} for curr_obj in selected_objects: final_dict[curr_obj] = CustomType(column_name_a=10, column_name_b=20) return final_dict