Mux Python SDK
Official Mux API wrapper for Python projects, supporting both Mux Data and Mux Video. Mux Video is an API-first platform for building video experiences, while Mux Data provides quality of service analytics. The library is currently at version 5.1.2 and is actively maintained with frequent patch and minor releases.
Warnings
- breaking In version 5.0.0, `CreateAssetRequest` changed `input` to `inputs` and `playback_policy` to `playback_policies`. While deprecation notices were added for the old fields, direct usage should update to the new array-accepting fields.
- deprecated The `encoding_tier` parameter has been deprecated since version 3.18.0 and replaced by `video_quality` (e.g., 'standard' or 'premium').
- gotcha Mux Python SDK, being code-generated, wraps API responses in an object where the main data payload is often accessed via a `.data` attribute (e.g., `response.data`). Forgetting `.data` will result in accessing the wrapper object instead of the actual API resource.
- gotcha The Mux Python SDK is not designed for parsing or modeling webhook payloads directly. Attempting to use SDK models for webhook events may lead to unexpected behavior or errors.
Install
-
pip install mux-python
Imports
- Configuration
import mux_python configuration = mux_python.Configuration()
- ApiClient
client = mux_python.ApiClient(configuration)
- ApiException
from mux_python.rest import ApiException
- AssetsApi
assets_api = mux_python.AssetsApi(client)
Quickstart
import os
import mux_python
from mux_python.rest import ApiException
# Authentication Setup
configuration = mux_python.Configuration()
configuration.username = os.environ.get('MUX_TOKEN_ID', '')
configuration.password = os.environ.get('MUX_TOKEN_SECRET', '')
if not configuration.username or not configuration.password:
print("Error: MUX_TOKEN_ID and MUX_TOKEN_SECRET environment variables must be set.")
exit(1)
# API Client Initialization
api_client = mux_python.ApiClient(configuration)
assets_api = mux_python.AssetsApi(api_client)
try:
# List Assets
print("Listing Mux Assets:")
list_assets_response = assets_api.list_assets()
if list_assets_response.data:
for asset in list_assets_response.data:
print(f" Asset ID: {asset.id}, Status: {asset.status}, Duration: {asset.duration}")
else:
print(" No assets found.")
except ApiException as e:
print(f"Exception when calling AssetsApi->list_assets: {e}\n")
except Exception as e:
print(f"An unexpected error occurred: {e}")