The OpenTok Python SDK provides server-side functionality for interacting with the OpenTok platform, which is part of the Vonage Video API. It enables developers to generate sessions and tokens for OpenTok applications, manage archiving of video sessions, and utilize other core video functionalities. The library is actively maintained, with the current version being 3.13.0, and receives regular updates.
pip install opentokVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the OpenTok Client, create a new session, and generate a client token. It's crucial to set your `OPENTOK_API_KEY` and `OPENTOK_API_SECRET` as environment variables for secure and functional use. The example creates a 'routed' session, which is necessary for features like archiving. A token is then generated for connecting a client to this session.
Update imports to `from opentok import Client` and instantiate with `Client(api_key, api_secret)`.
If your client-side applications or existing logic explicitly requires T1 tokens, you must now call `opentok_client.generate_token(session_id, use_jwt=False)`. Most modern client SDKs support JWTs.
Determine whether you are building for the legacy OpenTok platform or the unified Vonage Video API. If the latter, consider using the `vonage` Python SDK and following its migration guide.
If you need features like archiving or server-side media processing, always explicitly set `media_mode=MediaModes.routed` when calling `create_session()`.
Ensure your API Key and API Secret are correct and active. Verify your server's system time is accurate and synchronized with an internet time server to prevent JWT expiration issues. If you are using environment variables, double-check their values.
Install the package using pip: `pip install opentok`. If your script is named `opentok.py`, rename it to avoid conflicts with the library itself.
Generate a new token for the specific session ID you are trying to connect to. Ensure the `expire_time` parameter for token generation is set appropriately and that the token is used with the correct `session_id`.
When creating a session with `archive_mode=MediaModes.manual`, do not pass `archive_name` or `archive_resolution`. These parameters are only applicable for automatically archived sessions.