Skip to main content

Combine multiple configuration sources to a single configuration object.

Project description

merge-conf

A configuration aggregator for multiple configuration sources.

Using this library, it is easy to combine multiple configuration or settings sources. The following items can be combined:

  • a fixed object with default settings
  • command-line arguments
  • environment variables
  • configuration files like
    • .env files
    • python files
    • ConfigParser style ini files
    • toml files
    • yaml files
    • json files

The basic entry point is the so called MultiConfigurationSource. It can be initialized with an optional, existing configuration object. Multiple ConfigurationSource objects can be added. These objects will be traversed in order of insertion. Each of these instances create a dictionary of configuration entries that will be used to extend or override the previous ones. The resulting object can be received using the read_configuration method.

Example

import merge_conf

config = None # Create existing object
arguments = None # Argument parser result namespace

source = merge_conf.MultiConfigurationSource(config)
source.add(merge_conf.ConfigFileConfigurationSource(
    # Configuration file path
))
source.add(merge_conf.EnvironmentVariableSource("MY_APP"))
source.add(merge_conf.ArgParseSource(arguments))

config = source.read_configuration()

In this example, the configuration object will be created first. Then, the configuration file will be created. Afterwards, all environment variables starting with MY_APP_ will be used for configuration. The final configuration item will be fetched from the argparse module.

The trick is to created the configuration namespaces with a little sure instinct, so that items can be overridden.

Installing

The package can be installed using pip. Most support comes out of the box, but for the following features an extra must be activated:

.env file support (dotenv) yaml file support (yaml) toml file support (toml)

Licensing

This library is published under BSD-3-Clause license.

Versioning

This library follows semantic versioning 2.0. Any breaking change will produce a new major release. Versions below 1.0 are considered to have a unstable interface.

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

merge-conf-0.9.0.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

merge_conf-0.9.0-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

Details for the file merge-conf-0.9.0.tar.gz.

File metadata

  • Download URL: merge-conf-0.9.0.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1

File hashes

Hashes for merge-conf-0.9.0.tar.gz
Algorithm Hash digest
SHA256 fb5d1e7609b7ed649dbb45188d4cc56f503da6e47f66e22110cd296cf59c9a4a
MD5 a3609aa0244b09f344908148bd273e8f
BLAKE2b-256 52d687eaab1bd6545f4d059e9f61431b341a8989e98ff2d701bb5d8bde2befb8

See more details on using hashes here.

File details

Details for the file merge_conf-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: merge_conf-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 18.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1

File hashes

Hashes for merge_conf-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7655f433085aea638684251922d95ba9f3a5ef088b51d9de5ab3803a6c7115c8
MD5 a764e4a5159407f1be34e9f055b4d541
BLAKE2b-256 10fd3616ef58087c821497463f46c767103adc79f99dd9a95bd8e5abd8217eb3

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