GithubHelp home page GithubHelp logo

fabiangeisler / pyshotgrid Goto Github PK

View Code? Open in Web Editor NEW
42.0 4.0 0.0 831 KB

A pythonic and object oriented way to talk to Autodesk Flow Production Tracking (formally known as ShotGrid).

Home Page: https://fabiangeisler.github.io/pyshotgrid/

License: MIT License

Python 100.00%
python shotgrid

pyshotgrid's Introduction

VFX Platform pypi PyPI pyversions Tests coverage pre-commit Code style: black Ruff Checked with mypy

pyshotgrid is a python package that gives you a pythonic and object oriented way to talk to Autodesk Flow Production Tracking (formally known as ShotGrid).

Quickstart

Install pyshotgrid via pip:

pip install pyshotgrid

You are now ready to use it in your project (For other installation methods see the Installation section in the documentation)! Here is a quick example to list the "code" (aka. "name") of all shots from all projects:

import pyshotgrid as pysg

site = pysg.new_site(base_url='https://example.shotgunstudio.com',
                     script_name='Some User',
                     api_key='$ome_password')

for project in site.projects():
    print(project["name"].get())
    for shot in project.shots():
        print(shot["code"].get())

Features

In pyshotgrid you are working with SGEntity instances 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 to pyshotgrid objects 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 field

    print(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 field

    sg_version['sg_uploaded_movie'].upload('/path/to/movie.mov')
    sg_version['sg_uploaded_movie'].download('/path/to/download/to/')
  • Get the URL of the entity

    print(sg_project.url)  # https://example.shotgunstudio.com/detail/Project/1
  • Convert it to a regular dict, to use it in Autodesk shotgun_api3.

    sg_project.to_dict()  # {"type": "Project", "id": 1}
  • Iterate over all fields

    # Iterate over the fields directly to get some information about them...
    for field, value in sg_project.fields().items():
         print(field.display_name)
    # ... or iterate over the fields and values at the same time.
    for field_name, value in sg_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 from SGEntity and create implementations for specific entity types. pyshotgrid ships with a few common entities by default. For example the implementation for the Project entity (SGProject) gives you additional functions to query shots, assets or publishes:

    sg_project.shots()
    sg_project.assets()
    sg_project.publishes()

    Checkout the overview of all the default entities and the API documentation for all the extra functionality! As an additional bonus: You can customize and extend all these classes to your hearts content. Have a look at How to add custom entities in the docs.

FAQ

Is it faster than shotgun_api3?

No, and since it is build on top of shotgun_api3, it never will be. pyshotgrid is syntactic sugar that hopefully enables you to develop better and faster. :)

Is pyshotgrid replacing shotgun_api3?

No, quite the opposite. It is meant to be used in conjunction with shotgun_api3 and 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 shotgun_api3. That said, it is totally possible to write pyshotgrid code without using shotgun_api3.

I have some custom entity setup in ShotGrid. Can this be reflected in pyshotgrid?

Yes, it can! By default pyshotgrid returns any entity as SGEntity to provide a minimum of functionality in all cases. However you can write your own class that inherits from SGEntity and register that to pyshotgrid. After that, pyshotgrid will use your custom entity whenever you ask for it. With this method you can even overwrite default classes that ship with pyshotgrid.

Why does pyshotgrid not support Python 3.7? shotgun_api3 has support for it.

A couple of reasons:

  • Python 3.7 reached EOL and is no longer maintained.

  • Python 3.7 is soon off the VFX Reference Platform.

  • The hidden goal of this project is to create a python library that uses the latest innovations in the Python world. In a nutshell I want to create the simplest setup that gives you:

    • automatic publishing to PyPI
    • automatic testing with tox, pytest and coverage
    • automatic Sphinx documentation
    • mypy type hints
    • ruff linting
    • black code formatting (actually done by ruff format)
    • pre-commit checks
    • invoke setup for common tasks in the repository
    • streamlined commit messages and changelog with commitizen

    A good chunk of these tools do not support Python 3.7 anymore and I do not have the time to keep up the compatibility.

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. :)

How will the rebranding from "ShotGrid" to "Flow Production Tracking" affect this project?

There will be no code-breaking name changes and pyshotgrid will not be rebranded. Only docs and docstrings will use the new name.

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template (but was heavily modified in the meantime).

pyshotgrid's People

Contributors

dependabot[bot] avatar fabiangeisler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pyshotgrid's Issues

Typed Field classes

At the moment we have one Field class that encapsulates all aspects of fields. This can be a bit much and the overlap of functionality might be too big in the long run. We could implement a Field class for each Field data type for explicit functionality separation. This means on the other hand that we need to query and cache the ShotGrid entity schema to know up front which field class to create. That in of itself is not too complicated, what worries me is keeping the cache up to date. Fields can be added, deleted or change the data type. All not very common operations but with long running processes, like the event listener, this is something to consider.

Raise test coverage to ~90%

Description

Raising the coverage to ~ 90% should give a good and stable code base while leaving out the real hard things to test. All parts of the library should have a few tests to make it easy and obvious to add more.

Note about Shotgrid rebranding

