Mux Python SDK

5.1.2 · active · verified Mon Apr 13

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

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the Mux Python client using API credentials from environment variables and then list all existing video assets in your Mux account. Mux API responses typically return the primary data object within a `.data` attribute.

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}")

view raw JSON →