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.
83
Quality
Pending
Does it follow best practices?
Impact
83%
1.09xAverage score across 10 eval scenarios
Comprehensive management of media assets, the fundamental containers for audio and video content in Azure Media Services. Assets represent logical containers that reference media files stored in Azure Storage accounts, providing metadata management, access control, and integration with encoding and streaming workflows.
List and retrieve assets within media service accounts with comprehensive metadata.
def list(resource_group_name: str, account_name: str) -> Iterable[Asset]:
"""
List all assets in a media service account.
Parameters:
- resource_group_name: Name of the resource group (str)
- account_name: Name of the media service account (str)
Returns:
Iterable of Asset objects with metadata and properties
"""
def get(resource_group_name: str, account_name: str, asset_name: str) -> Asset:
"""
Get a specific asset with full details.
Parameters:
- resource_group_name: Name of the resource group (str)
- account_name: Name of the media service account (str)
- asset_name: Name of the asset (str)
Returns:
Asset object containing metadata and configuration
"""Create new assets and update existing asset configurations and metadata.
def create_or_update(
resource_group_name: str,
account_name: str,
asset_name: str,
parameters: Asset
) -> Asset:
"""
Create or update an asset.
Parameters:
- resource_group_name: Name of the resource group (str)
- account_name: Name of the media service account (str)
- asset_name: Name of the asset (str)
- parameters: Asset configuration and metadata (Asset)
Returns:
Created or updated Asset object
"""
def update(
resource_group_name: str,
account_name: str,
asset_name: str,
parameters: Asset
) -> Asset:
"""
Update an existing asset's metadata.
Parameters:
- resource_group_name: Name of the resource group (str)
- account_name: Name of the media service account (str)
- asset_name: Name of the asset (str)
- parameters: Updated asset configuration (Asset)
Returns:
Updated Asset object
"""Remove assets and optionally delete associated storage content.
def delete(resource_group_name: str, account_name: str, asset_name: str) -> None:
"""
Delete an asset.
Parameters:
- resource_group_name: Name of the resource group (str)
- account_name: Name of the media service account (str)
- asset_name: Name of the asset (str)
Returns:
None
Note:
This operation deletes the asset metadata but not the underlying storage files.
"""Generate SAS URLs for direct storage access to upload or download media files.
def list_container_sas(
resource_group_name: str,
account_name: str,
asset_name: str,
parameters: ListContainerSasInput
) -> AssetContainerSas:
"""
Generate SAS URLs for asset container access.
Parameters:
- resource_group_name: Name of the resource group (str)
- account_name: Name of the media service account (str)
- asset_name: Name of the asset (str)
- parameters: SAS generation parameters (ListContainerSasInput)
Returns:
AssetContainerSas containing SAS URLs and container information
"""Retrieve decryption keys for storage-encrypted assets.
def get_encryption_key(
resource_group_name: str,
account_name: str,
asset_name: str
) -> StorageEncryptedAssetDecryptionData:
"""
Get encryption key information for a storage-encrypted asset.
Parameters:
- resource_group_name: Name of the resource group (str)
- account_name: Name of the media service account (str)
- asset_name: Name of the asset (str)
Returns:
StorageEncryptedAssetDecryptionData containing decryption information
"""List streaming locators associated with an asset for content publishing.
def list_streaming_locators(
resource_group_name: str,
account_name: str,
asset_name: str
) -> ListStreamingLocatorsResponse:
"""
List streaming locators associated with an asset.
Parameters:
- resource_group_name: Name of the resource group (str)
- account_name: Name of the media service account (str)
- asset_name: Name of the asset (str)
Returns:
ListStreamingLocatorsResponse containing associated streaming locators
"""class Asset:
"""Media asset container for audio/video files."""
name: str
description: str
asset_id: str
created: str
last_modified: str
alternate_id: str
storage_account_name: str
container: str
storage_encryption_format: str # AssetStorageEncryptionFormat enum
class ListContainerSasInput:
"""Parameters for generating asset container SAS URLs."""
permissions: str # AssetContainerPermission enum (Read, ReadWrite, ReadWriteDelete)
expiry_time: str # ISO 8601 datetime
class AssetContainerSas:
"""Asset container SAS information."""
asset_container_sas_urls: List[str]
class StorageEncryptedAssetDecryptionData:
"""Asset decryption information for storage-encrypted assets."""
key: bytes
initialization_vector: bytes
class ListStreamingLocatorsResponse:
"""Response containing streaming locators for an asset."""
streaming_locators: List[AssetStreamingLocator]
class AssetStreamingLocator:
"""Streaming locator associated with an asset."""
name: str
asset_name: str
created: str
start_time: str
end_time: str
streaming_locator_id: str
streaming_policy_name: str
default_content_key_policy_name: strfrom azure.mgmt.media import AzureMediaServices
from azure.mgmt.media.models import Asset, ListContainerSasInput, AssetContainerPermission
from azure.identity import DefaultAzureCredential
from azure.storage.blob import BlobServiceClient
import os
client = AzureMediaServices(
credential=DefaultAzureCredential(),
subscription_id="your-subscription-id"
)
# Create a new asset
asset = Asset(
description="Sample video asset for encoding"
)
created_asset = client.assets.create_or_update(
resource_group_name="my-resource-group",
account_name="my-media-service",
asset_name="sample-video-asset",
parameters=asset
)
print(f"Asset created: {created_asset.name}")
print(f"Container: {created_asset.container}")
# Get SAS URL for upload
sas_input = ListContainerSasInput(
permissions=AssetContainerPermission.READ_WRITE,
expiry_time="2024-12-31T23:59:59Z"
)
sas_response = client.assets.list_container_sas(
resource_group_name="my-resource-group",
account_name="my-media-service",
asset_name="sample-video-asset",
parameters=sas_input
)
# Use SAS URL to upload files
sas_url = sas_response.asset_container_sas_urls[0]
blob_client = BlobServiceClient(account_url=sas_url)
# Upload a file
with open("sample-video.mp4", "rb") as data:
blob_client.get_blob_client(blob="sample-video.mp4").upload_blob(data)
print("File uploaded to asset container")# List all assets
assets = client.assets.list(
resource_group_name="my-resource-group",
account_name="my-media-service"
)
for asset in assets:
print(f"Asset: {asset.name}")
print(f"Created: {asset.created}")
print(f"Storage Account: {asset.storage_account_name}")
# Check streaming locators
locators_response = client.assets.list_streaming_locators(
resource_group_name="my-resource-group",
account_name="my-media-service",
asset_name=asset.name
)
if locators_response.streaming_locators:
print(f" Streaming Locators:")
for locator in locators_response.streaming_locators:
print(f" - {locator.name} (Policy: {locator.streaming_policy_name})")
else:
print(" No streaming locators associated")
print()# Get asset details
asset = client.assets.get(
resource_group_name="my-resource-group",
account_name="my-media-service",
asset_name="sample-video-asset"
)
print(f"Original description: {asset.description}")
# Update asset metadata
asset.description = "Updated sample video asset with new metadata"
asset.alternate_id = "external-id-12345"
updated_asset = client.assets.update(
resource_group_name="my-resource-group",
account_name="my-media-service",
asset_name="sample-video-asset",
parameters=asset
)
print(f"Updated description: {updated_asset.description}")
print(f"Alternate ID: {updated_asset.alternate_id}")Install with Tessl CLI
npx tessl i tessl/pypi-azure-mgmt-mediadocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10