TwelveLabs Python SDK

1.2.2 · active · verified Thu Apr 16

The TwelveLabs Python SDK provides a set of intuitive classes and methods that streamline platform interaction, minimizing the need for boilerplate code. It offers a robust interface for interacting with the TwelveLabs Video Understanding Platform, simplifying authentication and efficiently processing asynchronous tasks. The current version is 1.2.2 and releases are frequent, with breaking changes typically announced with major model updates or API shifts.

Common errors

Warnings

Install

Imports

Quickstart

Initializes the TwelveLabs client using an API key from an environment variable and lists existing indexes to confirm a successful connection.

import os
from twelvelabs import TwelveLabs

# It is recommended to set your API key as an environment variable:
# export TWELVELABS_API_KEY="YOUR_API_KEY"
api_key = os.environ.get("TWELVELABS_API_KEY", "YOUR_API_KEY")

if api_key == "YOUR_API_KEY":
    print("WARNING: Please set the 'TWELVELABS_API_KEY' environment variable or replace 'YOUR_API_KEY' in the code.")
    print("This quickstart will likely fail API calls without a valid key.")

try:
    client = TwelveLabs(api_key=api_key)
    print("Successfully initialized TwelveLabs client.")
    
    # Example: List existing indexes to verify connection and authentication
    indexes_response = client.indexes.list()
    indexes = indexes_response.data # Access the 'data' attribute for the list of indexes
    print(f"Found {len(indexes)} existing indexes:")
    for idx in indexes:
        print(f"- {idx.name} (ID: {idx.id}, Status: {idx.status})")

except Exception as e:
    print(f"An error occurred during client initialization or API call: {e}")

view raw JSON →