CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-azure-mgmt-media

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

1.09x

Quality

Pending

Does it follow best practices?

Impact

83%

1.09x

Average score across 10 eval scenarios

Overview
Eval results
Files

asset-management.mddocs/

Asset Management

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.

Capabilities

Asset Listing and Retrieval

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

Asset Creation and Updates

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

Asset Deletion

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.
    """

Storage Container Access

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

Encryption Key Management

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

Streaming Locator Association

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

Data Types

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: str

Usage Examples

Create and Upload to Asset

from 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 Assets and Associated Streaming Locators

# 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()

Manage Asset Metadata

# 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-media

docs

asset-management.md

asset-tracks.md

content-delivery-streaming.md

content-protection.md

encoding-transforms.md

index.md

live-streaming.md

location-management.md

media-filters.md

media-services-management.md

network-security.md

operations-monitoring.md

tile.json