Skip to main content

A library that allows to easily load configuration settings.

Project description

Build Status Coverage Documentation Status

Cfg-Loader

Cfg-Loader is a library that allows to easily load configuration settings. It uses marshmallow to deserialize input data into a target format configuration data.

Main features

Requirements

Python>=3.6

A simple example

>>> from cfg_loader import ConfigSchema, BaseConfigLoader
>>> from marshmallow import fields

# Declare your configuration schema
>>> class MyConfigSchema(ConfigSchema):
...     setting1 = fields.Str()
...     setting2 = fields.Int(required=True)
...     setting3 = fields.Float(missing=13.2)

# Declare mapping to substitute environment variable
>>> substitution_mapping = {'FILE_PATH': 'file'}

# Initialize config loader
>>> my_config_loader = BaseConfigLoader(MyConfigSchema, substitution_mapping=substitution_mapping)

# Load configuration
>>> config = my_config_loader.load({'setting1': '/home/folder/${FILE_PATH?:file path required}', 'setting2': '4'})
>>> config == {'setting1': '/home/folder/file', 'setting2': 4, 'setting3': 13.2}
True

# Invalid input data
>>> my_config_loader.load({'setting1': '/home/folder/${FILE_PATH?:file path required}', 'setting3': 13.4})
Traceback (most recent call last):
...
cfg_loader.exceptions.ValidationError: {'setting2': ['Missing data for required field.']}

>>> my_config_loader.load({'setting2': 12, 'setting3': 'string'})
Traceback (most recent call last):
...
cfg_loader.exceptions.ValidationError: {'setting3': ['Not a valid number.']}

# Variable substitution invalid
>>> my_config_loader.load({'setting2': '${UNSET_VARIABLE?Variable "UNSET_VARIABLE" required}'})
Traceback (most recent call last):
...
cfg_loader.exceptions.UnsetRequiredSubstitution: Variable "UNSET_VARIABLE" required

Documentation

Full documentation is available at https://cfg-loader.readthedocs.io/en/stable/.

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

theatro-cfg-loader-0.3.0.dev0.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

theatro_cfg_loader-0.3.0.dev0-py2.py3-none-any.whl (16.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file theatro-cfg-loader-0.3.0.dev0.tar.gz.

File metadata

  • Download URL: theatro-cfg-loader-0.3.0.dev0.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.4

File hashes

Hashes for theatro-cfg-loader-0.3.0.dev0.tar.gz
Algorithm Hash digest
SHA256 6100e0f2d258d635ab5a7962cea955224d750b51f0e1b9166b3142bd921cb939
MD5 c7c2c6ed57542c5059b96f44425a4099
BLAKE2b-256 9f2a9e1faaec9cbe76c6b6bc3b4b25f39f7c8aff864a9d43d01c7d1e7f19d550

See more details on using hashes here.

File details

Details for the file theatro_cfg_loader-0.3.0.dev0-py2.py3-none-any.whl.

File metadata

  • Download URL: theatro_cfg_loader-0.3.0.dev0-py2.py3-none-any.whl
  • Upload date:
  • Size: 16.7 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/40.8.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.4

File hashes

Hashes for theatro_cfg_loader-0.3.0.dev0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d3fd5a568b00e2f8fe87ac9bc023e857f595d4f18e1eaae5f7af00bf9efeb2db
MD5 4a2383dce10b26ac99a6b4a45a02aa68
BLAKE2b-256 e267760a82fcf34e0884351bb3436d99b4bcdfc89d84ea4918ca6d5ae19b10d1

See more details on using hashes here.

Supported by

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