{"id":5580,"library":"azure-mgmt-media","title":"Azure Media Services Management","description":"The azure-mgmt-media library is the Microsoft Azure Media Services Client Library for Python. It provides classes and methods for programmatically managing Azure Media Services resources, such as Media Services accounts, assets, transforms, and jobs. The current version is 10.2.1. Like other Azure SDKs, it follows a regular release cadence with updates aligning with Azure service API versions and general SDK improvements.","status":"active","version":"10.2.1","language":"en","source_language":"en","source_url":"https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/mediaservices/azure-mgmt-media","tags":["azure","management","media","sdk","cloud"],"install":[{"cmd":"pip install azure-mgmt-media","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core utilities for Azure SDK client libraries.","package":"azure-core","optional":false},{"reason":"Provides Azure Active Directory authentication support.","package":"azure-identity","optional":false}],"imports":[{"symbol":"MediaServicesClient","correct":"from azure.mgmt.media import MediaServicesClient"},{"symbol":"DefaultAzureCredential","correct":"from azure.identity import DefaultAzureCredential"}],"quickstart":{"code":"import os\nfrom azure.identity import DefaultAzureCredential\nfrom azure.mgmt.media import MediaServicesClient\n\n# Set your Azure subscription ID and resource group name in environment variables\n# AZURE_SUBSCRIPTION_ID, AZURE_RESOURCE_GROUP\n# Also ensure AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, AZURE_TENANT_ID are set for DefaultAzureCredential\n\nsubscription_id = os.environ.get('AZURE_SUBSCRIPTION_ID', 'YOUR_SUBSCRIPTION_ID')\nresource_group_name = os.environ.get('AZURE_RESOURCE_GROUP', 'YOUR_RESOURCE_GROUP_NAME')\nmedia_account_name = os.environ.get('AZURE_MEDIA_ACCOUNT_NAME', 'mytestmediaaccount')\nlocation = os.environ.get('AZURE_LOCATION', 'westus2') # Or your preferred Azure region\n\ndef main():\n    # Authenticate to Azure using DefaultAzureCredential\n    # This credential will attempt to authenticate via various mechanisms:\n    # environment variables, managed identity, VS Code, Azure CLI, etc.\n    credential = DefaultAzureCredential()\n    \n    # Create a Media Services client\n    media_client = MediaServicesClient(credential, subscription_id)\n    print(f\"Created MediaServicesClient for subscription: {subscription_id}\")\n\n    # Check if Media Services account exists\n    try:\n        account = media_client.mediaservices.get(resource_group_name, media_account_name)\n        print(f\"Media Services account '{media_account_name}' already exists.\")\n    except Exception as e:\n        print(f\"Media Services account '{media_account_name}' does not exist or error: {e}. Creating...\")\n\n        # Create a new Media Services account (requires a storage account to be linked)\n        # For a real scenario, you would first create a storage account and link it.\n        # This example assumes a default storage account is handled or will fail if not configured.\n        # In a real application, you'd define primary_storage_account: StorageAccount\n        # and related properties.\n        media_account_properties = {\n            \"location\": location,\n            \"storage_accounts\": [\n                {\n                    \"id\": f\"/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.Storage/storageAccounts/youruniquestorageaccountname\",\n                    \"type\": \"Primary\"\n                }\n            ]\n        }\n        \n        # NOTE: 'youruniquestorageaccountname' must be replaced with an actual, globally unique storage account name\n        # that exists in the same resource group and subscription.\n        print(f\"Creating Media Services account '{media_account_name}' in '{resource_group_name}'...\")\n        media_client.mediaservices.begin_create_or_update(\n            resource_group_name,\n            media_account_name,\n            media_account_properties\n        ).result()\n        print(f\"Media Services account '{media_account_name}' created successfully.\")\n\n    # List all Media Services accounts in the resource group\n    print(f\"Listing Media Services accounts in resource group '{resource_group_name}':\")\n    for media_account in media_client.mediaservices.list_by_resource_group(resource_group_name):\n        print(f\"- {media_account.name} (Location: {media_account.location})\")\n\nif __name__ == '__main__':\n    # Replace 'youruniquestorageaccountname' with an actual, globally unique storage account name\n    # that exists in your subscription and resource group.\n    # This quickstart is illustrative and requires a pre-existing storage account.\n    # For a fully runnable example, ensure the storage account is created first.\n    # os.environ['AZURE_STORAGE_ACCOUNT_ID'] = \"...\"\n    main()","lang":"python","description":"This quickstart demonstrates how to authenticate with Azure using `DefaultAzureCredential` and interact with Azure Media Services to list existing accounts or create a new one. It assumes you have Azure credentials configured (e.g., via environment variables, Azure CLI, or Visual Studio Code) and a resource group ready. Note that creating a Media Services account requires a linked storage account, which must be created separately and referenced by its full resource ID."},"warnings":[{"fix":"Verify IAM roles and permissions in the Azure portal for the identity used. Ensure `DefaultAzureCredential` can successfully authenticate and that environment variables (AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, AZURE_TENANT_ID for Service Principals) are correctly set.","message":"Azure Management SDKs, including `azure-mgmt-media`, require proper authentication and authorization. Common issues include insufficient permissions for the authenticated identity (e.g., Service Principal, Managed Identity) or incorrect Azure AD application configuration. Ensure your identity has 'Contributor' or 'Media Services Contributor' role on the relevant resource group or subscription.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Before creating a Media Services account, create a General-purpose v2 storage account in the same region and resource group. Provide its full resource ID in the `storage_accounts` property during Media Services account creation. E.g., `/subscriptions/{subId}/resourceGroups/{rgName}/providers/Microsoft.Storage/storageAccounts/{storageAccountName}`.","message":"When creating an Azure Media Services account, it *must* be linked to an existing Azure Storage account. If the specified storage account does not exist, is in a different region, or is not accessible by the identity creating the Media Services account, the creation will fail. Ensure the storage account name is globally unique and the full resource ID is correct.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Refer to the official Azure SDK for Python migration guides for `azure-mgmt-media` (if available) or the changelog for specific API changes. Update code to use new class names, parameter order, or object access patterns.","message":"The Azure SDKs for Python undergo significant changes between major versions, often aligning with new Azure REST API versions. While specific breaking changes from v9 to v10 for `azure-mgmt-media` might vary, general patterns include changes in class names, method signatures (e.g., parameters), and the structure of returned objects. Always consult the official migration guide for the specific service.","severity":"breaking","affected_versions":"Potentially v9.x to v10.x"}],"env_vars":null,"last_verified":"2026-04-08T00:00:00.000Z","next_check":"2026-07-07T00:00:00.000Z"}