Package: pyshotgrid
pyshotgridis a python package that gives you a pythonic and
object oriented way to talk toAutodesk ShotGrid.QuickstartInstallpyshotgridvia pip:pipinstallpyshotgridYou are now ready to use it in your project (For other installation methods see theInstallationsection in the documentation)!
Here is a quick example to list the "code" (aka. "name") of all shots from all projects:importpyshotgridaspysgsite=pysg.new_site(base_url='https://example.shotgunstudio.com',script_name='Some User',api_key='$ome_password')forprojectinsite.projects():print(project["name"].get())forshotinproject.shots():print(shot["code"].get())FeaturesInpyshotgridyou are working withSGEntityinstances which each represent exactly one entity
in ShotGrid. Any operation on it is reflected to ShotGrid.
So for example you can :Get entity fields in ShotGrid# Get the value of a field ...print(sg_project["name"].get())# "foobar"# ... or get multiple fields at once.print(sg_project.get(["name","tank_name"]))# {"name": "foobar", "tank_name": "fb"}Update entity fields in ShotGrid# Set the value of a field ...sg_project["name"].set("foobar")# ... or set multiple fields at once.sg_project.set({"name":"foobar","tank_name":"fb"})Values are automatically converted topyshotgridobjects which makes it
possible to chain queries together.# Name of the first Version in a Playlist.print(sg_playlist["versions"].get()[0]["code"].get())Get information about a fieldprint(sg_project["name"].data_type)# "text"print(sg_project["name"].description)# "The name of the project."print(sg_project["name"].display_name)# "Project Name"Upload/Download to/from a fieldsg_version['sg_uploaded_movie'].upload('/path/to/movie.mov')sg_version['sg_uploaded_movie'].download('/path/to/download/to/')Get the URL of the entityprint(sg_project.url)# https://example.shotgunstudio.com/detail/Project/1Convert it to a regular dict, to use it in Autodeskshotgun_api3.sg_project.to_dict()# {"type": "Project", "id": 1}Iterate over all fields# Iterate over the fields directly to get some information about them...forfield,valueinsg_project.fields().items():print(field.display_name)# ... or iterate over the fields and values at the same time.forfield_name,valueinsg_project.all_field_values().items():print(field_name,value)Do you keep forgetting which field is the "name" of an entity? (was it "code" or "name"?)
Just use the "SGEntity.name" property:sg_project.name# returns the "name" field.    Same as:  sg_project["name"]sg_shot.name# returns the "code" field.    Same as:  sg_shot["code"]sg_task.name# returns the "content" field. Same as:  sg_task["content"]It is possible to inherit fromSGEntityand create implementations for specific
entity types.pyshotgridships with a few common entities by default. For example
the implementation for theProjectentity (SGProject) gives you additional functions
to query shots, assets or publishes:sg_project.shots()sg_project.assets()sg_project.publishes()Checkout theoverview of all the default entitiesand theAPI documentationfor all the extra functionality!
As an additional bonus: You can customize and extend all these classes to your hearts content.
Have a look atHow to add custom entitiesin the docs.FAQIs it faster thanshotgun_api3?No, and since it is build on top ofshotgun_api3, it never will be.pyshotgridis syntactic sugar that hopefully enables you to develop better and faster. :)Ispyshotgridreplacingshotgun_api3?No, quite the opposite. It is meant to be used in conjunction withshotgun_api3and
improve handling and writing code with it. Its main goal is to make it easier to write
code for common scenarios and leave the special cases for theshotgun_api3. That said,
it is totally possible to writepyshotgridcode without usingshotgun_api3.I have some custom entity setup in ShotGrid. Can this be reflected inpyshotgrid?Yes, it can! By defaultpyshotgridreturns any entity asSGEntityto provide
a minimum of functionality in all cases. However you can write your own class
that inherits fromSGEntityand register that topyshotgrid. After that,pyshotgridwill use your custom entity whenever you ask for it. With this method
you can even overwrite default classes that ship withpyshotgrid.Why is doespyshotgridnot support Python 3.7?shotgun_api3has support for it.A couple of reasons:Python 3.7 reached EOLand is no longer maintained.Python 3.7 is soon off theVFX Reference Platform.pyshotgridis using a lot of modern tools and libraries which are hard to maintain for
Python 3.7 and since this is a "free time project" I cannot afford to waist my time on
compatibility issues.Is this an official project from Autodesk?No, just a brainchild from me,Fabian Geisler.
I am a Pipeline Developer based in Berlin.
Feel free to follow me on GitHub. :)CreditsThis package was created withCookiecutterand
theaudreyr/cookiecutter-pypackageproject template
(but was heavily modified in the meantime).