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
Metadata
Release files for sgchemist 0.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sgchemist-0.0.6.tar.gz | 30.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sgchemist-0.0.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 64.8 kB
Release files / sgchemist-0.0.6.tar.gz
| Download URL | sgchemist-0.0.6.tar.gz |
|---|---|
| Size | 30.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4a6c7db28733f13072ad20ec7dac73fd26c76dfde098b8f549b56d0005677e28
|
|
BLAKE2b-256 checksum How to use checksums |
350a418c453aff68d77a350a72ce3bf1a1f55054a20341f699d93183a4dd05ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Release files / sgchemist-0.0.6-py3-none-any.whl
| Download URL | sgchemist-0.0.6-py3-none-any.whl |
|---|---|
| Size | 34.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
207b423be75c48b7e0347e387e95d67dc516b7cafc7c684428fb46f2d0a95ebf
|
|
BLAKE2b-256 checksum How to use checksums |
064b6649f20a05ce2d6a1f6156c3d21ece648208b4484bdaf78788e99034d95c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|