How can I get a user id using Python code repositories?

I am trying to making a function backed action using Python code repositories. I want to have it so that the user that clicks the action on a workshop will have their user id added to a “Last Edited By” parameter on an Ontology object. Is this possible in Python natively? I think a workaround if not would be to publish a helper function in TypeScript and import that into the Python code, but just wanted to see if there was a more direct way.

There might be some way to get the user ID from python repos, but you can also just pass in the current user as a parameter in the action configuration, and use the multipass ID wherever you need in the function. Something like this:

Hi @CodeRepoEvangelist! It sounds like you want to perform an ontology edit using python functions. Docs on how to do that are here. You’ll need to import the necessary objects you want to edit into your code repo, and create a Python OSDK. Then, you can write a function like:

from functions.api import function, OntologyEdit
from ontology_sdk import FoundryClient
from ontology_sdk.ontology.objects import MyOntologyObject


@function(edits=[MyOntologyObject])
def modify_object(user_id: str, ontology_object: MyOntologyObject) -> list[OntologyEdit]:
    edits = FoundryClient().ontology.edits()
    my_object = edits.objects.MyOntologyObject.edit(ontology_object)
    my_object.last_edited_by = user_id
    return edits.get_edits()