When writing Typescript v2 functions or python functions in a code repository, I want to interact with the Ontology, by using an existing OSDK application defined in Developer Console.
How can I import and use this OSDK application ?
When writing Typescript v2 functions or python functions in a code repository, I want to interact with the Ontology, by using an existing OSDK application defined in Developer Console.
How can I import and use this OSDK application ?
You need to generate an SDK version in Developer Console:
You can then import it like any other library in your Code repository:
And use it, for example
from REDACTED_sdk import FoundryClient
@function
def example_function() -> str:
client = FoundryClient()
objects_iterator = client.ontology.objects.Cars.iterate()
objects = list(objects_iterator)
print(objects)
return "success"
Note: As of today, you need the Objects Types to be imported in your Project containing your Code repository of function. If not imported, the functions in preview will fail with “ObjectTypeNotFound”. Publishing the functions and executing the published versions will succeed.
Similarly, you can imported your SDK in the libraries.
You can then write the below code:
from pyspark.sql import DataFrame
from transforms.api import Input, Output, transform
import pandas as pd
from REDACTED_sdk import FoundryClient
from foundry_sdk_runtime.auth import ConfidentialClientAuth
from foundry_sdk_runtime.auth import UserTokenAuth
@transform(
out=Output("/path/example_output"),
)
def compute(out):
auth = ConfidentialClientAuth(
client_id="TOCHANGE",
client_secret="TOCHANGE",
hostname="https://TOCHANGE.com",
should_refresh=True,
)
auth.sign_in_as_service_user()
# If you want to test with your own token ## auth = UserTokenAuth(hostname="https://TOCHANGE.com", token="tokenhere!")
client = FoundryClient(auth=auth, hostname="https://TOCHANGE.com")
objects_iterator = client.ontology.objects.Cars.iterate()
objects = list(objects_iterator)
print(objects)
df = pd.DataFrame(objects)
out.write_pandas(df)