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 SgBaseEntity
from sgchemist.orm import TextField
from sgchemist.orm import EntityField
from sgchemist.orm import MultiEntityField
class SgEntity(SgBaseEntity):
"""Base class for all the entities."""
class Project(SgEntity):
__sg_type__ = "Project"
name: TextField = TextField(name="code")
title: TextField
assets: MultiEntityField[Asset]
class Asset(SgEntity):
__sg_type__ = "Asset"
name: TextField = TextField(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.
sgchemistprovides an engine implementation using theshotgun-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, Project
# 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.f(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.6.tar.gz
(30.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
sgchemist-0.0.6-py3-none-any.whl
(34.8 kB
view details)
File details
Details for the file sgchemist-0.0.6.tar.gz.
File metadata
- Download URL: sgchemist-0.0.6.tar.gz
- Upload date:
- Size: 30.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a6c7db28733f13072ad20ec7dac73fd26c76dfde098b8f549b56d0005677e28
|
|
| MD5 |
296d9a43c1c476733b92a4d037a2ea8b
|
|
| BLAKE2b-256 |
350a418c453aff68d77a350a72ce3bf1a1f55054a20341f699d93183a4dd05ef
|
File details
Details for the file sgchemist-0.0.6-py3-none-any.whl.
File metadata
- Download URL: sgchemist-0.0.6-py3-none-any.whl
- Upload date:
- Size: 34.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
207b423be75c48b7e0347e387e95d67dc516b7cafc7c684428fb46f2d0a95ebf
|
|
| MD5 |
58434dfeaf53c111937ab618d2147cfd
|
|
| BLAKE2b-256 |
064b6649f20a05ce2d6a1f6156c3d21ece648208b4484bdaf78788e99034d95c
|