Proper way to access SGTK in a RV package

You can add a callback to the sgtk-authenticated-user-changed event and import sgtk locally from that function. The event gets fired once the asynchronous tk-rv engine bootstrap is completed.

As you can see, this module is a special because it’s dynamic and importing in the scope of your function allows you to be sure to have a reference to the right sgtk.

You can then do something like:

user = sgtk.get_authenticated_user():

if user is None:
  return

sg = user.create_sg_connection()

# Then use sg find_one() and do the rest of your logic. 
2 Likes