.. role:: raw-html-m2r(raw) :format: html Azure App Configuration client library for Python ================================================= Azure App Configuration is a managed service that helps developers centralize their application configurations simply and securely. Modern programs, especially programs running in a cloud, generally have many components that are distributed in nature. Spreading configuration settings across these components can lead to hard-to-troubleshoot errors during an application deployment. Use App Configuration to securely store all the settings for your application in one place. Use the client library for App Configuration to create and manage application configuration settings. `Source code <>`_ | `Package (Pypi) `_ | `API reference documentation <>`_ | [Product documentation][azconfig_docs] Getting started --------------- Supported Python version ^^^^^^^^^^^^^^^^^^^^^^^^ Python 2.7 and 3.5+ Install the package ^^^^^^^^^^^^^^^^^^^ Install the Azure App Configuration client library for Python with pip: .. code-block:: commandline pip install azure-appconfiguration **Prerequisites**\ : You must have an `Azure subscription `_\ , and a [Configuration Store][configuration_store] to use this package. To create a Configuration Store, you can use the Azure Portal or `Azure CLI `_. After that, create the Configuration Store: .. code-block:: Powershell az appconfig create --name --resource-group --location eastus Authenticate the client ^^^^^^^^^^^^^^^^^^^^^^^ In order to interact with the App Configuration service, you'll need to create an instance of the `AzureAppConfigurationClient <./azure/configuration/azure_configuration_client.py>`_ class. To make this possible, you'll need the connection string of the Configuration Store. Get credentials ~~~~~~~~~~~~~~~ Use the `Azure CLI `_ snippet below to get the connection string from the Configuration Store. .. code-block:: Powershell az appconfig credential list --name Alternatively, get the connection string from the Azure Portal. Create client ~~~~~~~~~~~~~ Once you have the value of the connection string, you can create the AzureAppConfigurationClient: .. code-block:: python from azure.appconfiguration import AzureAppConfigurationClient connection_str = "" client = AzureAppConfigurationClient.from_connection_string(connection_str) Key concepts ------------ Configuration Setting ^^^^^^^^^^^^^^^^^^^^^ A Configuration Setting is the fundamental resource within a Configuration Store. In its simplest form it is a key and a value. However, there are additional properties such as the modifiable content type and tags fields that allow the value to be interpreted or associated in different ways. The Label property of a Configuration Setting provides a way to separate Configuration Settings into different dimensions. These dimensions are user defined and can take any form. Some common examples of dimensions to use for a label include regions, semantic versions, or environments. Many applications have a required set of configuration keys that have varying values as the application exists across different dimensions. For example, MaxRequests may be 100 in "NorthAmerica", and 200 in "WestEurope". By creating a Configuration Setting named MaxRequests with a label of "NorthAmerica" and another, only with a different value, in the "WestEurope" label, an application can seamlessly retrieve Configuration Settings as it runs in these two dimensions. Properties of a Configuration Setting: .. code-block:: python key : str label : str content_type : str value : str last_modified : str locked : bool tags : dict etag : str Examples -------- The following sections provide several code snippets covering some of the most common Configuration Service tasks, including: * `Azure App Configuration client library for Python <#azure-app-configuration-client-library-for-python>`_ * `Getting started <#getting-started>`_ * `Supported Python version <#supported-python-version>`_ * `Install the package <#install-the-package>`_ * `Authenticate the client <#authenticate-the-client>`_ * `Get credentials <#get-credentials>`_ * `Create client <#create-client>`_ * `Key concepts <#key-concepts>`_ * `Configuration Setting <#configuration-setting>`_ * `Examples <#examples>`_ * `Create a Configuration Setting <#create-a-configuration-setting>`_ * `Get a Configuration Setting <#get-a-configuration-setting>`_ * `Delete a Configuration Setting <#delete-a-configuration-setting>`_ * `List Configuration Settings <#list-configuration-settings>`_ * `Async Client <#async-client>`_ * `Troubleshooting <#troubleshooting>`_ * `Logging <#logging>`_ ### Create a Configuration Setting Create a Configuration Setting to be stored in the Configuration Store. There are two ways to store a Configuration Setting: * add_configuration_setting creates a setting only if the setting does not already exist in the store. .. code-block:: python config_setting = ConfigurationSetting( key="MyKey", label="MyLabel", value="my value", content_type="my content type", tags={"my tag": "my tag value"} ) added_config_setting = client.add_configuration_setting(config_setting) * set_configuration_setting creates a setting if it doesn't exist or overrides an existing setting. .. code-block:: python config_setting = ConfigurationSetting( key="MyKey", label="MyLabel", value="my set value", content_type="my set content type", tags={"my set tag": "my set tag value"} ) returned_config_setting = client.set_configuration_setting(config_setting) Get a Configuration Setting ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Get a previously stored Configuration Setting. .. code-block:: python fetched_config_setting = client.get_configuration_setting( key="MyKey", label="MyLabel" ) Delete a Configuration Setting ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Delete an existing Configuration Setting by calling delete_configuration_setting .. code-block:: python deleted_config_setting = client.delete_configuration_setting( key="MyKey", label="MyLabel" ) List Configuration Settings ^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: python filtered_listed = client.list_configuration_settings( labels=["*Labe*"], keys=["*Ke*"] ) for item in filtered_listed: pass # do something Async Client ------------ Async client is supported for python 3.5+. To use the async client library, import the AzureAppConfigurationClient from package azure.appconfiguration.aio instead of azure.appconfiguration .. code-block:: python from azure.appconfiguration.aio import AzureAppConfigurationClient connection_str = "" async_client = AzureAppConfigurationClient.from_connection_string(connection_str) This async AzureAppConfigurationClient has the same method signatures as the sync ones except that they're async. For instance, to retrieve a Configuration Setting asynchronously, async_client can be used: .. code-block:: python fetched_config_setting = await async_client.get_configuration_setting( key="MyKey", label="MyLabel" ) To use list_configuration_settings, call it synchronously and iterate over the returned async iterator asynchronously .. code-block:: python filtered_listed = async_client.list_configuration_settings( labels=["*Labe*"], keys=["*Ke*"] ) async for item in filtered_listed: pass # do something Troubleshooting --------------- Logging ^^^^^^^ This SDK uses Python standard logging library. You can configure logging print out debugging information to the stdout or anywhere you want. .. code-block:: python import logging logging.basicConfig(level=logging.DEBUG) ` Http request and response details are printed to stdout with this logging config. :raw-html-m2r:`` Indices and tables ------------------ * :ref:`genindex` * :ref:`modindex` * :ref:`search` .. toctree:: :maxdepth: 5 :glob: :caption: Developer Documentation azure.appconfiguration.rst