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.