Oomol Connect SDK for Python
Project description
Oomol Connect SDK for Python
Official Python SDK for Oomol Connect API. This SDK provides a complete, type-safe interface for interacting with Oomol Connect services.
Features
- ✨ Complete API Coverage - Full support for all Oomol Connect API endpoints
- 🔄 Smart Polling - Intelligent polling with exponential backoff strategy
- 📊 Progress Monitoring - Real-time callbacks for task progress and logs
- 📁 File Upload - Support for single and multiple file uploads
- 🎯 Type Safe - Full type annotations with TypedDict support
- ⚡ Async First - Modern async design based on asyncio and httpx
- 🛡️ Error Handling - Comprehensive error classification and handling
Installation
pip install oomol-connect-sdk
Quick Start
import asyncio
from oomol_connect_sdk import OomolConnectClient
async def main():
async with OomolConnectClient(
base_url="http://localhost:3000/api",
api_token="your-api-token"
) as client:
# Run a task and get results
result = await client.tasks.run({
"blockId": "audio-lab::text-to-audio",
"inputValues": {"text": "Hello, World"}
})
print(f"Task ID: {result['task_id']}")
print(f"Result: {result['result']}")
asyncio.run(main())
Core Concepts
Client Initialization
from oomol_connect_sdk import OomolConnectClient
client = OomolConnectClient(
base_url="/api", # API base URL
api_token="your-token", # API token (auto-added to Authorization header)
default_headers={}, # Custom headers (optional)
timeout=30.0 # Request timeout in seconds
)
Task Management
# Simple task execution (recommended)
result = await client.tasks.run({
"blockId": "audio-lab::text-to-audio",
"inputValues": {"text": "Hello"}
})
# With progress monitoring
result = await client.tasks.run(
{
"blockId": "audio-lab::text-to-audio",
"inputValues": {"text": "Hello"}
},
{
"interval_ms": 1000,
"timeout_ms": 60000,
"on_progress": lambda task: print(f"Status: {task['status']}"),
"on_log": lambda log: print(f"Log: {log['type']}")
}
)
Input Value Formats
The SDK automatically normalizes three input formats:
# Format 1: Simple object (most common)
{"input1": "value1", "input2": 123}
# Format 2: Array format
[
{"handle": "input1", "value": "value1"},
{"handle": "input2", "value": 123}
]
# Format 3: Node format (for multi-node scenarios)
[
{
"nodeId": "node1",
"inputs": [{"handle": "input1", "value": "value1"}]
}
]
File Upload
# Single file upload
with open("test.txt", "rb") as f:
result = await client.tasks.run_with_files(
"pkg::file-processor",
{"input1": "value"},
f
)
# Multiple files upload
with open("file1.txt", "rb") as f1, open("file2.txt", "rb") as f2:
result = await client.tasks.run_with_files(
"pkg::multi-file-processor",
{"input1": "value"},
[f1, f2]
)
API Reference
Tasks Client
Core API for task management:
list()- List all taskscreate(request)- Create a task (JSON format)create_with_files(block_id, input_values, files)- Create task with file uploadget(task_id)- Get task detailsstop(task_id)- Stop a taskget_logs(task_id)- Get task logswait_for_completion(task_id, options)- Poll until task completescreate_and_wait(request, polling_options)- Create and wait for completionrun(request, polling_options)- Recommended - One-step run and get resultsrun_with_files(block_id, input_values, files, polling_options)- One-step run with files
Blocks Client
# List all blocks (only latest versions by default)
blocks_response = await client.blocks.list()
for block in blocks_response["blocks"]:
print(f"{block['blockId']} - v{block['version']}")
# Example output: ffmpeg::audio_video_separation - v0.1.9
# List all versions
all_blocks = await client.blocks.list(include_all_versions=True)
Packages Client
# List installed packages
packages = await client.packages.list()
# Install a package
install_task = await client.packages.install("package-name", "1.0.0")
# Install and wait for completion
install_task = await client.packages.install_and_wait("package-name", "1.0.0")
Applets Client
Applets are blocks with preset parameters. The Applets Client provides convenient methods to discover and run them:
# List all available applets
applets = await client.applets.list()
for applet in applets:
print(f"Applet ID: {applet['appletId']}")
print(f" Title: {applet['data'].get('title', 'N/A')}")
print(f" Package: {applet['data']['packageId']}")
print(f" Block: {applet['data']['blockName']}")
print(f" Preset Inputs: {applet['data'].get('presetInputs', {})}")
# Run an applet with all preset parameters
result = await client.applets.run(
applet_id="84dc8cac-7f91-4bd1-a3b6-6715bf4f81c9"
)
print(f"Result: {result['result']}")
# Run an applet and override some parameters
result = await client.applets.run(
applet_id="84dc8cac-7f91-4bd1-a3b6-6715bf4f81c9",
input_values={"content": "test", "indent": 4}
)
# Run with progress monitoring
result = await client.applets.run(
applet_id="84dc8cac-7f91-4bd1-a3b6-6715bf4f81c9",
input_values={"content": "test"},
polling_options={
"interval_ms": 2000,
"on_progress": lambda task: print(f"Status: {task['status']}"),
"on_log": lambda log: print(f"Log: {log['type']}")
}
)
Note: Applets queries use a built-in query server (https://chat-data.oomol.com), while task execution uses your configured server.
Polling Options
from oomol_connect_sdk import BackoffStrategy
polling_options = {
"interval_ms": 2000, # Polling interval (milliseconds)
"timeout_ms": 300000, # Timeout (milliseconds)
"max_interval_ms": 10000, # Maximum interval (milliseconds)
"backoff_strategy": BackoffStrategy.EXPONENTIAL, # Backoff strategy
"backoff_factor": 1.5, # Backoff factor
"on_progress": lambda task: ..., # Progress callback
"on_log": lambda log: ... # Log callback
}
Error Handling
from oomol_connect_sdk import (
OomolConnectError, # Base class
ApiError, # HTTP errors
TaskFailedError, # Task execution failed
TaskStoppedError, # Task was stopped
TimeoutError, # Polling timeout
InstallFailedError # Package installation failed
)
try:
result = await client.tasks.run({
"blockId": "audio-lab::text-to-audio",
"inputValues": {"text": "test"}
})
except TaskFailedError as e:
print(f"Task failed: {e.task_id}")
except ApiError as e:
print(f"HTTP {e.status}: {e.message}")
Advanced Usage
Concurrent Tasks
import asyncio
tasks = [
client.tasks.run({
"blockId": "audio-lab::text-to-audio",
"inputValues": {"text": f"test-{i}"}
})
for i in range(5)
]
results = await asyncio.gather(*tasks)
Custom Backoff Strategy
from oomol_connect_sdk import BackoffStrategy
result = await client.tasks.run(
{"blockId": "audio-lab::text-to-audio", "inputValues": {"text": "Hello"}},
{
"interval_ms": 1000,
"max_interval_ms": 5000,
"backoff_strategy": BackoffStrategy.EXPONENTIAL,
"backoff_factor": 2.0
}
)
Examples
See examples/ directory for more examples:
basic_usage.py- Basic usage examplesadvanced_usage.py- Advanced features and patternsapplets_usage.py- Applets API usage examples
Development
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Type checking
mypy oomol_connect_sdk
Requirements
- Python >= 3.8
- httpx >= 0.27.0
License
MIT License - see LICENSE file for details
Links
- PyPI: https://pypi.org/project/oomol-connect-sdk/
- Source Code: https://github.com/oomol/oomol-connect-sdk-py
- Issue Tracker: https://github.com/oomol/oomol-connect-sdk-py/issues
- TypeScript Version: https://github.com/oomol/oomol-connect-sdk-ts
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
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_connect_sdk-1.0.3.tar.gz.
File metadata
- Download URL: oomol_connect_sdk-1.0.3.tar.gz
- Upload date:
- Size: 24.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c6d2104752bddf7438b490084c8e44b82fc6097a178793e3f99950d8e36483e
|
|
| MD5 |
e74ffed23058098489fba3eb52bd5b1a
|
|
| BLAKE2b-256 |
032f1a8e03c318173d7aed7ecaf72123057f3bd072de4c5901ce3de1a725e96a
|
File details
Details for the file oomol_connect_sdk-1.0.3-py3-none-any.whl.
File metadata
- Download URL: oomol_connect_sdk-1.0.3-py3-none-any.whl
- Upload date:
- Size: 19.7 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 |
36cefb30fe7e57016ab1c5f2a0b4ac82df5e2a0141856694f8e99c71968914ff
|
|
| MD5 |
e208bdc2d951bdee571203dafc53a777
|
|
| BLAKE2b-256 |
43b72ec8ec0ee2be1f904b0f243c6e1ff3cfdb61cb76595aca88b9112ec44335
|