Can users use sgtk api?

Hello

As a user, I have a few questions. The company is using shotgrid, is there any problem if the user uses sgtk api?

I want to make a simple tool to find and show files in Maya, and I want to use sgtk api here.

The code that I thought of briefly is

import sgtk
sg = sgtk.util.shotgun.get_sg_connection()
get_item = sg.find([......])

I want to find and write some files like this. Does it matter if the user uses this code? I’m curious.

In theory yeah there shouldn’t be anything stopping you from making API calls to SG as a user using your own credentials.
Though, it depends on the studio you’re at and the permission level your user has.

I’m not sure how in the loop with the API you are but there are two types SG auth, user-based and script-based.
More info can be found here:
https://developer.shotgridsoftware.com/python-api/authentication.html#user-based-authentication

The idea though is that with user-based, all API calls will essentially be bound to whatever permissions your user account has.
So if you’re a coordinator/artist that can’t change certain fields, delete things or restore from the trash then using your user account means the API can’t allow you to do that either.

There’s script-based which is where, as an admin, you can make an API key with it’s own permissions. Usually AMI (right click menu buttons) actions will call scripts using a script-based auth.

In your example of reading from SG though, I don’t see any issues as you’re just reading data.
You may want to ask for permission from Pipeline… though, tbh, I wouldn’t in this case.

The user can use api, but it is understood that there is a limit to the available commands depending on the pipeline setting. Did I get it right?

I have a question in the last sentence because I use a translator.

Do you mean not to use this code?

Or do you mean I don’t have to tell the pipeline team if I just read the data?

I have only ever used script based authentication, so I’m not aware of any limitations.
Looking quickly at the developer documentation I can’t see any mention that user authenticated commands are limited.

The only limitation would be if your pipeline/security/IT team restricted what can be read, written, deleted or edited on your permission group.

Use the code, all I meant was that if you are simply reading data from ShotGrid then I see no reason why you would need to inform your pipeline team.
However, be careful with how many reads you make because that will negatively impact performance for everyone else using your ShotGrid site.

So, for example, if you manually with a For loop read 1000 entries one-by-one from SG then you will likely cause issues because that’s a lot of heavy traffic.
Instead, make good use of Filter operator which works just like Filters in ShotGrid but through code.
https://developer.shotgridsoftware.com/python-api/reference.html#filter-syntax

You want to be specific to get the most performance, for example you said you want to “find and show files in Maya”.
So you will want the filter to:

  1. Only return the files you want
    i.e. only files for the shot that you are working on
  2. Only return the field/columns you want
    i.e. just the name of the file and the file path on disk

Check out the Performance section on this page:

Lastly, there are code examples here, this one in particular finds a specific shot and returns some specific data:
https://developer.shotgridsoftware.com/python-api/cookbook/examples/basic_find_shot.html

1 Like

Thank you very much for your kind reply.

I can get what I want with one command, so I don’t think there will be a problem with the performance.

Have a nice day!

1 Like

Also,

if you are running this code inside an engine you may want to use this instead to get a shotgun handle:

import sgtk
sg = sgtk.platform.current_engine().shotgun