Accessing Ontology objects from deployed Python function

I’m trying to get a list of Ontology objects to be iterated through. I’m currently trying to do it with a deployed Python function, as a serverless function didn’t work either. Here are the two methods I’ve tried so far:

  1. Using the FoundryClient


    The outcome of this code gives me a BaseKeywordFilterSet. However, I haven’t been able to do much with this. The useful-looking methods (to_dataframe(), iterate(), etc) all throw the following error:
    image
    For some reason, when it’s creating an ObjectIterator in the background when calling these methods, it errors out with the above error. I haven’t been able to find a workaround so far.

  2. Using a connection URL


    This works great when testing locally, but when I deploy it, even when testing in the code repository function tester, it doesn’t work. The error says it can’t resolve the https://HOSTNAME.palantirfoundry.com address.

Please let me know what I’m doing wrong. Thank you very much!

1 Like

Hey @deandean - typically, when writing a Python function, you shouldn’t need to explicitly provide the auth or hostname fields when constructing a FoundryClient, as these values will be automatically injected at runtime. In most cases, something like this should work:

client = FoundryClient()
objectSet = client.ontology.objects.KeywordFilter

for keyword_filter in objectSet:
    # ...

If you have a use case that requires overriding auth or hostname, the error you’re getting with your current approach is because the FoundryClient constructor expects an Auth object rather than a dict. You could instead provide an explicit UserTokenAuth object:

from ontology_sdk import UserTokenAuth

auth = UserTokenAuth(token="MYTOKEN", hostname="MYHOSTNAME")