Ask Learn
Preview
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Warning
Azure Media Services will be retired June 30th, 2024. For more information, see the AMS Retirement Guide.
This article shows you how to connect to the Azure Media Services v3 Python SDK using the service principal sign in method.
PATH
environment variableImportant
Review naming conventions.
To work with Azure Media Services using Python, you need to install these modules.
The azure-identity
module, which includes Azure modules for Active Directory.
The azure-mgmt-media
module, which includes the Media Services entities.
Make sure to get the latest version of the Media Services SDK for Python.
Open a command-line tool and use the following commands to install the modules.
pip3 install azure-identity
pip3 install azure-mgmt-media
Create a file with a .py
extension
Open the file in your favorite editor
Add the the following code to the file. The code imports the required modules and creates the Active Directory credentials object you need to connect to Media Services.
Set the variables' values to the values you got from Access APIs. Update the ACCOUNT_NAME
and RESOURCE_GROUP_NAME
variables to the Media Services account name and Resource Group names used when creating those resources.
from azure.identity import ClientSecretCredential
from azure.mgmt.media import AzureMediaServices
# Tenant ID for your Azure Subscription
TENANT_ID = "(update-this-value)"
# Your Application Client ID of your Service Principal
CLIENT_ID = "(update-this-value)"
# Your Service Principal secret key
CLIENT_SECRET = "(update-this-value)"
# Your Azure Subscription ID
SUBSCRIPTION_ID = "(update-this-value)"
# Your Resource Group name
RESOURCE_GROUP_NAME = "(update-this-value)"
# Your Azure Media Service account name
ACCOUNT_NAME = "(update-this-value)"
credentials = ClientSecretCredential(TENANT_ID, CLIENT_ID, CLIENT_SECRET)
# The Azure Media Services Client
client = AzureMediaServices(credentials, SUBSCRIPTION_ID)
# Now that you are authenticated, you can manipulate the entities.
# For example, list assets in your Media Services account
assets = client.assets.list(RESOURCE_GROUP_NAME, ACCOUNT_NAME)
for i, r in enumerate(assets):
print(r)
Run the file
Additional samples are available in GitHub in the Azure Media Services v3 Python Samples repo.
You can contact Media Services with questions or follow our updates by one of the following methods:
azure-media-services
.Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign in