.. role:: raw-html-m2r(raw)
:format: html
Azure Communication Network Traversal Package client library for Python
=======================================================================
Azure Communication Network Traversal is managing TURN credentials for Azure Communication Services.
It will provide TURN credentials to a user.
`Source code `_ | `API reference documentation `_
*Disclaimer*
----------------
*Azure SDK Python packages support for Python 2.7 has ended 01 January 2022. For more information and questions, please refer to https://github.com/Azure/azure-sdk-for-python/issues/20691*
Getting started
===============
Prerequisites
^^^^^^^^^^^^^
* Python 3.6 or later is required to use this package.
* You must have an `Azure subscription `_
* A deployed Communication Services resource. You can use the `Azure Portal `_ or the `Azure PowerShell `_ to set it up.
Install the package
^^^^^^^^^^^^^^^^^^^
Install the Azure Communication Identity client library for Python with `pip `_\ :
Install the Azure Communication Relay Client library for Python with `pip `_\ :
.. code-block:: bash
pip install azure-communication-identity
pip install azure-communication-networktraversal
Key concepts
============
Examples
--------
Initializing Relay Client
^^^^^^^^^^^^^^^^^^^^^^^^^
The following section provides code snippets covering some of the most common Azure Communication Network Traversal tasks, including:
* `Getting the relay configuration <#getting-the-relay-configuration>`_
.. code-block:: python
# You can find your endpoint and access token from your resource in the Azure Portal
import os
from azure.communication.networktraversal import CommunicationRelayClient
from azure.identity import DefaultAzureCredential
from azure.communication.identity import CommunicationIdentityClient
connection_str = "endpoint=ENDPOINT;accessKey=KEY"
endpoint = "https://.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 Identifier
identity_client = CommunicationIdentityClient(endpoint, DefaultAzureCredential())
relay_client = CommunicationRelayClient(endpoint, DefaultAzureCredential())
You can also authenticate using your connection string
======================================================
.. code-block:: python
identity_client = CommunicationIdentityClient.from_connection_string(self.connection_string)
relay_client = CommunicationRelayClient.from_connection_string(self.connection_string)
Getting the relay configuration providing a user
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: python
# We need a user from Identity
user = identity_client.create_user()
relay_configuration = relay_client.get_relay_configuration(user=user)
for iceServer in config.ice_servers:
assert iceServer.username is not None
print('Username: ' + iceServer.username)
assert iceServer.credential is not None
print('Credential: ' + iceServer.credential)
assert iceServer.urls is not None
for url in iceServer.urls:
print('Url:' + url)
Getting the relay configuration without providing a user
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: python
relay_configuration = relay_client.get_relay_configuration()
for iceServer in config.ice_servers:
assert iceServer.username is not None
print('Username: ' + iceServer.username)
assert iceServer.credential is not None
print('Credential: ' + iceServer.credential)
assert iceServer.urls is not None
for url in iceServer.urls:
print('Url:' + url)
Getting the relay configuration without providing a RouteType
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: python
# We need a user from Identity
user = identity_client.create_user()
relay_configuration = relay_client.get_relay_configuration(user=user, route_type=RouteType.NEAREST)
for iceServer in config.ice_servers:
assert iceServer.username is not None
print('Username: ' + iceServer.username)
assert iceServer.credential is not None
print('Credential: ' + iceServer.credential)
assert iceServer.urls is not None
for url in iceServer.urls:
print('Url:' + url)
Troubleshooting
===============
The Azure Communication Relay client will raise exceptions defined in `Azure Core `_.
Next steps
==========
More sample code
----------------
Provide Feedback
----------------
If you encounter any bugs or have suggestions, please file an issue in the `Issues `_ section of the project
Contributing
============
This 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, visit https://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 the `Microsoft Open Source Code of Conduct `_.
For more information see the `Code of Conduct FAQ `_ or contact `opencode@microsoft.com `_ with any additional questions or comments.
:raw-html-m2r:``
Indices and tables
------------------
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
.. toctree::
:maxdepth: 5
:glob:
:caption: Developer Documentation
azure.communication.networktraversal.rst