Vonage Video (API Client)

1.5.1 · active · verified Thu Apr 16

The `vonage-video` package provides programmatic access to the Vonage Video API, enabling server-side applications to manage video sessions, tokens, archives, and broadcasts. While it exists as a standalone PyPI package, it is primarily designed to be installed as a dependency of the main `vonage` Python SDK (currently v4.x.x). The `vonage` SDK is the recommended entry point for interacting with all Vonage APIs, including Video. Vonage maintains an active release cadence for its SDKs, with frequent updates and improvements.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the Vonage client, create a video session, and generate a client token. It uses environment variables for authentication credentials, which is recommended for security. Ensure you have a Vonage Application with Video capabilities enabled and the corresponding Application ID and Private Key file.

import os
from vonage import Vonage, Auth
from vonage_video.constants import MediaMode
from vonage_video import SessionOptions

# Replace with your actual Vonage Application ID and Private Key path
# Obtain these from your Vonage Dashboard after creating a Video-enabled application.
VONAGE_APPLICATION_ID = os.environ.get('VONAGE_APPLICATION_ID', 'YOUR_APPLICATION_ID')
VONAGE_PRIVATE_KEY_PATH = os.environ.get('VONAGE_PRIVATE_KEY_PATH', 'path/to/your/private.key')

if VONAGE_APPLICATION_ID == 'YOUR_APPLICATION_ID' or not os.path.exists(VONAGE_PRIVATE_KEY_PATH):
    print("Please set VONAGE_APPLICATION_ID environment variable and VONAGE_PRIVATE_KEY_PATH, and ensure the private key file exists.")
    print("Refer to https://developer.vonage.com/en/messages/application/create for creating an application.")
else:
    try:
        auth = Auth(
            application_id=VONAGE_APPLICATION_ID,
            private_key=VONAGE_PRIVATE_KEY_PATH,
        )
        client = Vonage(auth=auth)

        # Create a session
        session_options = SessionOptions(media_mode=MediaMode.ROUTED)
        session = client.video.create_session(session_options)
        session_id = session.session_id
        print(f"Created Session ID: {session_id}")

        # Generate a token for a client to connect to the session
        token = client.video.generate_client_token(session_id)
        print(f"Generated Client Token: {token}")

    except Exception as e:
        print(f"An error occurred: {e}")

view raw JSON →