You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: A quickstart for using Azure SignalR Service and Azure Functions to create an App showing GitHub star count using Python.
4
4
author: vicancy
5
5
ms.author: lianwei
6
-
ms.date: 06/09/2021
6
+
ms.date: 04/19/2022
7
7
ms.topic: quickstart
8
8
ms.service: signalr
9
9
ms.devlang: python
10
10
ms.custom: devx-track-python, mode-api
11
11
---
12
-
# Quickstart: Create an App showing GitHub star count with Azure Functions and SignalR Service using Python
12
+
# Quickstart: Create a serverless app with Azure Functions, SignalR Service, and Python
13
13
14
-
Azure SignalR Service lets you easily add real-time functionality to your application. Azure Functions is a serverless platform that lets you run your code without managing any infrastructure. In this quickstart, learn how to use SignalR Service and Azure Functions to build a serverless application with Python to broadcast messages to clients.
14
+
Get started with Azure SignalR Service by using Azure Functions and Python to build a serverless application that broadcasts messages to clients. You'll run the function in the local environment, connecting to an Azure SignalR Service instance in the cloud. Completing this quickstart incurs a small cost of a few USD cents or less in your Azure Account.
15
15
16
16
> [!NOTE]
17
-
> You can get all codes mentioned in the article from [GitHub](https://github.com/aspnet/AzureSignalR-samples/tree/main/samples/QuickStartServerless/python)
17
+
> You can get the code in this article from [GitHub](https://github.com/aspnet/AzureSignalR-samples/tree/main/samples/QuickStartServerless/python).
18
18
19
19
## Prerequisites
20
20
21
21
This quickstart can be run on macOS, Windows, or Linux.
22
22
23
-
Make sure you have a code editor such as [Visual Studio Code](https://code.visualstudio.com/) installed.
23
+
- You'll need a code editor such as [Visual Studio Code](https://code.visualstudio.com/).
24
24
25
-
Install the [Azure Functions Core Tools](https://github.com/Azure/azure-functions-core-tools#installing) (version 2.7.1505 or higher) to run Python Azure Function apps locally.
25
+
-Install the [Azure Functions Core Tools](https://github.com/Azure/azure-functions-core-tools#installing) (version 2.7.1505 or higher) to run Python Azure Function apps locally.
26
26
27
-
Azure Functions requires [Python 3.6+](https://www.python.org/downloads/). (See [Supported Python versions](../azure-functions/functions-reference-python.md#python-version))
27
+
-Azure Functions requires [Python 3.6+](https://www.python.org/downloads/). (See [Supported Python versions](../azure-functions/functions-reference-python.md#python-version).)
Having issues? Try the [troubleshooting guide](signalr-howto-troubleshoot-guide.md) or [let us know](https://aka.ms/asrs/qspython).
32
-
33
-
## Log in to Azure
29
+
- SignalR binding needs Azure Storage, but you can use a local storage emulator when a function is running locally. You'll need to download and enable [Storage Emulator](../storage/common/storage-use-emulator.md).
34
30
35
-
Sign in to the Azure portal at <https://portal.azure.com/> with your Azure account.
Having issues? Try the [troubleshooting guide](signalr-howto-troubleshoot-guide.md) or [let us know](https://aka.ms/asrs/qspython).
42
-
43
-
44
37
## Setup and run the Azure Function locally
45
38
46
-
1.Make sure you have Azure Function Core Tools installed. And create an empty directory and navigate to the directory with command line.
39
+
1.Create an empty directory and go to the directory with command line.
47
40
48
41
```bash
49
42
# Initialize a function project
50
43
func init --worker-runtime python
51
44
```
52
45
53
-
2. After you initialize a project, you need to create functions. In this sample, we need to create 3 functions.
46
+
2. After you initialize a project, you need to create functions. In this sample, we need to create three functions: `index`, `negotiate`, and `broadcast`.
54
47
55
-
1. Run the following command to create a`index` function, which will host a web page for client.
48
+
1. Run the following command to create an`index` function, which will host a web page for a client.
56
49
57
50
```bash
58
51
func new -n index -t HttpTrigger
59
52
```
60
-
Open `index/function.json` and copy the following json codes:
53
+
54
+
Open *index/function.json* and copy the following json code:
61
55
62
56
```json
63
57
{
@@ -81,27 +75,26 @@ Having issues? Try the [troubleshooting guide](signalr-howto-troubleshoot-guide.
81
75
}
82
76
```
83
77
84
-
Open `index/__init__.py` and copy the following codes.
78
+
Open *index/\__init\__.py* and copy the following code:
3. Create a `broadcast`functionto broadcast messages to all clients. In the sample, we use time trigger to broadcast messages periodically.
145
138
146
139
```bash
@@ -149,7 +142,7 @@ Having issues? Try the [troubleshooting guide](signalr-howto-troubleshoot-guide.
149
142
pip install requests
150
143
```
151
144
152
-
Open `broadcast/function.json` and copy the following codes.
145
+
Open *broadcast/function.json* and copy the following code:
153
146
154
147
```json
155
148
{
@@ -172,7 +165,7 @@ Having issues? Try the [troubleshooting guide](signalr-howto-troubleshoot-guide.
172
165
}
173
166
```
174
167
175
-
Open `broadcast/__init__.py` and copy the following codes.
168
+
Open *broadcast/\__init\__.py* and copy the following code:
176
169
177
170
```python
178
171
import requests
@@ -201,7 +194,7 @@ Having issues? Try the [troubleshooting guide](signalr-howto-troubleshoot-guide.
201
194
}))
202
195
```
203
196
204
-
3. The client interface of this sample is a web page. Considered we read HTML content from `content/index.html`in`index` function, create a new file `index.html`in`content` directory under your project root folder. And copy the following content.
197
+
3. The client interface of this sample is a web page. We read HTML content from *content/index.html*inthe `index` function, and thencreate a new file *index.html*inthe `content` directory under your project root folder. Copy the following content:
205
198
206
199
```html
207
200
<html>
@@ -228,43 +221,42 @@ Having issues? Try the [troubleshooting guide](signalr-howto-troubleshoot-guide.
228
221
229
222
</html>
230
223
```
231
-
232
-
4. It's almost done now. The last step is to set a connection string of the SignalR Service to Azure Function settings.
233
224
234
-
1. In the browser where the Azure portal is opened, confirm the SignalR Service instance you deployed earlier was successfully created by searching for its name in the search box at the top of the portal. Select the instance to open it.
225
+
4. We're almost done now. The last step is to set a connection string of the SignalR Service to Azure Function settings.
226
+
227
+
1. In the Azure portal, search for the SignalR Service instance you deployed earlier. Select the instance to open it.
235
228
236
229

237
230
238
231
2. Select **Keys** to view the connection strings for the SignalR Service instance.
239
-
232
+
240
233

241
234
242
-
3. Copy the primary connection string. And execute the command below.
243
-
235
+
3. Copy the primary connection string, and then run the following command:
5. Run the Azure Function in the local environment:
249
242
250
243
```bash
251
244
func start
252
245
```
253
246
254
-
After Azure Function running locally. Use your browser to visit `http://localhost:7071/api/index` and you can see the current star count. And if you star or unstar in the GitHub, you will get a star count refreshing every few seconds.
247
+
After the Azure Function is running locally, go to `http://localhost:7071/api/index` and you'll see the current star count. If you star or unstar in GitHub, you'll get a refreshed star count every few seconds.
255
248
256
249
> [!NOTE]
257
-
> SignalR binding needs Azure Storage, but you can use local storage emulator when the Function is running locally.
258
-
> If you got some error like `There was an error performing a read operation on the Blob Storage Secret Repository. Please ensure the 'AzureWebJobsStorage' connection string is valid.` You need to download and enable [Storage Emulator](../storage/common/storage-use-emulator.md)
250
+
> SignalR binding needs Azure Storage, but you can use a local storage emulator when the function is running locally.
251
+
> You need to download and enable [Storage Emulator](../storage/common/storage-use-emulator.md) if you got an error like `There was an error performing a read operation on the Blob Storage Secret Repository. Please ensure the 'AzureWebJobsStorage' connection string is valid.`
Having issues? Try the [troubleshooting guide](signalr-howto-troubleshoot-guide.md) or [let us know](https://aka.ms/asrs/qspython).
263
256
264
257
## Next steps
265
258
266
-
In this quickstart, you built and ran a real-time serverless application in local. Learn more how to use SignalR Service bindings for Azure Functions.
267
-
Next, learn more about how to bi-directional communicating between clients and Azure Function with SignalR Service.
259
+
In this quickstart, you built and ran a real-time serverless application in local. Next, learn more about how to use bi-directional communicating between clients and Azure Function with SignalR Service.
268
260
269
261
> [!div class="nextstepaction"]
270
262
> [SignalR Service bindings for Azure Functions](../azure-functions/functions-bindings-signalr-service.md)
0 commit comments