Skip to content

Commit 8de030b

Browse files
authored
Merge pull request #195630 from grminch/signalr-ci-python
Edit pass complete; ready for PR
2 parents aa0890b + 20829f9 commit 8de030b

File tree

1 file changed

+39
-47
lines changed

1 file changed

+39
-47
lines changed

articles/azure-signalr/signalr-quickstart-azure-functions-python.md

Lines changed: 39 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,61 +3,55 @@ title: Azure SignalR Service serverless quickstart - Python
33
description: A quickstart for using Azure SignalR Service and Azure Functions to create an App showing GitHub star count using Python.
44
author: vicancy
55
ms.author: lianwei
6-
ms.date: 06/09/2021
6+
ms.date: 04/19/2022
77
ms.topic: quickstart
88
ms.service: signalr
99
ms.devlang: python
1010
ms.custom: devx-track-python, mode-api
1111
---
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
1313

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

1616
> [!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).
1818
1919
## Prerequisites
2020

2121
This quickstart can be run on macOS, Windows, or Linux.
2222

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/).
2424

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

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).)
2828

29-
[!INCLUDE [quickstarts-free-trial-note](../../includes/quickstarts-free-trial-note.md)]
30-
31-
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).
3430

35-
Sign in to the Azure portal at <https://portal.azure.com/> with your Azure account.
31+
[!INCLUDE [quickstarts-free-trial-note](../../includes/quickstarts-free-trial-note.md)]
3632

37-
Having issues? Try the [troubleshooting guide](signalr-howto-troubleshoot-guide.md) or [let us know](https://aka.ms/asrs/qspython).
33+
## Create an Azure SignalR Service instance
3834

3935
[!INCLUDE [Create instance](includes/signalr-quickstart-create-instance.md)]
4036

41-
Having issues? Try the [troubleshooting guide](signalr-howto-troubleshoot-guide.md) or [let us know](https://aka.ms/asrs/qspython).
42-
43-
4437
## Setup and run the Azure Function locally
4538

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

4841
```bash
4942
# Initialize a function project
5043
func init --worker-runtime python
5144
```
5245

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`.
5447

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

5750
```bash
5851
func new -n index -t HttpTrigger
5952
```
60-
Open `index/function.json` and copy the following json codes:
53+
54+
Open *index/function.json* and copy the following json code:
6155

6256
```json
6357
{
@@ -81,27 +75,26 @@ Having issues? Try the [troubleshooting guide](signalr-howto-troubleshoot-guide.
8175
}
8276
```
8377

84-
Open `index/__init__.py` and copy the following codes.
78+
Open *index/\__init\__.py* and copy the following code:
8579

8680
```javascript
8781
import os
8882
8983
import azure.functions as func
90-
91-
84+
9285
def main(req: func.HttpRequest) -> func.HttpResponse:
9386
f = open(os.path.dirname(os.path.realpath(__file__)) + '/../content/index.html')
9487
return func.HttpResponse(f.read(), mimetype='text/html')
9588
```
96-
89+
9790
2. Create a `negotiate` function for clients to get access token.
98-
91+
9992
```bash
10093
func new -n negotiate -t HttpTrigger
10194
```
102-
103-
Open `negotiate/function.json` and copy the following json codes:
104-
95+
96+
Open *negotiate/function.json* and copy the following json code:
97+
10598
```json
10699
{
107100
"scriptFile": "__init__.py",
@@ -131,7 +124,7 @@ Having issues? Try the [troubleshooting guide](signalr-howto-troubleshoot-guide.
131124
}
132125
```
133126

134-
And open the `negotiate/__init__.py` and copy the following codes:
127+
Open *negotiate/\__init\__.py* and copy the following code:
135128

136129
```python
137130
import azure.functions as func
@@ -140,7 +133,7 @@ Having issues? Try the [troubleshooting guide](signalr-howto-troubleshoot-guide.
140133
def main(req: func.HttpRequest, connectionInfo) -> func.HttpResponse:
141134
return func.HttpResponse(connectionInfo)
142135
```
143-
136+
144137
3. Create a `broadcast` function to broadcast messages to all clients. In the sample, we use time trigger to broadcast messages periodically.
145138

146139
```bash
@@ -149,7 +142,7 @@ Having issues? Try the [troubleshooting guide](signalr-howto-troubleshoot-guide.
149142
pip install requests
150143
```
151144

152-
Open `broadcast/function.json` and copy the following codes.
145+
Open *broadcast/function.json* and copy the following code:
153146

154147
```json
155148
{
@@ -172,7 +165,7 @@ Having issues? Try the [troubleshooting guide](signalr-howto-troubleshoot-guide.
172165
}
173166
```
174167

175-
Open `broadcast/__init__.py` and copy the following codes.
168+
Open *broadcast/\__init\__.py* and copy the following code:
176169

177170
```python
178171
import requests
@@ -201,7 +194,7 @@ Having issues? Try the [troubleshooting guide](signalr-howto-troubleshoot-guide.
201194
}))
202195
```
203196
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* in the `index` function, and then create a new file *index.html* in the `content` directory under your project root folder. Copy the following content:
205198
206199
```html
207200
<html>
@@ -228,43 +221,42 @@ Having issues? Try the [troubleshooting guide](signalr-howto-troubleshoot-guide.
228221
229222
</html>
230223
```
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.
233224
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.
235228
236229
![Search for the SignalR Service instance](media/signalr-quickstart-azure-functions-csharp/signalr-quickstart-search-instance.png)
237230
238231
2. Select **Keys** to view the connection strings for the SignalR Service instance.
239-
232+
240233
![Screenshot that highlights the primary connection string.](media/signalr-quickstart-azure-functions-javascript/signalr-quickstart-keys.png)
241234
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:
236+
244237
```bash
245238
func settings add AzureSignalRConnectionString "<signalr-connection-string>"
246239
```
247-
248-
5. Run the Azure Function in local:
240+
241+
5. Run the Azure Function in the local environment:
249242
250243
```bash
251244
func start
252245
```
253246
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.
255248
256249
> [!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.`
259252
260253
[!INCLUDE [Cleanup](includes/signalr-quickstart-cleanup.md)]
261254
262255
Having issues? Try the [troubleshooting guide](signalr-howto-troubleshoot-guide.md) or [let us know](https://aka.ms/asrs/qspython).
263256
264257
## Next steps
265258
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.
268260
269261
> [!div class="nextstepaction"]
270262
> [SignalR Service bindings for Azure Functions](../azure-functions/functions-bindings-signalr-service.md)

0 commit comments

Comments
 (0)