title | description | author | ms.author | ms.date | ms.service | ms.custom | ms.topic |
---|---|---|---|---|---|---|---|
How to create a WebPubSubServiceClient with Python and Azure Identity |
How to create a WebPubSubServiceClient with Python and Azure Identity |
terencefan |
tefa |
11/15/2021 |
azure-web-pubsub |
devx-track-python |
how-to |
This how-to guide shows you how to create a WebPubSubServiceClient
using Microsoft Entra ID in Python.
-
Install azure-identity package from pypi.org.
python -m pip install azure-identity
-
Install azure-messaging-webpubsubservice package from pypi.org.
python -m pip install azure-messaging-webpubsubservice
-
Create a
TokenCredential
with Azure Identity SDK.from azure.identity import DefaultAzureCredential credential = DefaultAzureCredential()
credential
can be any class that inherits fromTokenCredential
class.- EnvironmentCredential
- ClientSecretCredential
- ClientCertificateCredential
- ManagedIdentityCredential
- VisualStudioCredential
- VisualStudioCodeCredential
- AzureCliCredential
To learn more, see Azure Identity client library for Python
-
Then create a
client
withendpoint
,hub
, andcredential
.from azure.identity import DefaultAzureCredential credential = DefaultAzureCredential() client = WebPubSubServiceClient(hub="<hub>", endpoint="<endpoint>", credential=credential)
Learn how to use this client, see Azure Web PubSub service client library for Python