Client library for the Sandai Operator SDK
Project description
Sandai Operator Client
Lightweight Python client for submitting tasks to a Sandai operator over Celery.
Installation
pip install sandai-operator-client
For local development:
pip install -e ".[dev]"
Quick Start
from sandai.operator_client import create_client
client = create_client("video-clipper", "v1")
artifacts, results = client.sync(
input_artifacts=[{"uri": "file:///tmp/input.mp4", "slot": "video"}],
options={"clip_duration": 10},
)
Async usage:
import asyncio
from sandai.operator_client import create_async_client
async def main() -> None:
async with create_async_client("video-clipper", "v1") as client:
artifacts, results = await client.sync(
input_artifacts=[{"uri": "file:///tmp/input.mp4", "slot": "video"}],
options={"clip_duration": 10},
)
print(artifacts, results)
asyncio.run(main())
Core API
- Sync client:
create_client(operator_name, operator_version, **kwargs)returnsOperatorClient. - Async client:
create_async_client(operator_name, operator_version, **kwargs)returnsAsyncOperatorClient. - Sync submit:
client.async_call(...)returns CeleryAsyncResult. - Async submit:
await async_client.async_call(...)returnsAsyncTaskHandle. - Sync request/response:
client.sync(...)returns(artifacts, results). - Async request/response:
await async_client.sync(...)returns(artifacts, results). - Sync description:
client.descis a cached property. - Async description:
await async_client.desc()is an async cached method. - Sync legacy batch APIs:
batch_async(...)andbatch_sync(...)keep the existing best-effort contract. - Async legacy-shaped batch APIs:
await async_client.batch_async(...)andawait async_client.batch_sync(...)keep the same result shapes in async call sites. - Structured batch APIs:
batch_submit(...),batch_collect(...), andbatch_sync_detailed(...)are available on both clients. - Health APIs:
probe()/ping()exist on both clients, withawaitrequired on the async client. get_queue_info()returns the queue names used for each priority.
Task Controls
The client supports the same task-control fields used by the operator runtime:
timeout: converted into an absolutedeadlinebefore sending the task.cancel_key: propagated to the operator so tasks can be skipped before compute starts.persistent_output: stored undermeta["persistent-output"]for runtimes that preserve uploaded outputs.
Batch APIs
The package now exposes two batch styles:
- Legacy compatibility APIs:
batch_async(...)andbatch_sync(...)keep the previous best-effort semantics. - Structured APIs:
batch_submit(...),batch_collect(...), andbatch_sync_detailed(...)expose explicit per-task submission/execution status instead of collapsing failures into empty results.
Async batch methods follow the same contract, but are awaited:
await async_client.batch_submit(...)returnsAsyncSubmittedTaskobjects.await async_client.batch_async(...)returnsAsyncTaskHandle | Noneper task.await async_client.batch_collect(...)returnsBatchTaskResultobjects.await async_client.batch_sync_detailed(...)returnsBatchTaskResultobjects.await async_client.batch_sync(...)returns legacy(artifacts, results)tuples.
Prefer the structured APIs for new integrations.
Async API
AsyncOperatorClient is an additive API layer. It does not remove or replace OperatorClient.
AsyncTaskHandle exposes:
task_id/idawait handle.get(timeout=...)await handle.ready()await handle.state()await handle.forget()
Implementation notes:
- Task submission remains compatible with the current Celery-based operator side.
- When
result_backendis Redis, the async client usesredis.asyncioplus a shared polling hub for async result waiting. - The async client is intended for async application integration and lower blocking overhead on result collection.
- The sync client remains the compatibility/default path for existing callers.
Health Checks
ping() and probe() are intentionally different:
ping()returnsTruewhen task submission succeeds.probe()returns a structuredHealthCheckResultwithsubmit_ok,retrieval_ok,response_ok, and optional error details.
Use probe() when you need a meaningful health signal.
Priority Model
Supported priorities are:
highnormallowvery_low
Queue names follow this pattern:
<priority>.<operator_name>.<operator_version>
Environment Variables
The client reads these settings when explicit connection arguments are not provided:
SANDAI_OPERATOR_CELERY_BROKER_URLSANDAI_OPERATOR_CELERY_RESULT_BACKENDSANDAI_OPERATOR_CELERY_TASK_SERIALIZERSANDAI_OPERATOR_CELERY_RESULT_SERIALIZERSANDAI_OPERATOR_AUTO_FORGET_RESULT
If broker/backend are not configured, the client falls back to local Redis defaults:
redis://localhost:6379/0
By default the client now submits Celery task payloads with msgpack, keeps Celery results on json, and advertises both json and msgpack in accept_content so it can interoperate with operators during rollout.
Error Model
sync() and desc normalize failures into typed exceptions where possible:
TaskTimeoutErrorTaskExecutionErrorTaskDeadlineExceededErrorTaskCancelledErrorInvalidTaskStatusErrorInvalidResultFormatErrorInvalidPriorityError
Structured batch APIs surface task errors directly on each result object instead of converting them into empty legacy tuples.
Testing
Run the client regression suite from the repository root:
python operator-client/tests/run_all_tests.py
The suite is mock-based and does not require a live Celery or Redis deployment.
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 sandai_operator_client-0.4.6.tar.gz.
File metadata
- Download URL: sandai_operator_client-0.4.6.tar.gz
- Upload date:
- Size: 22.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
38edd63db2872e1a6f2202b14a24e3c569b29426f4c895fa7b3b9c3948548a98
|
|
| MD5 |
aeb317ae55cbbce90e8f9102c0c95041
|
|
| BLAKE2b-256 |
27d944baa07fe0ed9301727f4a9396074b9c673f2a417e5788158138ebc9b3cd
|
File details
Details for the file sandai_operator_client-0.4.6-py3-none-any.whl.
File metadata
- Download URL: sandai_operator_client-0.4.6-py3-none-any.whl
- Upload date:
- Size: 16.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2648999fb8401f188f7d935f83d872358fa2f5035cdfa8a34d065e0def93619b
|
|
| MD5 |
b34bfe2a381c478c5c0d00026b1641c4
|
|
| BLAKE2b-256 |
8a77a010ef7a51b0449b0f188f54df64761fbc6130c3d883787f257c4d7f63e0
|