Skip to main content

GitHub

View source code and contribute

Installation

pip install decart

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:
        # Edit a video using the Queue API
        result = await client.queue.submit_and_poll({
            "model": models.video("lucy-2-v2v"),
            "data": video_file,
            "prompt": "Transform into anime style",
            "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:
If you need to…UseMain method
Transform live streams over WebRTCRealtime APIRealtimeClient.connect()
Generate/edit videos asynchronouslyQueue APIclient.queue.submit_and_poll()
Generate/edit images synchronouslyProcess APIclient.process()

Realtime API

Realtime video streams

Queue API

Video processing

Process API

Image editing
Use async with DecartClient(...) for automatic connection cleanup in production services.

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 — basic (60s TTL, unrestricted)
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

    # Or scoped to specific models with a longer TTL
    token = await client.tokens.create(
        expires_in=300,
        allowed_models=["lucy_2_rt"],
    )
See Client Tokens for details on secure realtime auth.

Available Models

Import models from the SDK to use with either API:
from decart import models

# Realtime models
models.realtime("lucy_2_rt")         # Realtime video editing
models.realtime("mirage_v2")         # Realtime video restyling
models.realtime("live_avatar")       # Avatar animation with audio

# Video models
models.video("lucy-2-v2v")           # Video editing
models.video("lucy-restyle-v2v")     # Video restyling
models.video("lucy-motion")          # Trajectory-based motion control

# Image models
models.image("lucy-pro-i2i")         # Image editing
# Realtime models
models.realtime("lucy_v2v_720p_rt")  # Realtime video editing
models.realtime("mirage")            # Realtime video transformation

# Video models
models.video("lucy-pro-v2v")         # Lucy Edit v1

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.
# Video editing requires 'data' field
await client.queue.submit_and_poll({
    "model": models.video("lucy-2-v2v"),
    "prompt": "Transform into anime style",
    "data": video_file,  # ✅ Required
})

# Image editing requires 'data' field
await client.process({
    "model": models.image("lucy-pro-i2i"),
    "prompt": "Change the background to a beach",
    "data": image_file,  # ✅ Required
})

Ready to start building?

Realtime API Guide

Build realtime experiencesLearn WebRTC integration, camera handling, and how to create interactive video applications.

Queue API Guide

Video processingEdit videos, control motion, and transform videos with style transfer.

Process API Guide

Image editingEdit and transform images on-demand with synchronous processing.