Package: azure-mixedreality-remoterendering
Azure Remote Rendering client library for PythonAzure Remote Rendering (ARR) is a service that enables you to render high-quality, interactive 3D content in the cloud and stream it in real time to devices, such as the HoloLens 2.This SDK offers functionality to convert assets to the format expected by the runtime, and also to manage
the lifetime of remote rendering sessions.This SDK supports version "2021-01-01" of theRemote Rendering REST API.NOTE: Once a session is running, a client application will connect to it using one of the "runtime SDKs".
These SDKs are designed to best support the needs of an interactive application doing 3d rendering.
They are available in (.netor (C++).Product documentationDisclaimerAzure SDK Python packages support for Python 2.7 has ended 01 January 2022. For more information and questions, please refer tohttps://github.com/Azure/azure-sdk-for-python/issues/20691Getting startedPrerequisitesYou will need anAzure subscriptionand anAzure Remote Rendering accountto use this package.In order to follow this tutorial it is highly recommended that youlink your storage account with your ARR account.Install the packageInstall the Azure Remote Rendering client library for Python withpip:pipinstall--preazure-mixedreality-remoterenderingCreate and authenticate the clientConstructing a remote rendering client requires an authenticated account, and a remote rendering endpoint.
For an account created in the eastus region, the account domain will have the form "eastus.mixedreality.azure.com".
There are several different forms of authentication:Account Key authenticationAccount keys enable you to get started quickly with using Azure Remote Rendering. But before you deploy your application to production, we recommend that you update your app to use Azure AD authentication.Azure Active Directory (AD) token authenticationIf you're building an enterprise application and your company is using Azure AD as its identity system, you can use user-based Azure AD authentication in your app. You then grant access to your Azure Remote Rendering accounts by using your existing Azure AD security groups. You can also grant access directly to users in your organization.Otherwise, we recommend that you obtain Azure AD tokens from a web service that supports your app. We recommend this method for production applications because it allows you to avoid embedding the credentials for access in your client application.Seeherefor detailed instructions and information.In all the following examples, the client is constructed with aendpointparameter.
The available endpoints correspond to regions, and the choice of endpoint determines the region in which the service performs its work.
An example ishttps://remoterendering.eastus2.mixedreality.azure.com.A full list of endpoints in supported regions can be found in theAzure Remote Rendering region list.NOTE: For converting assets, it is preferable to pick a region close to the storage containing the assets.NOTE: For rendering, it is strongly recommended that you pick the closest region to the devices using the service.
The time taken to communicate with the server impacts the quality of the experience.Authenticating with account key authenticationUse theAzureKeyCredentialobject to use an account identifier and account key to authenticate:fromazure.core.credentialsimportAzureKeyCredentialfromazure.mixedreality.remoterenderingimportRemoteRenderingClientaccount_id="<ACCOUNT_ID>"account_domain="<ACCOUNT_DOMAIN>"account_key="<ACCOUNT_KEY>"arr_endpoint="<ARR_ENDPOINT>"key_credential=AzureKeyCredential(account_key)client=RemoteRenderingClient(endpoint=arr_endpoint,account_id=account_id,account_domain=account_domain,credential=key_credential)Authenticating with a static access tokenYou can pass a Mixed Reality access token as anAccessTokenpreviously retrieved from theMixed Reality STS serviceto be used with a Mixed Reality client library:fromazure.mixedreality.authenticationimportMixedRealityStsClientfromazure.mixedreality.remoterenderingimportRemoteRenderingClientaccount_id="<ACCOUNT_ID>"account_domain="<ACCOUNT_DOMAIN>"account_key="<ACCOUNT_KEY>"key_credential=AzureKeyCredential(account_key)client=MixedRealityStsClient(account_id,account_domain,key_credential)token=client.get_token()client=RemoteRenderingClient(endpoint=arr_endpoint,account_id=account_id,account_domain=account_domain,credential=token,)Authenticating with an Azure Active Directory CredentialAccount key authentication is used in most of the examples, but you can also authenticate with Azure Active Directory
using theAzure Identity library. This is the recommended method for production applications. To use
the [DefaultAzureCredential][defaultazurecredential] provider shown below, or other credential providers provided with
the Azure SDK, please install the@azure/identitypackage:You will also need to [register a new AAD application][register_aad_app] and grant access to your Mixed Reality resource
by assigning the appropriate role for your Mixed Reality service to your service principal.fromazure.identityimportDefaultAzureCredentialfromazure.mixedreality.remoterenderingimportRemoteRenderingClientaccount_id="<ACCOUNT_ID>"account_domain="<ACCOUNT_DOMAIN>"default_credential=DefaultAzureCredential()client=RemoteRenderingClient(endpoint=arr_endpoint,account_id=account_id,account_domain=account_domain,credential=default_credential)Key conceptsRemoteRenderingClientTheRemoteRenderingClientis the client library used to access the RemoteRenderingService.
It provides methods to create and manage asset conversions and rendering sessions.Long-Running OperationsLong-running operations are operations which consist of an initial request sent to the service to start an operation,
followed by polling the service at intervals to determine whether the operation has completed or failed, and if it has
succeeded, to get the result.Methods that convert assets, or spin up rendering sessions are modelled as long-running operations.
The client exposes abegin_<method-name>method that returns an LROPoller or AsyncLROPoller.
Callers should wait for the operation to complete by calling result() on the poller object returned from thebegin_<method-name>method. Sample code snippets are provided to illustrate using long-running operationsbelow.ExamplesConvert an assetList conversionsCreate a sessionExtend the lease time of a sessionList sessionsStop a sessionConvert an assetWe assume that a RemoteRenderingClient has been constructed as described in theAuthenticate the Clientsection.
The following snippet describes how to request that "box.fbx", found at at a path of "/input/box/box.fbx" of the blob container at the given storage container URI, gets converted.Converting an asset can take anywhere from seconds to hours.
This code uses an existing conversion poller and polls regularly until the conversion has finished or failed.
The default polling period is 5 seconds.
Note that a conversion poller can be retrieved using the client.get_asset_conversion_poller using the id of an existing conversion and a client.Once the conversion process finishes the output is written to the specified output container under a path of "/output/<conversion_id>/box.arrAsset".
The path can be retrieved from the output.asset_uri of a successful conversion.conversion_id=str(uuid.uuid4())# A randomly generated uuid is a good choice for a conversion_id.input_settings=AssetConversionInputSettings(storage_container_uri="<STORAGE CONTAINER URI>",relative_input_asset_path="box.fbx",blob_prefix="input/box")output_settings=AssetConversionOutputSettings(storage_container_uri="<STORAGE CONTAINER URI>",blob_prefix="output/"+conversion_id,output_asset_filename="convertedBox.arrAsset"#if no output_asset_filename <input asset filename>.arrAsset will be the name of the resulting converted asset)try:conversion_poller=client.begin_asset_conversion(conversion_id=conversion_id,input_settings=input_settings,output_settings=output_settings)print("Conversion with id:",conversion_id,"created. Waiting for completion.")conversion=conversion_poller.result()print("conversion output:",conversion.output.asset_uri)exceptExceptionase:print("Conversion failed",e)List conversionsYou can get information about your conversions using thelist_asset_conversionsmethod.
This method may return conversions which have yet to start, conversions which are running and conversions which have finished.
In this example, we list all conversions and print id and creation ad as well as the output asset URIs of successful conversions.print("conversions:")forcinclient.list_asset_conversions():print("\tconversion:  id:",c.id,"status:",c.status,"created on:",c.created_on.strftime("%m/%d/%Y, %H:%M:%S"),)ifc.status==AssetConversionStatus.SUCCEEDED:print("\t\tconversion result URI:",c.output.asset_uri)Create a sessionWe assume that a RemoteRenderingClient has been constructed as described in theAuthenticate the Clientsection.
The following snippet describes how to request that a new rendering session be started.print("starting rendering session with id:",session_id)try:session_poller=client.begin_rendering_session(session_id=session_id,size=RenderingSessionSize.STANDARD,lease_time_minutes=20)print("rendering session with id:",session_id,"created. Waiting for session to be ready.",)session=session_poller.result()print("session with id:",session.id,"is ready. lease_time_minutes:",session.lease_time_minutes,)exceptExceptionase:print("Session startup failed",e)Extend the lease time of a sessionIf a session is approaching its maximum lease time, but you want to keep it alive, you will need to make a call to
increase its maximum lease time.
This example shows how to query the current properties and then extend the lease if it will expire soon.NOTE: The runtime SDKs also offer this functionality, and in many typical scenarios, you would use them to
extend the session lease.session=client.get_rendering_session(session_id)ifsession.lease_time_minutes-session.elapsed_time_minutes<2:session=client.update_rendering_session(session_id=session_id,lease_time_minutes=session.lease_time_minutes+10)List sessionsYou can get information about your sessions using thelist_rendering_sessionsmethod of the client.
This method may return sessions which have yet to start and sessions which are ready.print("sessions:")rendering_sessions=client.list_rendering_sessions()forsessioninrendering_sessions:print("\tsession:  id:",session.id,"status:",session.status,"created on:",session.created_on.strftime("%m/%d/%Y, %H:%M:%S"),)Stop a SessionThe following code will stop a running session with given id. Since running sessions incur ongoing costs it is
recommended to stop sessions which are not needed anymore.client.stop_rendering_session(session_id)print("session with id:",session_id,"stopped")TroubleshootingFor general troubleshooting advice concerning Azure Remote Rendering, seethe Troubleshoot pagefor remote rendering at docs.microsoft.com.The client methods and waiting for poller results will throw exceptions if the request failed.If the asset in a conversion is invalid, the conversion poller will throw an exception with an error containing details.
Once the conversion service is able to process the file, a <assetName>.result.json file will be written to the output container.
If the input asset is invalid, then that file will contain a more detailed description of the problem.Similarly, sometimes when a session is requested, the session ends up in an error state.
The poller will throw an exception containing details of the error in this case. Session errors are usually transient
and requesting a new session should succeed.LoggingThis library uses the standard
[logging][python_logging] library for logging.Basic information about HTTP sessions (URLs, headers, etc.) is logged atINFOlevel.DetailedDEBUGlevel logging, including request/response bodies andunredactedheaders, can be enabled on the client or per-operation with thelogging_enablekeyword argument.See full SDK logging documentation with exampleshere.Optional ConfigurationOptional keyword arguments can be passed in at the client and per-operation level.
The azure-corereference documentationdescribes available configurations for retries, logging, transport protocols, and more.ExceptionsThe Remote Rendering client library will raise exceptions defined inAzure Core.Async APIsThis library also includes a complete async API supported on Python 3.7+. To use it, you must
first install an async transport, such asaiohttp. Async clients
are found under theazure.mixedreality.remoterendering.aionamespace.Next stepsRead theProduct documentationLearn about the runtime SDKs:.NET:https://docs.microsoft.com/dotnet/api/microsoft.azure.remoterenderingC++:https://docs.microsoft.com/cpp/api/remote-rendering/ContributingThis project welcomes contributions and suggestions. Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visithttps://cla.microsoft.com.When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.This project has adopted theMicrosoft Open Source Code of Conduct.
For more information see theCode of Conduct FAQor
contactopencode@microsoft.comwith any additional questions or comments.If you'd like to contribute to this library, please read thecontributing guideto learn more about how
to build and test the code.Release History1.0.0b2 (2023-07-03)Other ChangesAdded case-insensitive support for enums.Python 2.7 is no longer supported. Please use Python version 3.7 or later.1.0.0b1 (2021-11-15)Initial release.