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
@@ -70,53 +70,6 @@ Add the following key-value to the App Configuration store and leave **Label** a
70
70
> [!NOTE]
71
71
> The code snippets in this example will help you get started with the App Configuration client library for Python. For your application, you should also consider handling exceptions according to your needs. To learn more about exception handling, please refer to our [Python SDK documentation](https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/appconfiguration/azure-appconfiguration).
72
72
73
-
## Configure an environment variable.
74
-
75
-
### [Microsoft Entra ID (recommended)](#tab/entra-id)
76
-
77
-
Set the environment variable named **AZURE_APPCONFIG_ENDPOINT** to the endpoint of your App Configuration store found under the *Overview* of your store in the Azure portal.
78
-
79
-
If you use the Windows command prompt, run the following command and restart the command prompt to allow the change to take effect:
Set the environment variable named **AZURE_APPCONFIG_CONNECTION_STRING** to the read-only connection string of your App Configuration store found under *Access keys* of your store in the Azure portal.
100
-
101
-
If you use the Windows command prompt, run the following command and restart the command prompt to allow the change to take effect:
The sample code snippets in this section show you how to perform common operations with the App Configuration client library for Python. Add these code snippets to the `try` block in *app-configuration-example.py* file you created earlier.
@@ -137,10 +90,12 @@ Learn below how to:
137
90
138
91
### Connect to an App Configuration store
139
92
140
-
The following code snippet creates an instance of **AzureAppConfigurationClient** using the environment variable you created in the step above.
93
+
The following code snippet creates an instance of **AzureAppConfigurationClient**. You can connect to your App Configuration store using Microsoft Entra ID (recommended), or a connection string.
141
94
142
95
### [Microsoft Entra ID (recommended)](#tab/entra-id)
143
96
97
+
You use the `DefaultAzureCredential` to authenticate to your App Configuration store. Follow the [instructions](./concept-enable-rbac.md#authentication-with-token-credentials) to assign your credential the **App Configuration Data Reader** role. Be sure to allow sufficient time for the permission to propagate before running your application.
98
+
144
99
```python
145
100
from azure.identity import DefaultAzureCredential
146
101
from azure.appconfiguration import AzureAppConfigurationClient
@@ -237,145 +192,192 @@ The following code snippet deletes a configuration setting by `key` name.
237
192
238
193
## Run the app
239
194
240
-
In this example, you created a Python app that uses the Azure App Configuration client library to retrieve a configuration setting created through the Azure portal, add a new setting, retrieve a list of existing settings, lock and unlock a setting, update a setting, and finally delete a setting.
241
-
242
-
At this point, your *app-configuration-example.py* file should have the following code:
243
-
244
-
### [Microsoft Entra ID (recommended)](#tab/entra-id)
245
-
246
-
```python
247
-
import os
248
-
from azure.identity import DefaultAzureCredential
249
-
from azure.appconfiguration import AzureAppConfigurationClient, ConfigurationSetting
In your console window, navigate to the directory containing the *app-configuration-example.py* file and execute the following Python command to run the app:
349
-
350
-
```console
351
-
python app-configuration-example.py
352
-
```
353
-
354
-
You should see the following output:
355
-
356
-
```output
357
-
Azure App Configuration - Python example
358
-
359
-
Retrieved configuration setting:
360
-
Key: TestApp:Settings:Message, Value: Data from Azure App Configuration
361
-
362
-
Added configuration setting:
363
-
Key: TestApp:Settings:NewSetting, Value: New setting value
364
-
365
-
Retrieved list of configuration settings:
366
-
Key: TestApp:Settings:Message, Value: Data from Azure App Configuration
367
-
Key: TestApp:Settings:NewSetting, Value: New setting value
368
-
369
-
Read-only status for TestApp:Settings:NewSetting: True
370
-
371
-
Read-only status for TestApp:Settings:NewSetting: False
195
+
1. In this example, you created a Python app that uses the Azure App Configuration client library to retrieve a configuration setting created through the Azure portal, add a new setting, retrieve a list of existing settings, lock and unlock a setting, update a setting, and finally delete a setting.
196
+
197
+
At this point, your *app-configuration-example.py* file should have the following code:
198
+
199
+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
200
+
201
+
```python
202
+
import os
203
+
from azure.identity import DefaultAzureCredential
204
+
from azure.appconfiguration import AzureAppConfigurationClient, ConfigurationSetting
Key: TestApp:Settings:NewSetting, Value: Value has been updated!
303
+
1. Configure an environment variable
304
+
305
+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
306
+
307
+
Set the environment variable named **AZURE_APPCONFIG_ENDPOINT** to the endpoint of your App Configuration store found under the *Overview* of your store in the Azure portal.
308
+
309
+
If you use the Windows command prompt, run the following command and restart the command prompt to allow the change to take effect:
Set the environment variable named **AZURE_APPCONFIG_CONNECTION_STRING** to the read-only connection string of your App Configuration store found under *Access keys* of your store in the Azure portal.
330
+
331
+
If you use the Windows command prompt, run the following command and restart the command prompt to allow the change to take effect:
Key: TestApp:Settings:NewSetting, Value: Value has been updated!
378
-
```
350
+
1. After the environment variable is properly set, in your console window, navigate to the directory containing the *app-configuration-example.py*fileand execute the following Python command to run the app:
351
+
352
+
```console
353
+
python app-configuration-example.py
354
+
```
355
+
356
+
You should see the following output:
357
+
358
+
```output
359
+
Azure App Configuration - Python example
360
+
361
+
Retrieved configuration setting:
362
+
Key: TestApp:Settings:Message, Value: Data from Azure App Configuration
363
+
364
+
Added configuration setting:
365
+
Key: TestApp:Settings:NewSetting, Value: New setting value
366
+
367
+
Retrieved list of configuration settings:
368
+
Key: TestApp:Settings:Message, Value: Data from Azure App Configuration
369
+
Key: TestApp:Settings:NewSetting, Value: New setting value
370
+
371
+
Read-only status for TestApp:Settings:NewSetting: True
372
+
373
+
Read-only status for TestApp:Settings:NewSetting: False
374
+
375
+
Updated configuration setting:
376
+
Key: TestApp:Settings:NewSetting, Value: Value has been updated!
377
+
378
+
Deleted configuration setting:
379
+
Key: TestApp:Settings:NewSetting, Value: Value has been updated!
0 commit comments