A library that allows to easily load configuration settings.
Project description
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
:alt: Build Status
.. image:: https://codecov.io/gh/nmvalera/cfg-loader/branch/master/graph/badge.svg
:target: https://codecov.io/gh/nmvalera/cfg-loader
:alt: Coverage
.. image:: https://readthedocs.org/projects/cfg-loader/badge/?version=stable
:target: https://cfg-loader.readthedocs.io/en/stable/?badge=stable
:alt: 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
~~~~~~~~~~~~~
- 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
Documentation
~~~~~~~~~~~~~
Full documentation is available at https://cfg-loader.readthedocs.io/en/stable/.
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
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
:alt: Build Status
.. image:: https://codecov.io/gh/nmvalera/cfg-loader/branch/master/graph/badge.svg
:target: https://codecov.io/gh/nmvalera/cfg-loader
:alt: Coverage
.. image:: https://readthedocs.org/projects/cfg-loader/badge/?version=stable
:target: https://cfg-loader.readthedocs.io/en/stable/?badge=stable
:alt: 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
~~~~~~~~~~~~~
- 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
Documentation
~~~~~~~~~~~~~
Full documentation is available at https://cfg-loader.readthedocs.io/en/stable/.
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
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
Cfg-Loader-0.2.2.tar.gz
(18.4 kB
view details)
Built Distribution
File details
Details for the file Cfg-Loader-0.2.2.tar.gz
.
File metadata
- Download URL: Cfg-Loader-0.2.2.tar.gz
- Upload date:
- Size: 18.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3fd2c7e73d5523e2682d8bb42202e670018e7563af043f2a9f8a74d9a03f8101 |
|
MD5 | 1c960d7817a3745126341913ae5ace28 |
|
BLAKE2b-256 | d3d81232d76cec8824f165fda7616b7de430e2825c7822cf054c1b815611fc89 |
File details
Details for the file Cfg_Loader-0.2.2-py2.py3-none-any.whl
.
File metadata
- Download URL: Cfg_Loader-0.2.2-py2.py3-none-any.whl
- Upload date:
- Size: 16.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5be16d5fa89a9839503b2c4470039f4224f8d01a85f4679d51cec6eb1877237 |
|
MD5 | 62c4943cefa3631267c15b86fcbc5d7c |
|
BLAKE2b-256 | 2252466daa9fa1c29c3234c00682033091f43125c738f9236159427a9a7c6f9a |