Skip to main content

Microsoft App Configuration Provider Library for Python

Project description

Azure App Configuration Python Provider client library for Python

Azure App Configuration is a managed service that helps developers centralize their application configurations simply and securely. This provider adds additional functionality above the azure-sdk-for-python.

Using the provider enables loading sets of configurations from an Azure App Configuration store in a managed way.

Getting started

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.

Creating a provider

You can create a client with a connection string:

config = load(connection_string="your-connection-string")

or with AAD:

config = load(endpoint="your-endpoint", credential=DefaultAzureCredential())

these providers will by default load all configurations with (No Label) from your configuration store.

Features

Currently the Azure App Configuration Provider enables:

  • Connecting to an App Configuration Store using a connection string or Azure Active Directory.
  • Selecting multiple sets of configurations using SettingSelector.
  • Trim prefixes off key names.
  • Resolving Key Vault References, requires AAD.
  • Secret Resolver, resolve Key Vault References locally without connecting to Key Vault.
  • Json Content Type

Future Features

List of features we are going to add to the Python Provider in the future.

  • Geo-Replication support
  • Feature Management
  • Dynamic Refresh
  • Configuration Placeholders

Examples

Selecting configurations

You can refine or expand the configurations loaded from your store by using SettingSelectors. Setting selectors provide a way to pass a key filter and label filter into the provider.

selects = {SettingSelector(key_filter="*", label_filter="\0"), SettingSelector(key_filter="*", label_filter="dev")}
config = load(endpoint=endpoint, credential=DefaultAzureCredential(), selects=selects)

In this example all configuration with empty label and the dev label are loaded. Because the dev selector is listed last, any configurations from dev take priority over those with (No Label) when duplicates are found.

Trimming Keys

You can trim the prefix off of keys by providing a list of trimmed key prefixes to the provider. For example, if you have the key(s) like /application/message in your configuration store, you could trim /application/ from them.

trim_prefixes={"/application/"}
config = load(endpoint=endpoint, credential=DefaultAzureCredential(), trim_prefixes=trim_prefixes)
print(config["message"])

Resolving Key Vault References

Key Vault References can be resolved by providing credentials to your key vault to the provider using AzureAppConfigurationKeyVaultOptions.

With Credentials

You can provide AzureAppConfigurationKeyVaultOptions with a credential and all key vault references will be resolved with it. The provider will attempt to connect to any key vault referenced with the credential provided.

key_vault_options = AzureAppConfigurationKeyVaultOptions(credential=DefaultAzureCredential())
config = load(endpoint=endpoint, credential=DefaultAzureCredential(), key_vault_options=key_vault_options)

With Clients

You can provide AzureAppConfigurationKeyVaultOptions with a list of SecretClients.

key_vault_options = AzureAppConfigurationKeyVaultOptions(
    client_configs={key_vault_uri: {'credential': credential}})
config = load(endpoint=endpoint, credential=DefaultAzureCredential(), key_vault_options=key_vault_options)

Secret Resolver

If no Credentials or Clients are provided a secret resolver can be used. Secret resolver provides a way to return any value you want to a key vault reference.

def secret_resolver(uri):
    return "From Secret Resolver"

key_vault_options = AzureAppConfigurationKeyVaultOptions(
    secret_resolver=secret_resolver)
config = load(endpoint=endpoint, credential=DefaultAzureCredential(), key_vault_options=key_vault_options)

Key concepts

Troubleshooting

Next steps

Check out our Django and Flask examples to see how to use the provider in a web application.

Django

Flask

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Release History

1.0.0 (2023-03-09)

Breaking Changes

  • Renamed load_provider to load
  • Added AzureAppConfigurationKeyVaultOptions to take in a client_configs a Mapping of endpoints to client kwargs instead of taking in the whole client.
  • Removed AzureAppConfigurationKeyVaultOptions secret_clients, client_configs should be used instead.
  • Made key_filter and label_filter kwargs for Setting Selector
  • Renamed trimmed_key_prefixes to trim_prefixes

Other Changes

  • Made EMPTY_LABEL a constant. i.e. "\0"

1.0.0b2 (2023-02-15)

Features Added

  • Added Async Support
  • Added missing methods for Mapping API
  • Made load method properties unordered.

Breaking Changes

  • Changes how load works. Moves if from AzureAppConfigurationProvider.load to load_provider.
  • Removed custom Key Vault Error
  • Removed unneeded repr and copy methods.
  • All Feature Flags are added to there own key and have there prefix removed

Bugs Fixed

  • Fixed Issue where Key Vault Clients couldn't be set in some situations

Other Changes

  • Updated method docs
  • Fixed load doc that used selector instead of selects.
  • Fixed CLI link in Readme.

1.0.0b1 (2022-10-13)

New Azure App Configuration Provider

Provides additional support above the Azure App Configuration SDK. Enables:

  • Connecting to an Azure App Configuration store
  • Selecting multiple keys using Setting Selector
  • Resolve Key Vault References when supplied AzureAppConfigurationKeyVaultOptions

The Azure App Configuration Provider once loaded returns a dictionary of key/value pairs to use in configuration.

endpoint = "https://<your-store>.azconfig.io"
default_credential = DefaultAzureCredential()
config = AzureAppConfigurationProvider.load(
    endpoint=endpoint, credential=default_credential)
print(config["message"])

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-provider-1.0.0.zip (40.1 kB view details)

Uploaded Source

Built Distribution

File details

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

File metadata

  • Download URL: azure-appconfiguration-provider-1.0.0.zip
  • Upload date:
  • Size: 40.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.28.2 setuptools/58.1.0 requests-toolbelt/0.10.1 tqdm/4.65.0 CPython/3.9.16

File hashes

Hashes for azure-appconfiguration-provider-1.0.0.zip
Algorithm Hash digest
SHA256 c8c7e943798f60eeeeff2c582f9befcf9b20cac1a84823daba7e8fbaaaa3fb9f
MD5 f9d296692d3b6dd1f1eabe9228d9164b
BLAKE2b-256 1b488bcd318783d2ca6cfbc59c047f488642a7f7cd90bff627f05d0a8770d0ae

See more details on using hashes here.

File details

Details for the file azure_appconfiguration_provider-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: azure_appconfiguration_provider-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 15.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.28.2 setuptools/58.1.0 requests-toolbelt/0.10.1 tqdm/4.65.0 CPython/3.9.16

File hashes

Hashes for azure_appconfiguration_provider-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6e8becad0545d3f93341b769bd8b7be38631a72206990b11ed8a228224aed76d
MD5 3cec5ca79def1f5f89652ddb76c2e58a
BLAKE2b-256 e87d1ba550a32a62e46b7eb6fad26abb7a9599d6f45573ff35aaa664d3a5f2a1

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