Skip to main content

Microsoft Azure Communication Network Traversal Service Client Library for Python

Project description

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

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:

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:

# 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://<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 Identifier
identity_client = CommunicationIdentityClient(endpoint, DefaultAzureCredential())
relay_client = CommunicationRelayClient(endpoint, DefaultAzureCredential())

#You can also authenticate using your connection string

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

# 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

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

# 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

File details

Details for the file azure-communication-networktraversal-1.1.0b1.zip.

File metadata

  • Download URL: azure-communication-networktraversal-1.1.0b1.zip
  • Upload date:
  • Size: 61.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for azure-communication-networktraversal-1.1.0b1.zip
Algorithm Hash digest
SHA256 4594083f843941b5b9b9669a6f7877a60f3faeb3b6cbebfcba8a462637e99cc4
MD5 15a9b1b05dd69d8f12affeeebb48c993
BLAKE2b-256 a3f7f456bed66954a9ca37e9d644a60cb4ff5b7efd7c52524f80830d8a71617f

See more details on using hashes here.

File details

Details for the file azure_communication_networktraversal-1.1.0b1-py3-none-any.whl.

File metadata

  • Download URL: azure_communication_networktraversal-1.1.0b1-py3-none-any.whl
  • Upload date:
  • Size: 39.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for azure_communication_networktraversal-1.1.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 3462e058f0c45023fa2d208ef66ade00ab8abf33a9ae24b97ba7d6a8ed13c722
MD5 eab988519b6dc0b279c498e8b2fd1c8f
BLAKE2b-256 f35783875d44613a8296f858177e003eb571bffc74cfc15be72a839993ee7343

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page