> ## Documentation Index
> Fetch the complete documentation index at: https://docs.platform.decart.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Overview

> A Python SDK for Decart's models

<Card title="GitHub" icon="github" href="https://github.com/DecartAI/decart-python">
  View source code and contribute
</Card>

## Installation

```bash theme={null}
pip install decart
```

## Quick Start

The SDK is fully async and uses standard Python async/await patterns:

```python theme={null}
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.1"),
            "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...                   | Use          | Main method                      |
| ----------------------------------- | ------------ | -------------------------------- |
| Transform live streams over WebRTC  | Realtime API | `RealtimeClient.connect()`       |
| Generate/edit videos asynchronously | Queue API    | `client.queue.submit_and_poll()` |
| Generate/edit images synchronously  | Process API  | `client.process()`               |

<CardGroup cols={3}>
  <Card title="Realtime API" href="/sdks/python-realtime">
    Realtime video streams
  </Card>

  <Card title="Queue API" href="/sdks/python-queue">
    Video processing
  </Card>

  <Card title="Process API" href="/sdks/python-process">
    Image editing
  </Card>
</CardGroup>

<Tip>
  Use `async with DecartClient(...)` for automatic connection cleanup in production services.
</Tip>

## Client Setup

All APIs share the same client initialization:

```python theme={null}
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](https://platform.decart.ai)
* `base_url` (optional) - Custom API endpoint (defaults to Decart's production API)

<Tip>Use the context manager (`async with`) for automatic cleanup of HTTP connections.</Tip>

## 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:

```python theme={null}
# 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 and origins with a longer TTL
    token = await client.tokens.create(
        expires_in=300,
        allowed_models=["lucy-2.1"],
        allowed_origins=["https://app.example.com"],  # browser-enforced; canonical origin
    )
```

<Tip>
  See [Client Tokens](/getting-started/client-tokens) for details on secure realtime auth.
</Tip>

## Available Models

Import models from the SDK to use with either API:

```python theme={null}
from decart import models

# Realtime models
models.realtime("lucy-2.1")              # Realtime video editing (latest)
models.realtime("lucy-2.1-vton")         # Virtual try-on
models.realtime("lucy-restyle-2")        # Realtime video restyling

# Video models
models.video("lucy-2.1")                # Video editing (latest)
models.video("lucy-2.1-vton")           # Virtual try-on
models.video("lucy-restyle-2")          # Video restyling

# Image models
models.image("lucy-image-2")            # Image editing

# Latest aliases — always point to the newest version
models.realtime("lucy-latest")           # Latest realtime editing model
models.video("lucy-latest")              # Latest video editing model
models.video("lucy-vton-latest")         # Latest virtual try-on model
models.video("lucy-restyle-latest")      # Latest video restyling model
models.image("lucy-image-latest")        # Latest image editing model
```

<Accordion title="Previous generation models">
  ```python theme={null}
  # Video models
  models.video("lucy-clip")         # Lucy Clip
  ```
</Accordion>

## 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.

```python theme={null}
# Video editing requires 'data' field
await client.queue.submit_and_poll({
    "model": models.video("lucy-2.1"),
    "prompt": "Transform into anime style",
    "data": video_file,  # ✅ Required
})

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

## Ready to start building?

<CardGroup cols={3}>
  <Card title="Realtime API Guide" href="/sdks/python-realtime">
    **Build realtime experiences**

    Learn WebRTC integration, camera handling, and how to create interactive video applications.
  </Card>

  <Card title="Queue API Guide" href="/sdks/python-queue">
    **Video processing**

    Edit videos, control motion, and transform videos with style transfer.
  </Card>

  <Card title="Process API Guide" href="/sdks/python-process">
    **Image editing**

    Edit and transform images on-demand with synchronous processing.
  </Card>
</CardGroup>
