Skip to main content

An ORM for Autodesk Shotgrid

Project description

sgchemist

An Object Relation Mapper for Autodesk Flow Production Tracker (previously Shotgrid and Shotgun) inspired by SQLAlchemy.

Declaring entities

You can declare all the entities and fields using a dataclass like structure:

from __future__ import annotations

from sgchemist.orm import SgEntity 
from sgchemist.orm import TextField 
from sgchemist.orm import EntityField
from sgchemist.orm import MultiEntityField
from sgchemist.orm import mapped_field


class Project(SgEntity):
    __sg_type__ = "Project"
    
    name: TextField = mapped_field(name="code")
    title: TextField
    assets: MultiEntityField[list[Asset]]
    
    
class Asset(SgEntity):
    __sg_type__ = "Asset"

    name: TextField = mapped_field(name="code")
    description: TextField
    project: EntityField[Project]

Query building

To make a query using sgchemist, you need to use two elements:

  • an engine: responsible for communicating with your Shotgrid instance. sgchemist provides an engine implementation using the shotgun-api3.
  • and a session: responsible for converting raw data from the engine back to objects. In case of creation and update querying it also implements the unit of work pattern.
from shotgun_api3 import Shotgun
from sgchemist.orm import ShotgunAPIEngine
from sgchemist.orm import select
from sgchemist.orm import Session

from myentities import Asset

# Create the engine
shotgun = Shotgun("https://mysite.shotgunstudio.com", script_name="xyz", api_key="abc")
engine = ShotgunAPIEngine(shotgun)

# Create the session
session = Session(engine)

# Create the query
query = select(Asset).where(Asset.project.name.eq("myproject"))

# Perform the query using the session
assets = list(session.exec(query))

# Update the description of the assets
with session:
    for asset in assets:
        asset.description = "This is an awesome asset"
        session.add(asset)
# Assets are now updated

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sgchemist-0.0.1.tar.gz (155.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sgchemist-0.0.1-py3-none-any.whl (38.6 kB view details)

Uploaded Python 3

File details

Details for the file sgchemist-0.0.1.tar.gz.

File metadata

  • Download URL: sgchemist-0.0.1.tar.gz
  • Upload date:
  • Size: 155.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for sgchemist-0.0.1.tar.gz
Algorithm Hash digest
SHA256 11ba282637e86f5aa10388fa3ba39c841c35db6031dd4d4a2703c036edd9492e
MD5 1583b8897e77b09d1c591f557a2e6a52
BLAKE2b-256 38072f04850cec7a925eb49f4195c005221171487f8d2bb7ebd410d7c689a9cc

See more details on using hashes here.

File details

Details for the file sgchemist-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: sgchemist-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 38.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for sgchemist-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 26b7bf6b5a6985188b10fc9804f048bb16cf51b683f059e8f1d49a957f001fc0
MD5 c1aec00ad58056b7e44b23bb361ec514
BLAKE2b-256 9bf24004b1d822e3f4e507d1636c95dbb4b4b04a427956cd78c4279598aea66f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page