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.2.tar.gz (155.0 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.2-py3-none-any.whl (38.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sgchemist-0.0.2.tar.gz
  • Upload date:
  • Size: 155.0 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.2.tar.gz
Algorithm Hash digest
SHA256 38c56ad5fc9f408ffb6baedaf25e983983bd59884e021481ed6fb424fa9c613c
MD5 f0bedd6d30fa433f2c66cbbe24447abd
BLAKE2b-256 126ebf58b7856c6be7d785f430c1d960677de512815af0041c750e2ab61310ba

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sgchemist-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 38.7 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c165fee55f82181018d858fcf74f3ac6bb840b837e89cf6ac72742a42a7f4063
MD5 fa123dacdab32706f6c8295fc550eb7b
BLAKE2b-256 c75492e29f3584b4930f92ecf21557b3937f13f37b9159e59db410e929509a79

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