Readme an docs need to be updated to mention the standpoint of the project concerning the rebranding of Shotgrid to Flow production tracking.

Add hints for DB calls to docstrings

Each Shotgrid Database call slows down code execution, which means that some pysg functions are more efficient than others.
For example sg_project["code"].get() and sg_project.all_field_values() each do only one call to the Shotgrid Database, but the second call returns vastly more information and might be more desirable to use in your code.
It would be great for the user to see how many calls are made in the docstring of each function, so they can decide what to use and optimise easier.

Use shotgun-api3 from PYPI

  • pyshotgrid version: v1.0.1
  • Python version:
  • Operating System:

Description

shotgun_api3 is present on PyPI and that is far easier to use then the git URL in the requirements.txt's.
On top this makes installing pyshotgrid even easier by just doing pip install pyshotgrid.

Documentation enhancements

The docs need a few enhancements to make the library easy to work with.

  • usage guide
  • general overhaul of structure - shorten where possible
  • add links where possible
  • consistent naming

Convenience method to authenticate to ShotGrid

  • pyshotgrid version: v1.0.1
  • Python version: any
  • Operating System: any

Description

If you are a SG user/developer the chances are high that you are using ShotGrid Desktop or ShotGrid Create. Both applications are storing their session token in a authentication file which is not hard to find and read. For example under windows in: C:\Users\USER\AppData\Roaming\Shotgun\SGSITE\authentication.yml. We could provide a convenience method that searches for the file and reads the session token from it.
The idea is to piggyback that session token so you do not need to enter any API tokens for simple scripts.

This certainly has some downsides. We do not want to add the super sophisticated logic of SGTK for authentication (nor do we want to add SGTK as a dependency). So we would likely just end in an error when the token is invalid, which makes the method unusable in production context.

Since this lowers the entry point to the library I think this is still a worthy addition.

Implementation

Either a dedicated method that searches for the everything necessary or we extend the pyshotgrid.new_site method so that if you give it no parameters is goes to search around for the session token.

Better documentation for the default entities

  • pyshotgrid version: v1.0.1
  • Python version:
  • Operating System:

Description

There should be better documentation for the default entities that are shipped with pyshotgrid.
An overview with a diagram would be great.

Improve performance of SGEntity.name property

  • pyshotgrid version: v1.0.0
  • Python version: any
  • Operating System: any

Description

The SGEntity.name property is doing a query to SG in order to find out which field to use. However for the sg_default_entities this could be pre determined by overwriting the "name" function. This would save the call to SG for the most common entities.

New version of ShotGrid Python API v3.4.1

  • pyshotgrid version:
  • Python version:
  • Operating System:

Description

Hello folks, I wanted to share with you a new release of the ShotGrid Python API v3.4.1

What I Did

  • Add methods for the user_subscriptions API endpoints
  • Retries also on 504
  • Retries S3 uploads on error 500
  • Comment typing annotation breaks Python 2 compatibility
  • Add field type entity_type to mockgun as simple str
  • Full release notes are available on GitHub.

"Url" fields incorrectly cast to "Attachment" entities

  • pyshotgrid version: 1.0.0
  • Python version: 3.*
  • Operating System: Linux

Description

When querying a "url" field it will return an "Attachment" SGEntity, which is undesired in most cases.

What I Did

>>> sg_published_file["path"].get()

Workaround

You can return the raw values in the get method:

>>> sg_published_file["path"].get(raw_values=True)

Update to shotgun_api v3.3.6

  • pyshotgrid version: v1.0.0
  • Python version: any
  • Operating System: any

Description

The shotgun_api3 was updated recently to v3.3.6

Add dynamic test coverage badge and reports

  • pyshotgrid version: v1.0.1
  • Python version: any
  • Operating System: any

Description

The coverage badge is static and manually updated at the moment. I would like to have it dynamic and this
Pytest Coverage Comment github action seems to be a good solution, with automatic comments about the coverage on each PR and, with some extra setup, a dynamic badge for the README.

Entity "name" property

Add a "name" property to entities that wraps around Shotgrids "code" vs. "name" fields, which are often misleading. So we only have one property to go to for the actual name of an entity.

ShotGrid python-api v3.4.0

  • pyshotgrid version: n/a
  • Python version: 3.7/3.9/3.10
  • Operating System: all

Description

Hello from the ShotGrid team ๐Ÿ‘‹ ,

I just wanted to let you know that we released v3.4.0 that now supports up to Python 3.10. Feel free to reach out if you have any questions.

Various issues with up and download from fields

  • pyshotgrid version: v0.14.0
  • Python version: 3.7
  • Operating System: Any

Description

There are various bugs when trying to up or download from a field.

  • downloading from "image" fields (thumbnails and filmstrips) does not work
  • downloading without a path should download to a temp directory
  • downloading should optionally create all missing folders
  • uploading fails to return an attachment entity

Here is a patch for a WIP fix:
WIP_fix_for_upload_and_download.patch.txt

Documentation improvements

Docs need some improvement

  • section on authentication
  • toc in Hompage needs less depth
  • maybe an "in-depth" features section?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.