You can write functions that interact with the Ontology using the Python Ontology SDK.
To generate a Python Ontology SDK client, navigate to the Resource imports sidebar and select Add > Ontology. From there, select your desired Ontology and import any objects and links you would like to interact with in your functions. After saving to confirm your selections, a Python OSDK client will be generated for you to use in your functions.
For an example object type named Aircraft
with properties brand
and capacity
, you could write a
function that accepts an Aircraft
object and summarizes it like so:
Copied!1 2 3 4 5 6
from functions.api import function from ontology_sdk.ontology.objects import Aircraft @function def aircraft_input_example(aircraft: Aircraft) -> str: return f"{aircraft.brand} aircraft, holds {aircraft.capacity} passengers"
Furthermore, if you wanted to search for Aircraft
objects satisfying a certain capacity threshold, you could write the
following:
Copied!1 2 3 4 5 6 7 8 9
from functions.api import function from ontology_sdk import FoundryClient from ontology_sdk.ontology.objects import Aircraft from ontology_sdk.ontology.object_sets import AircraftObjectSet @function def aircraft_search_example() -> AircraftObjectSet: client = FoundryClient() return client.ontology.objects.Aircraft.where(Aircraft.capacity > 100)
The Python OSDK also offers beta features such as interoperability with pandas DataFrames:
Copied!1 2 3 4 5 6 7
from functions.api import function from ontology_sdk.ontology.object_sets import AircraftObjectSet @function def aircraft_dataframe_example(aircrafts: AircraftObjectSet) -> int: df = aircrafts.to_dataframe() return df['capacity'].sum()
Review the Python Ontology SDK documentation for more information.