Microsoft Azure Media Services Client Library for Python - A management library for Azure Media Services that provides programmatic access to media processing and streaming capabilities in the cloud.
npx @tessl/cli install tessl/pypi-azure-mgmt-media@10.2.0Microsoft Azure Media Services Client Library for Python - A comprehensive management library for Azure Media Services that provides programmatic access to media processing and streaming capabilities in Azure's cloud platform. This library enables developers to manage media assets, encoding transforms, live streaming events, streaming endpoints, content protection policies, and streaming locators.
Important: This package has been deprecated and will no longer be maintained after June 30, 2024. Azure Media Services is being retired. Please refer to the Azure Media Services retirement guide for migration details.
pip install azure-mgmt-media azure-identityfrom azure.mgmt.media import AzureMediaServices
from azure.identity import DefaultAzureCredentialimport os
from azure.identity import DefaultAzureCredential
from azure.mgmt.media import AzureMediaServices
# Set up authentication
credential = DefaultAzureCredential()
subscription_id = os.getenv("AZURE_SUBSCRIPTION_ID")
# Create the client
client = AzureMediaServices(
credential=credential,
subscription_id=subscription_id
)
# Example: List media services in a resource group
resource_group_name = "my-resource-group"
media_services = client.mediaservices.list(resource_group_name)
for service in media_services:
print(f"Media Service: {service.name}")
print(f"Location: {service.location}")
print(f"Resource Group: {service.resource_group}")The Azure Media Services Management library is built around a main client class that provides access to 19 specialized operation groups, each managing a specific aspect of media services:
This design follows Azure Resource Manager (ARM) patterns and provides both synchronous and asynchronous operation support with comprehensive error handling and long-running operation (LRO) management.
Manage Azure Media Services accounts including creation, configuration, storage key synchronization, and edge policies. Essential for setting up and maintaining the foundational media processing infrastructure.
def list(resource_group_name: str) -> Iterable[MediaService]:
"""List media services in resource group."""
def get(resource_group_name: str, account_name: str) -> MediaService:
"""Get specific media service account."""
def begin_create_or_update(resource_group_name: str, account_name: str, parameters: MediaService) -> LROPoller[MediaService]:
"""Create or update media service account."""
def delete(resource_group_name: str, account_name: str) -> None:
"""Delete media service account."""
def sync_storage_keys(resource_group_name: str, account_name: str, parameters: SyncStorageKeysInput) -> None:
"""Synchronize storage account keys."""Media Services Account Management
Manage media assets - the containers for audio and video files in Azure Storage. Includes asset creation, metadata management, container SAS URL generation, encryption key handling, and streaming locator associations.
def list(resource_group_name: str, account_name: str) -> Iterable[Asset]:
"""List all assets in media service account."""
def get(resource_group_name: str, account_name: str, asset_name: str) -> Asset:
"""Get specific asset."""
def create_or_update(resource_group_name: str, account_name: str, asset_name: str, parameters: Asset) -> Asset:
"""Create or update asset."""
def list_container_sas(resource_group_name: str, account_name: str, asset_name: str, parameters: ListContainerSasInput) -> AssetContainerSas:
"""Get asset container SAS URLs for upload/download."""
def get_encryption_key(resource_group_name: str, account_name: str, asset_name: str) -> StorageEncryptedAssetDecryptionData:
"""Get asset encryption key information."""Manage encoding transforms (job templates) and processing jobs for media transcoding, analysis, and content preparation. Includes custom and built-in encoding presets, job monitoring, and error handling.
def list(resource_group_name: str, account_name: str) -> Iterable[Transform]:
"""List encoding transforms."""
def create_or_update(resource_group_name: str, account_name: str, transform_name: str, parameters: Transform) -> Transform:
"""Create or update encoding transform."""
def create(resource_group_name: str, account_name: str, transform_name: str, job_name: str, parameters: Job) -> Job:
"""Create encoding job from transform."""
def cancel_job(resource_group_name: str, account_name: str, transform_name: str, job_name: str) -> None:
"""Cancel running encoding job."""Manage live streaming events and outputs for real-time content delivery. Includes live event lifecycle management, input configuration, preview settings, and output publishing with long-running operation support.
def begin_create(resource_group_name: str, account_name: str, live_event_name: str, parameters: LiveEvent) -> LROPoller[LiveEvent]:
"""Create live streaming event."""
def begin_start(resource_group_name: str, account_name: str, live_event_name: str) -> LROPoller[None]:
"""Start live streaming event."""
def begin_stop(resource_group_name: str, account_name: str, live_event_name: str, parameters: LiveEventActionInput) -> LROPoller[None]:
"""Stop live streaming event."""
def begin_create(resource_group_name: str, account_name: str, live_event_name: str, live_output_name: str, parameters: LiveOutput) -> LROPoller[LiveOutput]:
"""Create live output for archiving."""Manage streaming endpoints, locators, and policies for content delivery to end users. Includes streaming endpoint scaling, content publishing, path generation, and multi-protocol streaming support.
def begin_create(resource_group_name: str, account_name: str, streaming_endpoint_name: str, parameters: StreamingEndpoint) -> LROPoller[StreamingEndpoint]:
"""Create streaming endpoint."""
def begin_start(resource_group_name: str, account_name: str, streaming_endpoint_name: str) -> LROPoller[None]:
"""Start streaming endpoint."""
def create(resource_group_name: str, account_name: str, streaming_locator_name: str, parameters: StreamingLocator) -> StreamingLocator:
"""Create streaming locator for asset publishing."""
def list_paths(resource_group_name: str, account_name: str, streaming_locator_name: str) -> ListPathsResponse:
"""Get streaming URLs and paths."""Content Delivery and Streaming
Manage content protection through content key policies, encryption configurations, and DRM integration. Supports PlayReady, Widevine, FairPlay, and AES encryption with token-based access control.
def create_or_update(resource_group_name: str, account_name: str, content_key_policy_name: str, parameters: ContentKeyPolicy) -> ContentKeyPolicy:
"""Create or update content key policy."""
def get_policy_properties_with_secrets(resource_group_name: str, account_name: str, content_key_policy_name: str) -> ContentKeyPolicyProperties:
"""Get policy configuration with secrets."""
def list_content_keys(resource_group_name: str, account_name: str, streaming_locator_name: str) -> ListContentKeysResponse:
"""List content keys for streaming locator."""Manage account-level and asset-level filters for dynamic content filtering, including presentation time ranges, track filtering, and bitrate constraints for adaptive streaming scenarios.
def create_or_update(resource_group_name: str, account_name: str, filter_name: str, parameters: AccountFilter) -> AccountFilter:
"""Create or update account filter."""
def create_or_update(resource_group_name: str, account_name: str, asset_name: str, filter_name: str, parameters: AssetFilter) -> AssetFilter:
"""Create or update asset filter."""Manage individual tracks within assets, including audio, video, and text tracks. Supports track metadata, track data updates, and long-running track operations.
def begin_create_or_update(resource_group_name: str, account_name: str, asset_name: str, track_name: str, parameters: AssetTrack) -> LROPoller[AssetTrack]:
"""Create or update asset track."""
def begin_update_track_data(resource_group_name: str, account_name: str, asset_name: str, track_name: str) -> LROPoller[None]:
"""Update track data."""Monitor operation status and results for long-running operations, including media service operations, asset track operations, and streaming endpoint operations with comprehensive error reporting.
def list() -> OperationCollection:
"""List all available API operations."""
def get(location_name: str, operation_id: str) -> MediaServiceOperationStatus:
"""Get media service operation status."""
def get(location_name: str, operation_id: str) -> Optional[MediaService]:
"""Get media service operation result."""Manage private endpoints and private link resources for secure network connectivity to media services, enabling access through private networks without exposure to the public internet.
def create_or_update(resource_group_name: str, account_name: str, name: str, parameters: PrivateEndpointConnection) -> PrivateEndpointConnection:
"""Create or update private endpoint connection."""
def list(resource_group_name: str, account_name: str) -> PrivateLinkResourceListResult:
"""List available private link resources."""Manage Azure resource location validation and name availability checking for Media Services resources across Azure regions.
def check_name_availability(location_name: str, parameters: CheckNameAvailabilityInput) -> EntityNameAvailabilityCheckOutput:
"""Check if a Media Services account name is available in a specific Azure region."""class AzureMediaServices:
"""Main client for Azure Media Services management operations."""
def __init__(
self,
credential: TokenCredential,
subscription_id: str,
base_url: str = "https://management.azure.com",
**kwargs: Any
) -> None:
"""
Initialize Azure Media Services client.
Parameters:
- credential: Azure authentication credential (TokenCredential)
- subscription_id: Azure subscription identifier (str)
- base_url: Service URL, defaults to Azure Resource Manager (str)
- polling_interval: Default polling interval for LRO operations (int)
"""
def close(self) -> None:
"""Clean up client resources."""
def __enter__(self) -> "AzureMediaServices":
"""Context manager entry."""
def __exit__(self, *exc_details) -> None:
"""Context manager exit."""class MediaService:
"""Azure Media Services account resource."""
class Asset:
"""Media asset container for audio/video files."""
class Transform:
"""Encoding transform template."""
class Job:
"""Encoding or analysis job instance."""
class LiveEvent:
"""Live streaming event resource."""
class LiveOutput:
"""Live stream output configuration."""
class StreamingEndpoint:
"""Streaming endpoint for content delivery."""
class StreamingLocator:
"""Asset streaming configuration."""
class StreamingPolicy:
"""Streaming access policy."""
class ContentKeyPolicy:
"""Content protection policy."""
class AccountFilter:
"""Account-level media filter."""
class AssetFilter:
"""Asset-level media filter."""
class AssetTrack:
"""Individual track within an asset."""
class CheckNameAvailabilityInput:
"""Input for checking Media Services account name availability."""
class EntityNameAvailabilityCheckOutput:
"""Output containing name availability check results."""
class ListContainerSasInput:
"""Input parameters for generating asset container SAS URLs."""
class AssetContainerSas:
"""Response containing asset container SAS URLs for upload/download."""
class SyncStorageKeysInput:
"""Input parameters for synchronizing storage account keys."""
class LiveEventActionInput:
"""Input parameters for live event lifecycle actions."""
class ListPathsResponse:
"""Response containing streaming URLs and paths."""
class ListContentKeysResponse:
"""Response containing content keys for streaming locator."""
class ListStreamingLocatorsResponse:
"""Response containing streaming locators associated with an asset."""
class StorageEncryptedAssetDecryptionData:
"""Asset decryption information for storage-encrypted assets."""The library raises standard Azure exceptions for error conditions:
ResourceNotFoundError - Resource not found (404)ResourceExistsError - Resource already exists (409)ClientAuthenticationError - Authentication failure (401/403)HttpResponseError - General HTTP errors with detailed error informationAll long-running operations return LROPoller objects that can be used to monitor operation progress and handle failures gracefully.