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
#Customer intent: As a Python developer, I want to dynamically update my app to use the latest configuration data in Azure App Configuration.
@@ -38,6 +38,44 @@ Add the following key-value to your Azure App Configuration store. For more info
38
38
39
39
1. Create a new Python file named *app.py* and add the following code:
40
40
41
+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
42
+
43
+
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.
44
+
45
+
```python
46
+
from azure.appconfiguration.provider import load, WatchKey
Copy file name to clipboardExpand all lines: articles/azure-app-configuration/quickstart-python-provider.md
+66-50Lines changed: 66 additions & 50 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,13 +2,13 @@
2
2
title: Quickstart for using Azure App Configuration with Python apps | Microsoft Learn
3
3
description: In this quickstart, create a Python app with the Azure App Configuration to centralize storage and management of application settings separate from your code.
#Customer intent: As a Python developer, I want to manage all my app settings in one place.
13
13
---
14
14
# Quickstart: Create a Python app with Azure App Configuration
@@ -57,17 +57,22 @@ In this section, you will create a console application and load data from your A
57
57
58
58
1. Create a new file called *app-configuration-quickstart.py* in the *app-configuration-quickstart* directory and add the following code:
59
59
60
+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
61
+
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.
# Print True or False to indicate if "message" is found in Azure App Configuration.
88
93
print("message found: " + str("message" in config))
89
94
print("test.message found: " + str("test.message" in config))
90
95
```
91
96
92
-
### Run the application
93
-
94
-
1. Set an environment variable named **AZURE_APPCONFIG_CONNECTION_STRING**, and set it to the connection string of your App Configuration store. At the command line, run the following command:
To run the app locally using the Windows command prompt, run the following command and replace `<app-configuration-store-connection-string>` with the connection string of your app configuration store:
107
+
# Connect to Azure App Configuration using a connection string.
# From the keys with trimmed prefixes, find a key with "message" and print its value.
119
+
print(config["message"])
105
120
106
-
If you use Windows PowerShell, run the following command and replace `<app-configuration-store-connection-string>` with the connection string of your app configuration store:
121
+
# Connect to Azure App Configuration using SettingSelector.
# Print True or False to indicate if "message" is found in Azure App Configuration.
126
+
print("message found: " + str("message" in config))
127
+
print("test.message found: " + str("test.message" in config))
110
128
```
129
+
---
111
130
112
-
#### [macOS](#tab/unix)
113
-
114
-
If you use macOS, run the following command and replace `<app-configuration-store-connection-string>` with the connection string of your app configuration store:
### [Microsoft Entra ID (recommended)](#tab/entra-id)
136
+
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.
121
137
122
-
If you use Linux, run the following command and replace `<app-configuration-store-connection-string>` with the connection string of your app configuration store:
138
+
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.
139
158
140
-
If you use Windows PowerShell, run the following command:
159
+
If you use the Windows command prompt, run the following command and restart the command prompt to allow the change to take effect:
1. After the environment variable is properly set, run the following command to run the app locally:
163
179
@@ -182,7 +198,7 @@ The App Configuration provider loads data into a `Mapping` object, accessible as
182
198
You can use Azure App Configuration in your existing Flask web apps by updating its in-built configuration. You can do this by passing your App Configuration provider object to the `update` function of your Flask app instance in `app.py`:
To access individual configuration settings in the Django views, you can reference them from the provider object created in Django settings. For example, in `views.py`:
0 commit comments