Metadata-Version: 2.5
Name: render-lab-tasks-sanity
Version: 0.1.0
Summary: sanity tasks for Render Workflows
Project-URL: Repository, https://github.com/render-lab/render-tasks-python
License-Expression: MIT
License-File: LICENSE
Requires-Python: >=3.12
Requires-Dist: httpx<0.29,>=0.28
Requires-Dist: render-lab-tasks-core<0.2,>=0.1.1
Requires-Dist: render-lab-triggers<0.2,>=0.1.0
Requires-Dist: render==1.0.1
Description-Content-Type: text/markdown

# render-lab-tasks-sanity

Python port of all 10 registered tasks in the pinned TypeScript pack at
`45f9c2d44bd28e01ae9813e0d2ff56ee6c533816`. Python 3.12+.

Install this distribution and its dependencies:

```sh
pip install render-lab-tasks-sanity==0.1.0
```

Import definitions from `render_lab_tasks_sanity.tasks`; combine `app` objects
with `Workflows.from_workflows(...)`. JSON fields retain TS spelling; functions
use snake_case. Package root imports are inert.

## Tasks

| Registered name | Python export (also exposes `_impl`) |
| --- | --- |
| `sanity.createDocument` | `create_document` |
| `sanity.deleteAsset` | `delete_asset` |
| `sanity.deleteByQuery` | `delete_by_query` |
| `sanity.deleteDocument` | `delete_document` |
| `sanity.getDocument` | `get_document` |
| `sanity.getDocuments` | `get_documents` |
| `sanity.mutate` | `mutate` |
| `sanity.patchDocument` | `patch_document` |
| `sanity.query` | `query` |
| `sanity.uploadAsset` | `upload_asset` |

## Dependencies and retries

Raw implementations accept context first and keyword-only `deps`. The `.client`
module exports typed `Port`, `Deps`, and `Client` classes. Inject a fake port, or
pass a caller-owned `httpx.AsyncClient` to `Client`. Default dependencies close
their client after one operation. Credentials resolve at first use. Transport
retries are disabled; `retry.py` owns durable policies. DTO types are in `.types`.
Requires core >=0.1.1.

## Environment

| Variable | Contract |
| --- | --- |
| `SANITY_PROJECT_ID` | Required project. |
| `SANITY_DATASET` | Required dataset. |
| `SANITY_API_TOKEN` | Required for all API operations. |
| `SANITY_API_VERSION` | Optional version; defaults to `v2025-02-19`. |

## Verification and limitations

The Python adapter translates the TS @sanity/client seam into direct HTTP with
CDN disabled and API version v2025-02-19 by default. Documents preserve arbitrary
JSON fields. Multi-get preserves input order/null slots, caps IDs at 1,000, and
rejects results at or above 4 MiB; query has the same byte ceiling. Uploads accept
at most 2 MiB of decoded base64. Python forwards ifRevisionId as the API's
ifRevisionID patch guard. Mutations retain TS retries; increment and arbitrary
mutation batches may be applied more than once after ambiguous failures. Live
revision-conflict and duplicate-write verification are still required.

Shared fixtures execute the actual pinned TS implementations and compare Python
outputs and requests. Sanity's SDK calls are translated into separately asserted
REST requests. These are hermetic checks, not real account or hosted verification.
See [the testing backlog](https://github.com/render-lab/render-tasks-python/issues/1)
and the root verification tracker. Licensed under MIT.

## Webhook adapter

`render_lab_tasks_sanity.webhooks.sanity_adapter(on_event, ...)` returns a
registration-free adapter for `render_lab_triggers`. The callback receives the
verified event and returns `{"task": "namespace.task", "args": [event]}` or `None`.
The signing credential `SANITY_WEBHOOK_SECRET` is read inside verification unless
provided explicitly. Importing this module does not register tasks. Signature
checks use the raw body; live delivery remains in the testing backlog.
