Skip to main content
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/.

Release files for theatro-cfg-loader 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for theatro-cfg-loader 0.3.1
File Size Uploaded
theatro-cfg-loader-0.3.1.tar.gz 17.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for theatro-cfg-loader 0.3.1
File Interpreter ABI Platform
theatro_cfg_loader-0.3.1-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 34.3 kB

Release files / theatro-cfg-loader-0.3.1.tar.gz

Download URL theatro-cfg-loader-0.3.1.tar.gz
Size 17.6 kB
Tags Source
SHA-256 checksum
How to use checksums
49bdd77499b601339a35fb2c4dba683f8ece322ab3ca3f09eb6d240411dc3d51
BLAKE2b-256 checksum
How to use checksums
d36f5779c3fcf043c99d4c9bbbcf4a46dfe5e69417db3989fcd1dd79913be071
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.1

Release files / theatro_cfg_loader-0.3.1-py2.py3-none-any.whl

Download URL theatro_cfg_loader-0.3.1-py2.py3-none-any.whl
Size 16.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
ea7970c91c1a770d0566c3d23fecb5723f5ac3420d8ebfc3d9f6e935e7ddea6f
BLAKE2b-256 checksum
How to use checksums
f046b7a0280ab85fbb06f5e2981d55cf47197ce6d49760b88ff2ebc406d6fbfa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.1

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page