Skip to main content

An ORM for Autodesk Shotgrid

Project description

sgchemist

Tests codecov Ruff Checked with mypy

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.4.tar.gz (34.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.4-py3-none-any.whl (39.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sgchemist-0.0.4.tar.gz
  • Upload date:
  • Size: 34.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for sgchemist-0.0.4.tar.gz
Algorithm Hash digest
SHA256 a8d24bad126279ad56d6e777a92547da3ce9ea704c678dd4fd8c939931f28f69
MD5 b6278171cba8331bc87785d9785810ff
BLAKE2b-256 16fa22650245eb2337acadaea14a2b46d14d2c0e309a69197185276f53b9de39

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sgchemist-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 39.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for sgchemist-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 46b70cd39a1e99eadfb2aa55885eb2f01d7aaf492d3f7d51ef58cda2c3065446
MD5 c369b0a23e3e1016bfcb265110237e58
BLAKE2b-256 53c75dffaf336013b0af5f4e54d80e384b61661580f37f36fc9f401bee7697ad

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