Registry / communication / opentok

opentok

JSON →
library3.14.0pypypi✓ verified 22d ago

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 opentok
INSTALL
IMPORT
SIG · OPENTOK
O
opentok
communicationpythonv3.14.0
Install
3.4s avg
Import
498ms
Disk
41MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.14.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.524s · 42.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.4s · import 0.472s · 43MB
41MB installed
● package 41MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Client
from opentok import Client
from opentok import OpenTok
The primary class was renamed from `OpenTok` to `Client` in version 3.x.x. Using `OpenTok` will raise an `AttributeError` or `ImportError` in recent versions.
MediaModes
from opentok import MediaModes
Used to specify the media routing mode when creating a session (e.g., `MediaModes.routed`).

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.

import os from opentok import Client, MediaModes # Replace with your OpenTok API key and secret API_KEY = os.environ.get('OPENTOK_API_KEY', 'YOUR_API_KEY') API_SECRET = os.environ.get('OPENTOK_API_SECRET', 'YOUR_API_SECRET') if not API_KEY or not API_SECRET or API_KEY == 'YOUR_API_KEY': print("WARNING: Please set OPENTOK_API_KEY and OPENTOK_API_SECRET environment variables or replace placeholders.") exit(1) try: # Initialize an OpenTok Client instance opentok_client = Client(API_KEY, API_SECRET) # Create a session that uses the OpenTok Media Router # The routed mode is required for features like archiving. # For a relayed (peer-to-peer) session, use MediaModes.relayed or omit parameter for default. session = opentok_client.create_session(media_mode=MediaModes.routed) session_id = session.session_id print(f"Session ID: {session_id}") # Generate a token for a publisher role in this session # By default (since v3.10.0), JWTs are generated. For legacy T1 tokens, use `use_jwt=False`. token = opentok_client.generate_token(session_id) print(f"Generated Token: {token}") # In a real application, you would send `session_id` and `token` to your client-side application. except Exception as e: print(f"An error occurred: {e}")
Debug
Known issues
breakingThe main class for interacting with the SDK was renamed from `OpenTok` to `Client` in version 3.x.x. Code using `from opentok import OpenTok` or `OpenTok.OpenTok()` will fail in versions 3.0 and above.
fix
Update imports to `from opentok import Client` and instantiate with `Client(api_key, api_secret)`.
affects: >=3.0.0
breakingAs of v3.10.0, the `Client.generate_token()` method now generates JWT (JSON Web Token) formatted tokens by default. Previously, it generated T1 tokens by default.
fix
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.
affects: >=3.10.0
gotchaThe `opentok` Python SDK is specifically for the legacy Tokbox/OpenTok platform, even though OpenTok is now part of the Vonage Video API. For new projects or migrations to the unified Vonage platform, it is recommended to use the `vonage` Python SDK, which has a different import path (`from vonage import Vonage` then `vonage_client.video`) and uses different authentication (application ID and private key instead of API key/secret).
fix
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.
affects: All versions
gotchaThe default `media_mode` for sessions created via `create_session()` changed from `MediaModes.routed` to `MediaModes.relayed` in v2.2.1. Relayed (peer-to-peer) sessions have limitations, particularly regarding archiving or certain advanced features, which require `routed` sessions.
fix
If you need features like archiving or server-side media processing, always explicitly set `media_mode=MediaModes.routed` when calling `create_session()`.
affects: >=2.2.1
Errors
Common errors & fixes
Failed to create session, invalid credentials
This error typically occurs when the OpenTok API Key or API Secret provided are incorrect, expired, or there's a server time synchronization issue affecting the JWT generation for authentication.
fix
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.
ModuleNotFoundError: No module named 'opentok'
This means the `opentok` Python package is not installed in your current environment or there is a naming conflict (e.g., your script is named `opentok.py`).
fix
Install the package using pip: `pip install opentok`. If your script is named `opentok.py`, rename it to avoid conflicts with the library itself.
The token is invalid
The generated token is either expired, was generated for a different session ID, or contains incorrect or malformed data.
fix
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`.
Passing 'archive_name' with archive mode 'manual' will cause an error response.
The `archive_name` and `archive_resolution` parameters are only valid when creating a session with `archive_mode=MediaModes.always` (auto-archived sessions), not with `archive_mode=MediaModes.manual`.
fix
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.
Upgrade
Version history
3.14.0latest on PyPI · released Jun 25, 2026
Audit
Dependencies
requestsrequiredUsed for making HTTP requests to the OpenTok API.
PyJWTrequiredUsed for generating JSON Web Tokens (JWTs) for authentication and token generation.
Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources
opentok — pip install opentok · libregistry