Skip to main content

Aggregates multiple configuration sources into one configuration object with dot-notation or dictionary-like access.

Project description

pipeline status coverage report

What is configstacker?

Configstacker is a python library with the goal to simplify configuration handling as much as possible. You can read configurations from different sources (e.g. files, environment variables and others) and load single or merge multiple sources at will. The resulting configuration object can be used like a dictionary or with dot-notation. If you need additional flexibility configstacker also allows you to specify converters for values or merging strategies for keys that occur multiple times throughout different sources. If this is still not sufficient enough configstacker makes it very easy for you to add additional source handlers.

#
# Single Source Example
#
from configstacker import YAMLFile

config = YAMLFile('/path/to/my/config.yml')

# Dot-notation access
assert config.a_key is True

# Mixed dictionary and dot-notation access
assert config['subsection'].nested_key == 100

# Dictionary-like interface
assert config.keys() == ['a_key', 'subsection']

# Dictionary dumping on any level
assert config.dump() == {'a_key': True, 'subsection': {'nested_key': 100}}
assert config.subsection.dump() == {'nested_key': 100}

# New value assignment
config.new_value = 10.0
assert config.new_value == 10.0
#
# Multi Source Example
#
import configstacker as cs

# The resulting configuration object behaves
# the same as a single source one.
config = cs.StackedConfig(
    # The order of sources defines their search priority whereas the
    # last element has the highest one.
    cs.Environment(prefix='MYAPP'),
    cs.YAMLFile('/path/to/my/config.yml')
)

# Higher priority values shadow lower priority values.
assert config.a_key is False

# Lower prioritized values which are not shadowed stay accessible.
assert config['subsection'].nested_key == 100

# New values will be added to the source that has the highest
# priority and is writable.
config.other_new_value = True
assert config.other_new_value is True

# In this case the new item was added to the last element in the
# source list.
assert config.source_list[-1].other_new_value

Examples for type conversion and merging strategies can be found in the documentation.

Latest Version and History

Configstacker adheres to Semantic Versioning.

The current version is 0.2.0 which means configstacker is still in a planning phase. As such it is not meant for production use. That said it is already very stable and should hit its first major version soon.

Changes can be found in CHANGELOG.

Installation

Configstacker can be installed with pip and only requires six for the minimal installation.

pip install configstacker

However, some of the source handlers require additional packages when in use.

You can use the following syntax to install all optional dependencies. Leave out those from the brackets you do not need.

pip install configstacker[yaml]

Documentation

Configstacker provides a user documentation on readthedocs.org.

Licensing

Please see LICENSE.

Contribution

Contributions are very welcome. The main development happens on gitlab. For reporting issues you can also use github.

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

configstacker-0.2.0.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

configstacker-0.2.0-py3-none-any.whl (22.4 kB view details)

Uploaded Python 3

File details

Details for the file configstacker-0.2.0.tar.gz.

File metadata

  • Download URL: configstacker-0.2.0.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.8

File hashes

Hashes for configstacker-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d11b48f0d772a36d43e99ae637fc2838b4de4fe0a952626e55dc9eee4c3096c8
MD5 182b0f6046c3c08fe904d5e1b4523f8f
BLAKE2b-256 e35b84d993eb3ab2bb75c83d0f19b851800bcc748756d3973c4b47af2af557db

See more details on using hashes here.

File details

Details for the file configstacker-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: configstacker-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 22.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.8

File hashes

Hashes for configstacker-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f5e6057b9f7e536f174b4a47830354d51590667eba3b1fed0fec4186093f91df
MD5 7118a720fe7ad48aa19d661f0cd1295d
BLAKE2b-256 4bf371de320decad728cbc3bccd265a9e32571129f1999b6047a67e2dea1fe1a

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