Installation
Quick Start
The SDK is fully async and uses standard Python async/await patterns:
import asyncio
from decart import DecartClient, models
import os
async def main():
# Using context manager (recommended for automatic cleanup)
async with DecartClient(api_key=os.getenv("DECART_API_KEY")) as client:
# Generate a video from text using the Queue API
result = await client.queue.submit_and_poll({
"model": models.video("lucy-pro-t2v"),
"prompt": "A cat walking in a lego world",
"resolution": "720p",
"on_status_change": lambda job: print(f"Status: {job.status}"),
})
if result.status == "completed":
with open("output.mp4", "wb") as f:
f.write(result.data)
print("Video saved!")
asyncio.run(main())
What can you build?
The SDK provides three main APIs for different use cases:
Client Setup
All APIs share the same client initialization:
import os
from decart import DecartClient
# Option 1: Context manager (recommended - automatic cleanup)
async with DecartClient(
api_key=os.getenv("DECART_API_KEY"),
base_url="https://custom-endpoint.com", # optional
) as client:
result = await client.process({...})
# Session automatically closed when done
# Option 2: Manual initialization
client = DecartClient(
api_key=os.getenv("DECART_API_KEY"),
base_url="https://custom-endpoint.com", # optional
)
# Remember to call await client.close() when done
Parameters:
api_key (required) - Your Decart API key from the platform
base_url (optional) - Custom API endpoint (defaults to Decart’s production API)
Use the context manager (async with) for automatic cleanup of HTTP connections.
Client Tokens
For client-side applications (browsers, mobile apps) using the Realtime API, create short-lived client tokens instead of exposing your permanent API key:
# On your backend
async with DecartClient(api_key=os.getenv("DECART_API_KEY")) as client:
token = await client.tokens.create()
# token.api_key - send to your frontend for secure client-side authentication
# token.expires_at - expiration timestamp
Available Models
Import models from the SDK to use with either API:
from decart import models
# Video models
models.video("lucy-pro-t2v") # Text-to-video
models.video("lucy-pro-i2v") # Image-to-video
models.video("lucy-dev-i2v") # Image-to-video (dev)
models.video("lucy-pro-v2v") # Video-to-video
models.video("lucy-fast-v2v") # Video-to-video (fast)
# Image models
models.image("lucy-pro-t2i") # Text-to-image
models.image("lucy-pro-i2i") # Image-to-image
# Realtime models
models.realtime("mirage") # Realtime video transformation
models.realtime("mirage_v2") # Realtime video transformation (v2)
models.realtime("lucy_v2v_720p_rt") # Realtime video editing
Async/Await
All SDK methods are asynchronous and must be called with await. If you’re new to async Python:
- Use
async def for functions that call SDK methods
- Call async functions with
await
- Run async code with
asyncio.run(main())
- For scripts or notebooks, you can use the sync wrapper pattern shown above
Type Hints Support
The SDK includes full type hints for better IDE support and type checking. Each model enforces its own required inputs, so you’ll get autocomplete and helpful errors if something is missing.
# Image-to-video requires 'data' field
await client.queue.submit_and_poll({
"model": models.video("lucy-pro-i2v"),
"prompt": "Make it cinematic",
"data": image_file, # ✅ Required
})
# Text-to-video doesn't need 'data'
await client.queue.submit_and_poll({
"model": models.video("lucy-pro-t2v"),
"prompt": "A cat walking",
"data": image_file, # ❌ Type error
})
Ready to start building?