Advanced usage

Publish a query function

To register a Python function that is callable from other TypeScript or Python functions, you must give your Python function an API name. To do this, provide the api_name field in the @function decorator:

Copied!
1 2 3 4 5 from functions.api import function @function(api_name="myPythonFunction") def my_python_function() -> str: return "Hello World!"

Call a query function

After publishing your TypeScript or Python query function, navigate to the code repository where you want to consume the function, and import it using the Resource imports sidebar.

Then, your function will be callable from the consuming repository. For example, to call it from a Python function:

Copied!
1 2 3 4 5 6 from functions.api import function from ontology_sdk import FoundryClient @function def call_query_function() -> str: return FoundryClient().ontology.queries.my_python_function()

To call it from a TypeScript function:

Copied!
1 2 3 4 5 6 7 8 import { Queries } from "@foundry/ontology-api" export class MyFunctions { @Function() public callQueryFunction(): Promise<string> { return Queries.myPythonFunction(); } }

Calling a TypeScript query function from a Python function will look exactly the same; publish the TypeScript query function with an API name, then consume it from Python as shown above.

Create a function-backed column

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 configuration.