Skip to main content
Some rights reserved.

Redistribution and use in source and binary forms of the software as well
as documentation, with or without modification, are permitted provided
that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* Neither the name of Config-Loader nor the names of the contributors may not be used to endorse or
promote products derived from this software without specific
prior written permission.

THIS SOFTWARE AND DOCUMENTATION IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE AND DOCUMENTATION, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
Description: .. image:: https://travis-ci.org/nmvalera/cfg-loader.svg?branch=master
:target: https://travis-ci.org/nmvalera/cfg-loader#

.. image:: https://codecov.io/gh/nicolas-maurice/cfg-loader/branch/master/graph/badge.svg
:target: https://codecov.io/gh/nmvalera/cfg-loader

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
~~~~~~~~~~~~~

- input data validation and automatic processing using `marshmallow`_
- substitution of environment variables in input data (following `docker compose variable substitution syntax`_)
- configuration loading from .yaml file

.. _`marshmallow`: https://github.com/marshmallow-code/marshmallow
.. _`docker compose variable substitution syntax`: https://docs.docker.com/compose/compose-file/#variable-substitution

Requirements
------------

- Python>=3.5

A simple example
----------------

.. code-block:: python

>>> 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

Platform: any
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Provides-Extra: dev
Provides-Extra: doc

Metadata

Release files for Cfg-Loader 0.1.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 Cfg-Loader 0.1.1
File Size Uploaded
Cfg-Loader-0.1.1.tar.gz 17.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Cfg-Loader 0.1.1
File Interpreter ABI Platform
Cfg_Loader-0.1.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 33.2 kB

Release files / Cfg-Loader-0.1.1.tar.gz

Download URL Cfg-Loader-0.1.1.tar.gz
Size 17.5 kB
Tags Source
SHA-256 checksum
How to use checksums
0a7d709706d0b3be4c566ba62b87603f3bc44d5118b2d2d7968a486298d54519
BLAKE2b-256 checksum
How to use checksums
9e4bc8f11bc4eb619e259e59d93338f3e0dfe82912519c2aba9bd7b44513f1e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / Cfg_Loader-0.1.1-py2.py3-none-any.whl

Download URL Cfg_Loader-0.1.1-py2.py3-none-any.whl
Size 15.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
e195b815d2504d3f02aa4d17606a7821355b02f034e0732189e9e6b1315474ed
BLAKE2b-256 checksum
How to use checksums
aae1f72e13cb1566d53224ce48eea4b307eb76ef6dead6bf4865a81b13a2531e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.2.2

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

This release

0.1.1 This release

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