@@ -192,113 +192,113 @@ The following code snippet deletes a configuration setting by `key` name.
192
192
193
193
## Run the app
194
194
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
205
-
206
- try :
207
- print (" Azure App Configuration - Python example" )
208
- # Example code goes here
209
-
210
- credential = DefaultAzureCredential()
211
- endpoint = os.getenv(' AZURE_APPCONFIG_ENDPOINT' )
212
- app_config_client = AzureAppConfigurationClient(base_url = endpoint, credential = credential)
213
-
214
- retrieved_config_setting = app_config_client.get_configuration_setting(key = ' TestApp:Settings:Message' )
215
- print (" \n Retrieved configuration setting:" )
216
- print (" Key: " + retrieved_config_setting.key + " , Value: " + retrieved_config_setting.value)
217
-
218
- config_setting = ConfigurationSetting(
219
- key = ' TestApp:Settings:NewSetting' ,
220
- value = ' New setting value'
221
- )
222
- added_config_setting = app_config_client.add_configuration_setting(config_setting)
223
- print (" \n Added configuration setting:" )
224
- print (" Key: " + added_config_setting.key + " , Value: " + added_config_setting.value)
225
-
226
- filtered_settings_list = app_config_client.list_configuration_settings(key_filter = " TestApp*" )
227
- print (" \n Retrieved list of configuration settings:" )
228
- for item in filtered_settings_list:
229
- print (" Key: " + item.key + " , Value: " + item.value)
230
-
231
- locked_config_setting = app_config_client.set_read_only(added_config_setting, read_only = True )
232
- print (" \n Read-only status for " + locked_config_setting.key + " : " + str (locked_config_setting.read_only))
233
-
234
- unlocked_config_setting = app_config_client.set_read_only(locked_config_setting, read_only = False )
235
- print (" \n Read-only status for " + unlocked_config_setting.key + " : " + str (unlocked_config_setting.read_only))
236
-
237
- added_config_setting.value = " Value has been updated!"
238
- updated_config_setting = app_config_client.set_configuration_setting(added_config_setting)
239
- print (" \n Updated configuration setting:" )
240
- print (" Key: " + updated_config_setting.key + " , Value: " + updated_config_setting.value)
241
-
242
- deleted_config_setting = app_config_client.delete_configuration_setting(key = " TestApp:Settings:NewSetting" )
243
- print (" \n Deleted configuration setting:" )
244
- print (" Key: " + deleted_config_setting.key + " , Value: " + deleted_config_setting.value)
245
-
246
- except Exception as ex:
247
- print (' Exception:' )
248
- print (ex)
249
- ```
250
-
251
- # ## [Connection string](#tab/connection-string)
252
-
253
- ```python
254
- import os
255
- from azure.appconfiguration import AzureAppConfigurationClient, ConfigurationSetting
256
-
257
- try :
258
- print (" Azure App Configuration - Python example" )
259
- # Example code goes here
260
-
261
- connection_string = os.getenv(' AZURE_APPCONFIG_CONNECTION_STRING' )
262
- app_config_client = AzureAppConfigurationClient.from_connection_string(connection_string)
263
-
264
- retrieved_config_setting = app_config_client.get_configuration_setting(key = ' TestApp:Settings:Message' )
265
- print (" \n Retrieved configuration setting:" )
266
- print (" Key: " + retrieved_config_setting.key + " , Value: " + retrieved_config_setting.value)
267
-
268
- config_setting = ConfigurationSetting(
269
- key = ' TestApp:Settings:NewSetting' ,
270
- value = ' New setting value'
271
- )
272
- added_config_setting = app_config_client.add_configuration_setting(config_setting)
273
- print (" \n Added configuration setting:" )
274
- print (" Key: " + added_config_setting.key + " , Value: " + added_config_setting.value)
275
-
276
- filtered_settings_list = app_config_client.list_configuration_settings(key_filter = " TestApp*" )
277
- print (" \n Retrieved list of configuration settings:" )
278
- for item in filtered_settings_list:
279
- print (" Key: " + item.key + " , Value: " + item.value)
280
-
281
- locked_config_setting = app_config_client.set_read_only(added_config_setting, read_only = True )
282
- print (" \n Read-only status for " + locked_config_setting.key + " : " + str (locked_config_setting.read_only))
283
-
284
- unlocked_config_setting = app_config_client.set_read_only(locked_config_setting, read_only = False )
285
- print (" \n Read-only status for " + unlocked_config_setting.key + " : " + str (unlocked_config_setting.read_only))
286
-
287
- added_config_setting.value = " Value has been updated!"
288
- updated_config_setting = app_config_client.set_configuration_setting(added_config_setting)
289
- print (" \n Updated configuration setting:" )
290
- print (" Key: " + updated_config_setting.key + " , Value: " + updated_config_setting.value)
291
-
292
- deleted_config_setting = app_config_client.delete_configuration_setting(key = " TestApp:Settings:NewSetting" )
293
- print (" \n Deleted configuration setting:" )
294
- print (" Key: " + deleted_config_setting.key + " , Value: " + deleted_config_setting.value)
295
-
296
- except Exception as ex:
297
- print (' Exception:' )
298
- print (ex)
299
- ```
300
-
301
- -- -
195
+ 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
205
+
206
+ try :
207
+ print (" Azure App Configuration - Python example" )
208
+ # Example code goes here
209
+
210
+ credential = DefaultAzureCredential()
211
+ endpoint = os.getenv(' AZURE_APPCONFIG_ENDPOINT' )
212
+ app_config_client = AzureAppConfigurationClient(base_url = endpoint, credential = credential)
213
+
214
+ retrieved_config_setting = app_config_client.get_configuration_setting(key = ' TestApp:Settings:Message' )
215
+ print (" \n Retrieved configuration setting:" )
216
+ print (" Key: " + retrieved_config_setting.key + " , Value: " + retrieved_config_setting.value)
217
+
218
+ config_setting = ConfigurationSetting(
219
+ key = ' TestApp:Settings:NewSetting' ,
220
+ value = ' New setting value'
221
+ )
222
+ added_config_setting = app_config_client.add_configuration_setting(config_setting)
223
+ print (" \n Added configuration setting:" )
224
+ print (" Key: " + added_config_setting.key + " , Value: " + added_config_setting.value)
225
+
226
+ filtered_settings_list = app_config_client.list_configuration_settings(key_filter = " TestApp*" )
227
+ print (" \n Retrieved list of configuration settings:" )
228
+ for item in filtered_settings_list:
229
+ print (" Key: " + item.key + " , Value: " + item.value)
230
+
231
+ locked_config_setting = app_config_client.set_read_only(added_config_setting, read_only = True )
232
+ print (" \n Read-only status for " + locked_config_setting.key + " : " + str (locked_config_setting.read_only))
233
+
234
+ unlocked_config_setting = app_config_client.set_read_only(locked_config_setting, read_only = False )
235
+ print (" \n Read-only status for " + unlocked_config_setting.key + " : " + str (unlocked_config_setting.read_only))
236
+
237
+ added_config_setting.value = " Value has been updated!"
238
+ updated_config_setting = app_config_client.set_configuration_setting(added_config_setting)
239
+ print (" \n Updated configuration setting:" )
240
+ print (" Key: " + updated_config_setting.key + " , Value: " + updated_config_setting.value)
241
+
242
+ deleted_config_setting = app_config_client.delete_configuration_setting(key = " TestApp:Settings:NewSetting" )
243
+ print (" \n Deleted configuration setting:" )
244
+ print (" Key: " + deleted_config_setting.key + " , Value: " + deleted_config_setting.value)
245
+
246
+ except Exception as ex:
247
+ print (' Exception:' )
248
+ print (ex)
249
+ ```
250
+
251
+ ### [ Connection string] ( #tab/connection-string )
252
+
253
+ ``` python
254
+ import os
255
+ from azure.appconfiguration import AzureAppConfigurationClient, ConfigurationSetting
256
+
257
+ try :
258
+ print (" Azure App Configuration - Python example" )
259
+ # Example code goes here
260
+
261
+ connection_string = os.getenv(' AZURE_APPCONFIG_CONNECTION_STRING' )
262
+ app_config_client = AzureAppConfigurationClient.from_connection_string(connection_string)
263
+
264
+ retrieved_config_setting = app_config_client.get_configuration_setting(key = ' TestApp:Settings:Message' )
265
+ print (" \n Retrieved configuration setting:" )
266
+ print (" Key: " + retrieved_config_setting.key + " , Value: " + retrieved_config_setting.value)
267
+
268
+ config_setting = ConfigurationSetting(
269
+ key = ' TestApp:Settings:NewSetting' ,
270
+ value = ' New setting value'
271
+ )
272
+ added_config_setting = app_config_client.add_configuration_setting(config_setting)
273
+ print (" \n Added configuration setting:" )
274
+ print (" Key: " + added_config_setting.key + " , Value: " + added_config_setting.value)
275
+
276
+ filtered_settings_list = app_config_client.list_configuration_settings(key_filter = " TestApp*" )
277
+ print (" \n Retrieved list of configuration settings:" )
278
+ for item in filtered_settings_list:
279
+ print (" Key: " + item.key + " , Value: " + item.value)
280
+
281
+ locked_config_setting = app_config_client.set_read_only(added_config_setting, read_only = True )
282
+ print (" \n Read-only status for " + locked_config_setting.key + " : " + str (locked_config_setting.read_only))
283
+
284
+ unlocked_config_setting = app_config_client.set_read_only(locked_config_setting, read_only = False )
285
+ print (" \n Read-only status for " + unlocked_config_setting.key + " : " + str (unlocked_config_setting.read_only))
286
+
287
+ added_config_setting.value = " Value has been updated!"
288
+ updated_config_setting = app_config_client.set_configuration_setting(added_config_setting)
289
+ print (" \n Updated configuration setting:" )
290
+ print (" Key: " + updated_config_setting.key + " , Value: " + updated_config_setting.value)
291
+
292
+ deleted_config_setting = app_config_client.delete_configuration_setting(key = " TestApp:Settings:NewSetting" )
293
+ print (" \n Deleted configuration setting:" )
294
+ print (" Key: " + deleted_config_setting.key + " , Value: " + deleted_config_setting.value)
295
+
296
+ except Exception as ex:
297
+ print (' Exception:' )
298
+ print (ex)
299
+ ```
300
+
301
+ ---
302
302
303
303
1 . Configure an environment variable
304
304
0 commit comments