Python client for Sanity.io CMS HTTP API
Project description
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.
Examples
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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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
File details
Details for the file python_sanity-0.1.0.dev1.tar.gz.
File metadata
- Download URL: python_sanity-0.1.0.dev1.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
89d791366fde28c2528367cfb1e71ed3c4f0801ab7969656b9442d7166999356
|
|
| MD5 |
1be614b028dd5021a2b530d77f4f837d
|
|
| BLAKE2b-256 |
9e23b06fc8ff0d6416628307d3cddd04c36a75cf7d223840f7feafafe3588611
|
File details
Details for the file python_sanity-0.1.0.dev1-py3-none-any.whl.
File metadata
- Download URL: python_sanity-0.1.0.dev1-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86d7894cb854f4e460567cf0c18fe989c8a0d036aa53985185fc46346706a495
|
|
| MD5 |
78f886439f6e84c0e20c35f93c0aa49c
|
|
| BLAKE2b-256 |
e6ba5681faab9811c21d8939963aad8eccd7e5df565b897040ba88ea6ffa1f04
|