Metadata-Version: 2.4
Name: python-sanity
Version: 0.1.0.dev0
Summary: Python client for Sanity.io CMS HTTP API
Home-page: https://github.com/OmniPro-Group/sanity-python
Download-URL: https://github.com/OmniPro-Group/sanity-python
Author: OmniPro
Author-email: OmniPro Group <git@none.com>, Nik Cubrilovic <git@nikcub.me>
License: MIT License
        
        Copyright (c) 2023 OmniPro-Group
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Keywords: sanity,sanity-http-api
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python
Requires-Python: <4.0,>=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.32.5
Dynamic: author
Dynamic: download-url
Dynamic: home-page
Dynamic: license-file

# sanity-python

Python client for Sanity.io CMS HTTP API.

> **ℹ️ Note:**
> This package is an active **fork** of the original project at [OmniPro-Group/sanity-python](https://github.com/OmniPro-Group/sanity-python/).


## Examples

```python
from sanity.client import Client
import logging
from scripts.colour_json import print_json_in_colour

logger = logging.getLogger(__name__)

project_id = "<project id>"
dataset = "<dataset>"
token = "<api token>"

client = Client(
    logger,
    project_id=project_id,
    dataset=dataset,
    token=token,
    use_cdn=True
)

# GET Query Method
result = client.query(
    groq="count(*[_type == 'post'])",
    explain=False,
    variables={
        "language": "es",
        "t": 4
    },
    method="GET"
)
print_json_in_colour(result)

# POST Query Method
result = client.query(
    groq="count(*[_type == 'post'])",
    variables={
        "language": "es",
        "t": 4
    },
    method="POST"
)
print_json_in_colour(result)

# Assets
png = "https://some.web.address.com/some_name.png"
result = client.assets(file_path=png)
print_json_in_colour(result)

png2 = "some_file_path/name"
result = client.assets(file_path=png2, mime_type="image/png")
print_json_in_colour(result)

# Mutate
transactions = [
    {
        "createOrReplace": {
            "_id": "speaker.asdf",
            "_type": "speaker",
            "title": "Some Name",
            "slug": {
                "_type": "slug",
                "current": "some-name"
            },
            'image': {
              '_type': 'image',
              'asset': {
                '_ref': 'image-6ffb37d2eeabc7d07b3ca485c7b497e77bdcccd4-1232x1280-png',
                '_type': 'reference'
              }
            }
        }
    }
]
result = client.mutate(
    transactions=transactions,
    return_ids=False,
    return_documents=False,
    visibility="sync",
    dry_run=False,
)
print_json_in_colour(result)
```
