Azure App Configuration Client

1.8.0 · active · verified Thu Apr 09

The Microsoft App Configuration Data Client Library for Python provides functionality to manage application settings and feature flags in Azure App Configuration. It is currently at version 1.8.0 and follows the Azure SDK's regular release cadence, with updates typically several times a year.

Warnings

Install

Imports

Quickstart

Connect to an Azure App Configuration store and retrieve a key-value setting using `DefaultAzureCredential` for authentication. Remember to set the `AZURE_APPCONFIGURATION_ENDPOINT` environment variable and ensure the specified key exists.

import os
from azure.appconfiguration import AzureAppConfigurationClient
from azure.identity import DefaultAzureCredential

# It is recommended to set environment variables for your App Configuration endpoint and credentials.
# For example:
# AZURE_APPCONFIGURATION_ENDPOINT="https://<your-app-config-name>.azconfig.io"
# AZURE_CLIENT_ID="<your-client-id>"
# AZURE_CLIENT_SECRET="<your-client-secret>"
# AZURE_TENANT_ID="<your-tenant-id>" (if using service principal)

app_config_endpoint = os.environ.get('AZURE_APPCONFIGURATION_ENDPOINT', 'https://YOUR_APP_CONFIG_ENDPOINT.azconfig.io')
# The key of the setting you want to retrieve
config_key = "MyApplication:Settings:MyKey"

try:
    # DefaultAzureCredential attempts to authenticate via various methods:
    # Environment variables, Managed Identity, Azure CLI, Visual Studio Code, etc.
    credential = DefaultAzureCredential()

    # Create a synchronous client
    client = AzureAppConfigurationClient(endpoint=app_config_endpoint, credential=credential)

    # Retrieve a configuration setting.
    # By default, get_configuration_setting retrieves settings with no label.
    # If your setting has a label, you must specify it, e.g., label="development"
    setting = client.get_configuration_setting(key=config_key)

    if setting:
        print(f"Successfully retrieved setting:")
        print(f"  Key: {setting.key}")
        print(f"  Value: {setting.value}")
        print(f"  Label: {setting.label if setting.label else 'None'}")
        print(f"  Content Type: {setting.content_type if setting.content_type else 'None'}")
    else:
        print(f"Setting with key '{config_key}' not found or no label matched.")

except Exception as e:
    print(f"An error occurred: {e}")
    print("Please ensure 'AZURE_APPCONFIGURATION_ENDPOINT' is set and valid.")
    print(f"Also verify that a setting with key '{config_key}' exists in your Azure App Configuration store and your credentials have 'App Configuration Data Reader' permissions.")

view raw JSON →