Skip to content

Commit 00f3e57

Browse files
committed
Update docs metadata
1 parent 6cf9e2a commit 00f3e57

File tree

2 files changed

+92
-99
lines changed

2 files changed

+92
-99
lines changed
Lines changed: 90 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,145 +1,136 @@
11
---
2-
title: Azure WebPubSubService client library for Python
2+
title: Azure Web PubSub service client library for Python
33
keywords: Azure, python, SDK, API, azure-messaging-webpubsubservice, webpubsub
4-
author: ramya-rao-a
5-
ms.author: ramyar
6-
ms.date: 10/15/2021
4+
author: msyyc
5+
ms.author: yuchaoyan
6+
ms.date: 12/12/2022
77
ms.topic: reference
8-
ms.prod: azure
9-
ms.technology: azure
108
ms.devlang: python
119
ms.service: webpubsub
1210
---
11+
# Azure Web PubSub service client library for Python - version 1.1.0b1
1312

14-
# Azure WebPubSubService client library for Python - version 1.0.0b2
1513

14+
[Azure Web PubSub Service](https://aka.ms/awps/doc) is an Azure-managed service that helps developers easily build web applications with real-time features and publish-subscribe pattern. Any scenario that requires real-time publish-subscribe messaging between server and clients or among clients can use Azure Web PubSub service. Traditional real-time features that often require polling from server or submitting HTTP requests can also use Azure Web PubSub service.
1615

17-
[Azure Web PubSub Service](https://aka.ms/awps/doc) is a service that enables you to build real-time messaging web applications using WebSockets and the publish-subscribe pattern. Any platform supporting WebSocket APIs can connect to the service easily, e.g. web pages, mobile applications, edge devices, etc. The service manages the WebSocket connections for you and allows up to 100K concurrent connections. It provides powerful APIs for you to manage these clients and deliver real-time messages.
16+
You can use this library in your app server side to manage the WebSocket client connections, as shown in below diagram:
1817

19-
Any scenario that requires real-time publish-subscribe messaging between server and clients or among clients, can use Azure Web PubSub service. Traditional real-time features that often require polling from server or submitting HTTP requests, can also use Azure Web PubSub service.
20-
21-
We list some examples that are good to use Azure Web PubSub service:
22-
23-
- **High frequency data updates:** gaming, voting, polling, auction.
24-
- **Live dashboards and monitoring:** company dashboard, financial market data, instant sales update, multi-player game leader board, and IoT monitoring.
25-
- **Cross-platform live chat:** live chat room, chat bot, on-line customer support, real-time shopping assistant, messenger, in-game chat, and so on.
26-
- **Real-time location on map:** logistic tracking, delivery status tracking, transportation status updates, GPS apps.
27-
- **Real-time targeted ads:** personalized real-time push ads and offers, interactive ads.
28-
- **Collaborative apps:** coauthoring, whiteboard apps and team meeting software.
29-
- **Push instant notifications:** social network, email, game, travel alert.
30-
- **Real-time broadcasting:** live audio/video broadcasting, live captioning, translating, events/news broadcasting.
31-
- **IoT and connected devices:** real-time IoT metrics, remote control, real-time status, and location tracking.
32-
- **Automation:** real-time trigger from upstream events.
33-
34-
Use the client library to:
18+
![overflow](https://user-images.githubusercontent.com/668244/140014067-25a00959-04dc-47e8-ac25-6957bd0a71ce.png)
3519

20+
Use this library to:
3621
- Send messages to hubs and groups.
3722
- Send messages to particular users and connections.
3823
- Organize users and connections into groups.
3924
- Close connections
40-
- Grant/revoke/check permissions for an existing connection
25+
- Grant, revoke, and check permissions for an existing connection
4126

42-
[Source code](https://github.com/Azure/azure-sdk-for-python/blob/azure-messaging-webpubsubservice_1.0.0b2/sdk/webpubsub/azure-messaging-webpubsubservice) | [Package (Pypi)][package] | [API reference documentation](https://github.com/Azure/azure-sdk-for-python/blob/azure-messaging-webpubsubservice_1.0.0b2/sdk/webpubsub/azure-messaging-webpubsubservice) | [Product documentation][webpubsubservice_docs]
27+
[Source code](https://github.com/Azure/azure-sdk-for-python/blob/azure-messaging-webpubsubservice_1.1.0b1/sdk/webpubsub/azure-messaging-webpubsubservice) | [Package (Pypi)][package] | [API reference documentation](https://aka.ms/awps/sdk/python) | [Product documentation][webpubsubservice_docs]
4328

44-
## Getting started
29+
## _Disclaimer_
4530

46-
### Installating the package
31+
_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_
4732

48-
```bash
49-
python -m pip install azure-messaging-webpubsubservice
50-
```
33+
## Getting started
5134

52-
#### Prequisites
35+
### Prerequisites
5336

54-
- Python 2.7, or 3.6 or later is required to use this package.
37+
- Python 3.6 or later is required to use this package.
5538
- You need an [Azure subscription][azure_sub], and a [Azure WebPubSub service instance][webpubsubservice_docs] to use this package.
5639
- An existing Azure Web PubSub service instance.
5740

58-
### Authenticating the client
41+
### 1. Install the package
42+
43+
```bash
44+
python -m pip install azure-messaging-webpubsubservice
45+
```
5946

60-
#### 1. Create the client from the service connection string
47+
### 2. Create and authenticate a WebPubSubServiceClient
6148

62-
You can get the [API key][api_key] or [Connection string][connection_string] in the [Azure Portal][azure_portal].
63-
Once you have the value for the API key, you can pass it as a string into an instance of [AzureKeyCredential][azure-key-credential].
64-
Use the key as the credential parameter to authenticate the client:
49+
You can authenticate the `WebPubSubServiceClient` using [connection string][connection_string]:
6550

6651
```python
6752
>>> from azure.messaging.webpubsubservice import WebPubSubServiceClient
68-
>>> from azure.core.credentials import AzureKeyCredential
6953

70-
>>> client = WebPubSubServiceClient(endpoint='<endpoint>', credential=AzureKeyCredential("<api_key>"))
54+
>>> service = WebPubSubServiceClient.from_connection_string(connection_string='<connection_string>', hub='hub')
7155
```
7256

73-
Once you have the value for the connection string, you can pass it as a string into the function `from_connection_string` and it will
74-
authenticate the client:
57+
Or using the service endpoint and the access key:
58+
7559
```python
7660
>>> from azure.messaging.webpubsubservice import WebPubSubServiceClient
61+
>>> from azure.core.credentials import AzureKeyCredential
7762

78-
>>> client = WebPubSubServiceClient.from_connection_string(connection_string='<connection_string>')
63+
>>> service = WebPubSubServiceClient(endpoint='<endpoint>', hub='hub', credential=AzureKeyCredential("<access_key>"))
7964
```
8065

81-
#### 2. Create with an Azure Active Directory Credential
82-
To use an [Azure Active Directory (AAD) token credential][authenticate_with_token],
83-
provide an instance of the desired credential type obtained from the
84-
[azure-identity][azure_identity_credentials] library.
66+
Or using [Azure Active Directory][aad_doc]:
67+
1. [pip][pip] install [`azure-identity`][azure_identity_pip]
68+
2. Follow the document to [enable AAD authentication on your Webpubsub resource][aad_doc]
69+
3. Update code to use [DefaultAzureCredential][default_azure_credential]
8570

86-
To authenticate with AAD, you must first [pip][pip] install [`azure-identity`][azure_identity_pip] and
87-
[enable AAD authentication on your Webpubsub resource][enable_aad]
71+
```python
72+
>>> from azure.messaging.webpubsubservice import WebPubSubServiceClient
73+
>>> from azure.identity import DefaultAzureCredential
74+
>>> service = WebPubSubServiceClient(endpoint='<endpoint>', hub='hub', credential=DefaultAzureCredential())
75+
```
8876

89-
After setup, you can choose which type of [credential][azure_identity_credentials] from azure.identity to use.
90-
As an example, [DefaultAzureCredential][default_azure_credential]
91-
can be used to authenticate the client:
77+
## Key concepts
9278

93-
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables:
94-
AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET
79+
### Connection
9580

96-
Use the returned token credential to authenticate the client:
81+
A connection, also known as a client or a client connection, represents an individual WebSocket connection connected to the Web PubSub service. When successfully connected, a unique connection ID is assigned to this connection by the Web PubSub service.
9782

98-
```python
99-
>>> from azure.messaging.webpubsubservice import WebPubSubServiceClient
100-
>>> from azure.identity import DefaultAzureCredential
101-
>>> client = WebPubSubServiceClient(endpoint='<endpoint>', credential=DefaultAzureCredential())
102-
```
83+
### Hub
10384

104-
## Examples
85+
A hub is a logical concept for a set of client connections. Usually you use one hub for one purpose, for example, a chat hub, or a notification hub. When a client connection is created, it connects to a hub, and during its lifetime, it belongs to that hub. Different applications can share one Azure Web PubSub service by using different hub names.
10586

106-
### Broadcast messages
87+
### Group
10788

108-
```python
109-
>>> from azure.messaging.webpubsubservice import WebPubSubServiceClient
110-
>>> from azure.identity import DefaultAzureCredential
111-
>>> from azure.core.exceptions import HttpResponseError
89+
A group is a subset of connections to the hub. You can add a client connection to a group, or remove the client connection from the group, anytime you want. For example, when a client joins a chat room, or when a client leaves the chat room, this chat room can be considered to be a group. A client can join multiple groups, and a group can contain multiple clients.
11290

113-
>>> client = WebPubSubServiceClient(endpoint='<endpoint>', credential=DefaultAzureCredential())
114-
>>> with open('file.json', 'r') as f:
115-
try:
116-
client.send_to_all('ahub', content=f, content_type='application/json')
117-
except HttpResponseError as e:
118-
print('service responds error: {}'.format(e.response.json()))
91+
### User
11992

120-
```
93+
Connections to Web PubSub can belong to one user. A user might have multiple connections, for example when a single user is connected across multiple devices or multiple browser tabs.
12194

122-
## Key concepts
95+
### Message
12396

124-
### Connection
97+
When the client is connected, it can send messages to the upstream application, or receive messages from the upstream application, through the WebSocket connection.
12598

126-
Connections, represented by a connection id, represent an individual websocket connection to the Web PubSub service. Connection id is always unique.
99+
## Examples
127100

128-
### Hub
101+
### Broadcast messages in JSON format
129102

130-
Hub is a logical concept for a set of connections. Connections are always connected to a specific hub. Messages that are broadcast to the hub are dispatched to all connections to that hub. Hub can be used for different applications, different applications can share one Azure Web PubSub service by using different hub names.
103+
```python
104+
>>> from azure.messaging.webpubsubservice import WebPubSubServiceClient
131105

132-
### Group
106+
>>> service = WebPubSubServiceClient.from_connection_string('<connection_string>', hub='hub1')
107+
>>> service.send_to_all(message = {
108+
'from': 'user1',
109+
'data': 'Hello world'
110+
})
111+
```
133112

134-
Group allow broadcast messages to a subset of connections to the hub. You can add and remove users and connections as needed. A client can join multiple groups, and a group can contain multiple clients.
113+
The WebSocket client will receive JSON serialized text: `{"from": "user1", "data": "Hello world"}`.
135114

136-
### User
115+
### Broadcast messages in plain-text format
137116

138-
Connections to Web PubSub can belong to one user. A user might have multiple connections, for example when a single user is connected across multiple devices or multiple browser tabs.
117+
```python
118+
>>> from azure.messaging.webpubsubservice import WebPubSubServiceClient
119+
>>> service = WebPubSubServiceClient.from_connection_string('<connection_string>', hub='hub1')
120+
>>> service.send_to_all(message = 'Hello world', content_type='text/plain')
121+
```
139122

140-
### Message
123+
The WebSocket client will receive text: `Hello world`.
124+
125+
### Broadcast messages in binary format
141126

142-
Using this library, you can send messages to the client connections. A message can either be string text, JSON or binary payload.
127+
```python
128+
>>> import io
129+
>>> from azure.messaging.webpubsubservice import WebPubSubServiceClient
130+
>>> service = WebPubSubServiceClient.from_connection_string('<connection_string>', hub='hub')
131+
>>> service.send_to_all(message=io.StringIO('Hello World'), content_type='application/octet-stream')
132+
```
133+
The WebSocket client will receive binary text: `b'Hello world'`.
143134

144135
## Troubleshooting
145136

@@ -165,22 +156,22 @@ logger.addHandler(handler)
165156
endpoint = "<endpoint>"
166157
credential = DefaultAzureCredential()
167158

168-
# This client will log detailed information about its HTTP sessions, at DEBUG level
169-
client = WebPubSubServiceClient(endpoint=endpoint, credential=credential, logging_enable=True)
159+
# This WebPubSubServiceClient will log detailed information about its HTTP sessions, at DEBUG level
160+
service = WebPubSubServiceClient(endpoint=endpoint, hub='hub', credential=credential, logging_enable=True)
170161
```
171162

172163
Similarly, `logging_enable` can enable detailed logging for a single call,
173-
even when it isn't enabled for the client:
164+
even when it isn't enabled for the WebPubSubServiceClient:
174165

175166
```python
176-
result = client.send_to_all(..., logging_enable=True)
167+
result = service.send_to_all(..., logging_enable=True)
177168
```
178169

179170
Http request and response details are printed to stdout with this logging config.
180171

181172
## Next steps
182173

183-
More examples are coming soon...
174+
Check [more samples here][samples].
184175

185176
## Contributing
186177

@@ -201,22 +192,24 @@ additional questions or comments.
201192

202193
<!-- LINKS -->
203194
[webpubsubservice_docs]: https://aka.ms/awps/doc
204-
[azure_cli]: https://docs.microsoft.com/cli/azure
195+
[azure_cli]: /cli/azure
205196
[azure_sub]: https://azure.microsoft.com/free/
206197
[package]: https://pypi.org/project/azure-messaging-webpubsubservice/
207198
[default_cred_ref]: https://aka.ms/azsdk-python-identity-default-cred-ref
208199
[cla]: https://cla.microsoft.com
209200
[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/
210201
[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/
211202
[coc_contact]: mailto:opencode@microsoft.com
212-
[authenticate_with_token]: https://docs.microsoft.com/azure/cognitive-services/authentication?tabs=powershell#authenticate-with-an-authentication-token
213-
[azure_identity_credentials]: https://github.com/Azure/azure-sdk-for-python/tree/azure-messaging-webpubsubservice_1.0.0b2/sdk/identity/azure-identity#credentials
203+
[authenticate_with_token]: /azure/cognitive-services/authentication?tabs=powershell#authenticate-with-an-authentication-token
204+
[azure_identity_credentials]: https://github.com/Azure/azure-sdk-for-python/tree/azure-messaging-webpubsubservice_1.1.0b1/sdk/identity/azure-identity#credentials
214205
[azure_identity_pip]: https://pypi.org/project/azure-identity/
215-
[default_azure_credential]: https://github.com/Azure/azure-sdk-for-python/tree/azure-messaging-webpubsubservice_1.0.0b2/sdk/identity/azure-identity#defaultazurecredential
206+
[default_azure_credential]: https://github.com/Azure/azure-sdk-for-python/tree/azure-messaging-webpubsubservice_1.1.0b1/sdk/identity/azure-identity#defaultazurecredential
216207
[pip]: https://pypi.org/project/pip/
217-
[enable_aad]: https://docs.microsoft.com/azure/azure-web-pubsub/howto-develop-create-instance
218-
[api_key]: https://docs.microsoft.com/azure/azure-web-pubsub/howto-websocket-connect?tabs=browser#authorization
219-
[connection_string]: https://docs.microsoft.com/azure/azure-web-pubsub/howto-websocket-connect?tabs=browser#authorization
220-
[azure_portal]: https://docs.microsoft.com/azure/azure-web-pubsub/howto-develop-create-instance
208+
[enable_aad]: /azure/azure-web-pubsub/howto-develop-create-instance
209+
[api_key]: /azure/azure-web-pubsub/howto-websocket-connect?tabs=browser#authorization
210+
[connection_string]: /azure/azure-web-pubsub/howto-websocket-connect?tabs=browser#authorization
211+
[azure_portal]: /azure/azure-web-pubsub/howto-develop-create-instance
221212
[azure-key-credential]: https://aka.ms/azsdk-python-core-azurekeycredential
213+
[aad_doc]: https://aka.ms/awps/aad
214+
[samples]: https://github.com/Azure/azure-sdk-for-python/tree/azure-messaging-webpubsubservice_1.1.0b1/sdk/webpubsub/azure-messaging-webpubsubservice/samples
222215

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"Name": "azure-messaging-webpubsubservice",
3-
"Version": "1.0.0b2",
3+
"Version": "1.1.0b1",
44
"DevVersion": null,
55
"DirectoryPath": "sdk/webpubsub/azure-messaging-webpubsubservice",
66
"ServiceDirectory": "webpubsub",
@@ -10,5 +10,5 @@
1010
"SdkType": "client",
1111
"IsNewSdk": true,
1212
"ArtifactName": "azure-messaging-webpubsubservice",
13-
"ReleaseStatus": "2021-10-14"
13+
"ReleaseStatus": "2022-12-12"
1414
}

0 commit comments

Comments
 (0)