Python SDK for Oomol Cloud Task API
Project description
OOMOL Cloud Task SDK (Python)
Python SDK for OOMOL Cloud Task API v3.
Features
- Supports
serverlesstask creation - Covers the same user-facing task APIs as the TypeScript SDK:
create_task,create_and_wait,list_tasks,get_latest_tasks,get_task,get_task_result,get_dashboard,set_tasks_pause,upload_file - Supports
pause_user_queue,resume_user_queue, andget_task_detailaliases - Retries transient polling failures in
await_resultuntil timeout or terminal status - Exposes aligned error types:
ApiError,RunTaskError,TaskFailedError,TimeoutError,UploadError - Exports aligned public typing helpers such as
AwaitOptions,BackoffOptions,ClientOptions,UploadOptions, andTaskTerminalStatus
Installation
pip install oomol-cloud-task-sdk
Requirements
- Python
>=3.7 requests>=2.25.0typing_extensions>=4.0.0on Python 3.7
Authentication
api_key is optional.
- Token auth: pass
api_key, the client sendsAuthorization: Bearer <api_key> - Cookie auth: omit
api_keyand use the underlyingrequests.Sessioncookies
from oomol_cloud_task import OomolTaskClient
client = OomolTaskClient(
api_key=None,
default_headers={"x-client": "my-app"},
)
Quick Start
from oomol_cloud_task import BackoffStrategy, OomolTaskClient
client = OomolTaskClient(api_key="YOUR_API_KEY")
response = client.create_and_wait(
{
"packageName": "@oomol/my-package",
"packageVersion": "1.0.0",
"blockName": "main",
"inputValues": {"text": "hello"},
},
interval_ms=2000,
timeout_ms=10 * 60 * 1000,
backoff_strategy=BackoffStrategy.EXPONENTIAL,
max_interval_ms=10000,
on_progress=lambda progress, status: print("progress:", progress, "status:", status),
)
print("taskID:", response.taskID)
if response.result["status"] == "success":
print("resultURL:", response.result.get("resultURL"))
print("resultData:", response.result.get("resultData"))
API Overview
Available methods:
create_task(request)create_and_wait(request, interval_ms=3000, timeout_ms=None, backoff_strategy=BackoffStrategy.EXPONENTIAL, max_interval_ms=3000, on_progress=None)list_tasks(query=None)get_latest_tasks(workload_ids)get_task(task_id)/get_task_detail(task_id)get_task_result(task_id)await_result(task_id, interval_ms=3000, timeout_ms=None, backoff_strategy=BackoffStrategy.EXPONENTIAL, max_interval_ms=3000, on_progress=None)get_dashboard()set_tasks_pause(paused)pause_user_queue()resume_user_queue()upload_file(file, upload_base_url=..., retries=3, on_progress=None)
Common Examples
Create a task:
client.create_task(
{
"packageName": "@oomol/my-package",
"packageVersion": "1.0.0",
"blockName": "main",
"inputValues": {"foo": "bar"},
}
)
Query tasks:
page = client.list_tasks(
{
"size": 20,
"status": "running",
"taskType": "user",
}
)
latest = client.get_latest_tasks(
[
"550e8400-e29b-41d4-a716-446655440022",
"550e8400-e29b-41d4-a716-446655440023",
]
)
latest2 = client.get_latest_tasks(
"550e8400-e29b-41d4-a716-446655440022,550e8400-e29b-41d4-a716-446655440023"
)
detail = client.get_task("019234a5-b678-7def-8123-456789abcdef")
result = client.get_task_result("019234a5-b678-7def-8123-456789abcdef")
dashboard = client.get_dashboard()
Pause or resume the current user's queue:
client.pause_user_queue()
client.resume_user_queue()
client.set_tasks_pause(True)
client.set_tasks_pause(False)
Upload a file:
url = client.upload_file(
"/path/to/file.pdf",
retries=3,
on_progress=lambda progress: print("upload:", progress),
)
upload_file accepts either:
- a filesystem path
- a seekable binary file object
Polling Behavior
await_result and create_and_wait follow the same polling semantics as the TypeScript SDK:
- default polling interval is
3000ms BackoffStrategy.EXPONENTIALis the default- transient polling request failures are retried
- terminal task failure raises
TaskFailedError - timeout raises
TimeoutError
If polling times out after earlier request failures, the timeout message includes the most recent polling error.
Errors
from oomol_cloud_task import (
ApiError,
RunTaskErrorCode,
TaskFailedError,
TimeoutError,
UploadError,
)
try:
response = client.create_and_wait(
{
"packageName": "@oomol/my-package",
"packageVersion": "1.0.0",
"blockName": "main",
},
timeout_ms=60_000,
)
except TaskFailedError as err:
print(err.taskID, err.code, err.status_code, err.detail)
if err.code == RunTaskErrorCode.INSUFFICIENT_QUOTA:
print("insufficient quota")
except TimeoutError as err:
print("timeout:", err)
except UploadError as err:
print("upload error:", err.code, err.status_code, err)
except ApiError as err:
print("api error:", err.status, err.body)
License
MIT
Project details
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 oomol_cloud_task_sdk-1.1.0.tar.gz.
File metadata
- Download URL: oomol_cloud_task_sdk-1.1.0.tar.gz
- Upload date:
- Size: 13.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08df1c87bc0dfe8911cbc470bf9a5c68dc488230958a0b89aece9ac95f615789
|
|
| MD5 |
09f1b0c454ff543b7fd89ecfc6ed388f
|
|
| BLAKE2b-256 |
d9c8dc3d6cba971d71281720d5083969d0d66bd0bb88883ecf897d3dd0e1304a
|
File details
Details for the file oomol_cloud_task_sdk-1.1.0-py3-none-any.whl.
File metadata
- Download URL: oomol_cloud_task_sdk-1.1.0-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c1152052577d93176e52cabd34f4bb7e2aa3d54b95f9b358c93215cc4d4c752
|
|
| MD5 |
4aa366b6feefbc890b4c681959b5288d
|
|
| BLAKE2b-256 |
9e3c85c834b3300aac72be582f0b3dbd557cd04e9fe2147720952c0b95d6c35a
|