Copyright © 2024 Minura Punchihewa
Py-TwelveLabs is a Python library for interacting with the TwelveLabs API.
pip install py_twelvelabs
First, sign up for a TwelveLabs account here and get your API key.
The API key can either be passed to the constructor directly or through the environment variable TWELVE_LABS_API_KEY
like so:
export TWELVE_LABS_API_KEY=tlk_...
Then, import the library and create a client object:
from py_twelvelabs import TwelveLabsAPIClient
client = TwelveLabsAPIClient()
# OR
client = TwelveLabsAPIClient(api_key='tlk_...')
index_id = client.index.create(
index_name='my_index',
index_options=["visual", "conversation", "text_in_video", "logo"]
)
index = client.index.get(index_id)
index
will be an instance of the Index
class.
indexes = client.index.list()
indexes
will be a list of Index
objects.
client.index.update(
index_id=index_id,
index_name='my_index_updated'
)
client.index.delete(index_id)
Create a task asynchronously:
task_id = client.task.create_async(
index_id=index_id,
video_file='path/to/my/video.mp4'
)
task_id
will be a string representing the ID of the task.
Create a task synchronously:
task = client.task.create_sync(
index_id=index_id,
video_file='path/to/my/video.mp4'
)
task
will be an instance of the Task
class.
task = client.task.get(task_id)
task
will be an instance of the Task
class.
tasks = client.task.list()
tasks
will be a list of Task
objects.
client.task.delete(task_id)
results = client.search.query(
index_id=index_id,
search_query='my search query',
search_options=["visual", "conversation", "text_in_video", "logo"]
)