Package: azure-communication-networktraversal
Azure Communication Network Traversal Package client library for PythonAzure Communication Network Traversal is managing TURN credentials for Azure Communication Services.It will provide TURN credentials to a user.Source code|API reference 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 startedPrerequisitesPython 3.6 or later is required to use this package.You must have anAzure subscriptionA deployed Communication Services resource. You can use theAzure Portalor theAzure PowerShellto set it up.Install the packageInstall the Azure Communication Identity client library for Python withpip:
Install the Azure Communication Relay Client library for Python withpip:pipinstallazure-communication-identity
pipinstallazure-communication-networktraversalKey conceptsExamplesInitializing Relay ClientThe following section provides code snippets covering some of the most common Azure Communication Network Traversal tasks, including:Getting the relay configuration# You can find your endpoint and access token from your resource in the Azure Portalimportosfromazure.communication.networktraversalimportCommunicationRelayClientfromazure.identityimportDefaultAzureCredentialfromazure.communication.identityimportCommunicationIdentityClientconnection_str="endpoint=ENDPOINT;accessKey=KEY"endpoint="https://<RESOURCE_NAME>.communication.azure.com"# To use Azure Active Directory Authentication (DefaultAzureCredential) make sure to have# AZURE_TENANT_ID, AZURE_CLIENT_ID and AZURE_CLIENT_SECRET as env variables.# We also need Identity client to get a User Identifieridentity_client=CommunicationIdentityClient(endpoint,DefaultAzureCredential())relay_client=CommunicationRelayClient(endpoint,DefaultAzureCredential())#You can also authenticate using your connection stringidentity_client=CommunicationIdentityClient.from_connection_string(self.connection_string)relay_client=CommunicationRelayClient.from_connection_string(self.connection_string)Getting the relay configuration providing a user# We need a user from Identityuser=identity_client.create_user()relay_configuration=relay_client.get_relay_configuration(user=user)foriceServerinconfig.ice_servers:asserticeServer.usernameisnotNoneprint('Username: '+iceServer.username)asserticeServer.credentialisnotNoneprint('Credential: '+iceServer.credential)asserticeServer.urlsisnotNoneforurliniceServer.urls:print('Url:'+url)Getting the relay configuration without providing a userrelay_configuration=relay_client.get_relay_configuration()foriceServerinconfig.ice_servers:asserticeServer.usernameisnotNoneprint('Username: '+iceServer.username)asserticeServer.credentialisnotNoneprint('Credential: '+iceServer.credential)asserticeServer.urlsisnotNoneforurliniceServer.urls:print('Url:'+url)Getting the relay configuration without providing a RouteType# We need a user from Identityuser=identity_client.create_user()relay_configuration=relay_client.get_relay_configuration(user=user,route_type=RouteType.NEAREST)foriceServerinconfig.ice_servers:asserticeServer.usernameisnotNoneprint('Username: '+iceServer.username)asserticeServer.credentialisnotNoneprint('Credential: '+iceServer.credential)asserticeServer.urlsisnotNoneforurliniceServer.urls:print('Url:'+url)TroubleshootingThe Azure Communication Relay client will raise exceptions defined inAzure Core.Next stepsMore sample codeProvide FeedbackIf you encounter any bugs or have suggestions, please file an issue in theIssuessection of the projectContributingThis 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.