Skip to main content

Microsoft App Configuration Data Library for Python

Project description

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

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:

pip install azure-appconfiguration

Prerequisites: You must have an Azure subscription, and a 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:

az appconfig create --name <config-store-name> --resource-group <resource-group-name> --location eastus

Authenticate the client

In order to interact with the App Configuration service, you'll need to create an instance of the AzureAppConfigurationClient 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.

az appconfig credential list --name <config-store-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:

    from azure.appconfiguration import AzureAppConfigurationClient

    connection_str = "<connection_string>"
    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:

    key : str
    label : str
    content_type : str
    value : str
    last_modified : str
    read_only : bool
    tags : dict
    etag : str

Examples

The following sections provide several code snippets covering some of the most common Configuration Service tasks, including:

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.
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.
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.

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

deleted_config_setting = client.delete_configuration_setting(
    key="MyKey", label="MyLabel"
)

List Configuration Settings

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

from azure.appconfiguration.aio import AzureAppConfigurationClient

connection_str = "<connection_string>"
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:

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

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.

import logging

logging.basicConfig(level=logging.DEBUG)

Http request and response details are printed to stdout with this logging config.

Release History


2019-12-03 Version 1.0.0b6

Features

  • Add sync-token support #8418

Breaking changes

  • Combine set_read_only & clear_read_only to be set_read_only(True/False) #8453

2019-10-30 Version 1.0.0b5

Breaking changes

  • etag and match_condition of delete_configuration_setting are now keyword argument only #8161

2019-10-07 Version 1.0.0b4

  • Add conditional operation support
  • Add set_read_only and clear_read_only methods

2019-09-09 Version 1.0.0b3

  • New azure app configuration

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

azure-appconfiguration-1.0.0b6.zip (66.7 kB view details)

Uploaded Source

Built Distribution

azure_appconfiguration-1.0.0b6-py2.py3-none-any.whl (35.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file azure-appconfiguration-1.0.0b6.zip.

File metadata

  • Download URL: azure-appconfiguration-1.0.0b6.zip
  • Upload date:
  • Size: 66.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.8.0

File hashes

Hashes for azure-appconfiguration-1.0.0b6.zip
Algorithm Hash digest
SHA256 9ead95dd781b04c0c63e3629cccd4747d3ada0bd2a0f23fec49e3c3a8e665b65
MD5 1f5a406f6a1746476da214e7afef56a1
BLAKE2b-256 81ddada8cf745d190b68d9b08b15f7aa3e0a9fbcb9007d80cb881206410fcb04

See more details on using hashes here.

File details

Details for the file azure_appconfiguration-1.0.0b6-py2.py3-none-any.whl.

File metadata

  • Download URL: azure_appconfiguration-1.0.0b6-py2.py3-none-any.whl
  • Upload date:
  • Size: 35.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.8.0

File hashes

Hashes for azure_appconfiguration-1.0.0b6-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e2e905239baee1015485934e820db79f68ee26f521c48b88fde0c992b5cf8bfa
MD5 b7ac5fc2feb19f75f45d39137b8ffad6
BLAKE2b-256 964f6586edaa6b2a163b0cac65863eae306d7bdb8a2cef365b998ebc6779cc0c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page