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.
PrerequisitesPATH
environment variableTo 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
Connect to the Python client
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.
Get help and supportYou can contact Media Services with questions or follow our updates by one of the following methods:
azure-media-services
.RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4