Query functions

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!
1from functions.api import function 2 3@function(api_name="myPythonFunction") 4def my_python_function() -> str: 5 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!
1from functions.api import function 2from ontology_sdk import FoundryClient 3 4@function 5def call_query_function() -> str: 6 return FoundryClient().ontology.queries.my_python_function()

To call it from a TypeScript function:

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

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.