sgchemist


Namesgchemist JSON
Version 0.0.6 PyPI version JSON
download
home_pageNone
SummaryAn ORM for Autodesk Shotgrid
upload_time2024-07-17 12:10:36
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
licenseNone
keywords shotgrid shotgun slow production tracker orm
VCS
bugtrack_url
requirements shotgun-api3
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # sgchemist

[![Tests](https://github.com/PoloB/sgchemist/actions/workflows/test.yml/badge.svg)](https://github.com/PoloB/sgchemist/actions/workflows/test.yml)
[![codecov](https://codecov.io/gh/PoloB/sgchemist/graph/badge.svg?token=KNWN8UT6OK)](https://codecov.io/gh/PoloB/sgchemist)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![Checked with mypy](https://www.mypy-lang.org/static/mypy_badge.svg)](https://mypy-lang.org/)

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:

```python
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.
`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.

```python

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
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "sgchemist",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "Shotgrid, Shotgun, Slow Production Tracker, ORM",
    "author": null,
    "author_email": "Paul-Emile Buteau <paulemilebuteau@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/35/0a/418c453aff68d77a350a72ce3bf1a1f55054a20341f699d93183a4dd05ef/sgchemist-0.0.6.tar.gz",
    "platform": null,
    "description": "# sgchemist\n\n[![Tests](https://github.com/PoloB/sgchemist/actions/workflows/test.yml/badge.svg)](https://github.com/PoloB/sgchemist/actions/workflows/test.yml)\n[![codecov](https://codecov.io/gh/PoloB/sgchemist/graph/badge.svg?token=KNWN8UT6OK)](https://codecov.io/gh/PoloB/sgchemist)\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n[![Checked with mypy](https://www.mypy-lang.org/static/mypy_badge.svg)](https://mypy-lang.org/)\n\nAn Object Relation Mapper for Autodesk Flow Production Tracker (previously Shotgrid and Shotgun) inspired by SQLAlchemy.\n\n\n## Declaring entities\n\nYou can declare all the entities and fields using a dataclass like structure:\n\n```python\nfrom __future__ import annotations\n\nfrom sgchemist.orm import SgBaseEntity\nfrom sgchemist.orm import TextField\nfrom sgchemist.orm import EntityField\nfrom sgchemist.orm import MultiEntityField\n\n\nclass SgEntity(SgBaseEntity):\n    \"\"\"Base class for all the entities.\"\"\"\n\n    \nclass Project(SgEntity):\n    __sg_type__ = \"Project\"\n\n    name: TextField = TextField(name=\"code\")\n    title: TextField\n    assets: MultiEntityField[Asset]\n\n\nclass Asset(SgEntity):\n    __sg_type__ = \"Asset\"\n\n    name: TextField = TextField(name=\"code\")\n    description: TextField\n    project: EntityField[Project]\n\n```\n\n## Query building\n\nTo make a query using sgchemist, you need to use two elements:\n* an engine: responsible for communicating with your Shotgrid instance.\n`sgchemist` provides an engine implementation using the `shotgun-api3`.\n* and a session: responsible for converting raw data from the engine back to objects.\nIn case of creation and update querying it also implements the unit of work pattern.\n\n```python\n\nfrom shotgun_api3 import Shotgun\nfrom sgchemist.orm import ShotgunAPIEngine\nfrom sgchemist.orm import select\nfrom sgchemist.orm import Session\n\nfrom myentities import Asset, Project\n\n# Create the engine\nshotgun = Shotgun(\"https://mysite.shotgunstudio.com\", script_name=\"xyz\", api_key=\"abc\")\nengine = ShotgunAPIEngine(shotgun)\n\n# Create the session\nsession = Session(engine)\n\n# Create the query\nquery = select(Asset).where(Asset.project.f(Project.name).eq(\"myproject\"))\n\n# Perform the query using the session\nassets = list(session.exec(query))\n\n# Update the description of the assets\nwith session:\n    for asset in assets:\n        asset.description = \"This is an awesome asset\"\n        session.add(asset)\n# Assets are now updated\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "An ORM for Autodesk Shotgrid",
    "version": "0.0.6",
    "project_urls": {
        "Homepage": "https://github.com/PoloB/sgchemist",
        "Issues": "https://github.com/PoloB/sgchemist/issues"
    },
    "split_keywords": [
        "shotgrid",
        " shotgun",
        " slow production tracker",
        " orm"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "064b6649f20a05ce2d6a1f6156c3d21ece648208b4484bdaf78788e99034d95c",
                "md5": "58434dfeaf53c111937ab618d2147cfd",
                "sha256": "207b423be75c48b7e0347e387e95d67dc516b7cafc7c684428fb46f2d0a95ebf"
            },
            "downloads": -1,
            "filename": "sgchemist-0.0.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "58434dfeaf53c111937ab618d2147cfd",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 34793,
            "upload_time": "2024-07-17T12:10:34",
            "upload_time_iso_8601": "2024-07-17T12:10:34.822370Z",
            "url": "https://files.pythonhosted.org/packages/06/4b/6649f20a05ce2d6a1f6156c3d21ece648208b4484bdaf78788e99034d95c/sgchemist-0.0.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "350a418c453aff68d77a350a72ce3bf1a1f55054a20341f699d93183a4dd05ef",
                "md5": "296d9a43c1c476733b92a4d037a2ea8b",
                "sha256": "4a6c7db28733f13072ad20ec7dac73fd26c76dfde098b8f549b56d0005677e28"
            },
            "downloads": -1,
            "filename": "sgchemist-0.0.6.tar.gz",
            "has_sig": false,
            "md5_digest": "296d9a43c1c476733b92a4d037a2ea8b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 30044,
            "upload_time": "2024-07-17T12:10:36",
            "upload_time_iso_8601": "2024-07-17T12:10:36.411867Z",
            "url": "https://files.pythonhosted.org/packages/35/0a/418c453aff68d77a350a72ce3bf1a1f55054a20341f699d93183a4dd05ef/sgchemist-0.0.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-17 12:10:36",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "PoloB",
    "github_project": "sgchemist",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "shotgun-api3",
            "specs": []
        }
    ],
    "lcname": "sgchemist"
}
        
Elapsed time: 0.70006s