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.3.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.3-py3-none-any.whl (38.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sgchemist-0.0.3.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.3.tar.gz
Algorithm Hash digest
SHA256 f1f71922687bb15e4db1ccbc84c69e191f9f3d88ad6292e007556a7075b94505
MD5 a1e2af15862c7a2bd96df6ac03a03689
BLAKE2b-256 30dac5e530ca9e6e89ed2550b3a0aee40b07cfb80da8fb00ceea514a7e83099f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sgchemist-0.0.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6d3d27bca9120827b4c13f25654b118aa04a958a5dfe30433f73434025ba665e
MD5 beac4f6e96a28e4fe19ed1b615c3c0da
BLAKE2b-256 def419856e801a05fe77cd6c58ed293cc42a425ed716c7691cef45ea27ddd731

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