Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ramonhagenaars/conf
A *very* simple and *lightweight* configuration loader and parser for Python.
https://github.com/ramonhagenaars/conf
config configurable configuration configuration-file configuration-loader configuration-parser python
Last synced: 3 months ago
JSON representation
A *very* simple and *lightweight* configuration loader and parser for Python.
- Host: GitHub
- URL: https://github.com/ramonhagenaars/conf
- Owner: ramonhagenaars
- License: mit
- Created: 2018-12-18T21:26:30.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-08-15T14:30:09.000Z (over 5 years ago)
- Last Synced: 2024-09-26T12:16:10.821Z (4 months ago)
- Topics: config, configurable, configuration, configuration-file, configuration-loader, configuration-parser, python
- Language: Python
- Homepage:
- Size: 20.5 KB
- Stars: 3
- Watchers: 1
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.rst
- Changelog: HISTORY.rst
- License: LICENSE
Awesome Lists containing this project
README
|PyPI version| |Build Status|
conf
====A *very* simple and *lightweight* configuration loader and parser for Python.
Supports:
- ini files (``*.ini``)
- json files (``*.json``)
- yaml files (``*.yml``, ``*.yaml``)Installation
''''''''''''Bare installation:
::pip install conf
Installation with support for YAML:
::pip install "conf[yaml]"
Usage
'''''Starting your app
"""""""""""""""""Start your app with your configuration file:
::
python your_app.py --config your_config.yml
Or:
::
python your_app.py --config config_env_var
The ``--config`` argument can be:
- a relative path to a file;
- an absolute path to a file;
- the name of an environment variable which value holds one of the above.You are allowed to provide multiple configuration names (separated by a single space), in which case any setting of a former
configuration file can be overwritten by a setting of a later configuration file (if the name of that setting is identical).Once you have supplied your application with some configuration, you can fetch the settings of that configuration. There are
three options of how to do that.Fetching your setting (option 1)
""""""""""""""""""""""""""""""""Simply get your setting from the ``conf`` module:
.. code:: python
import conf
your_setting = conf.your_settingFetching your setting (option 2)
""""""""""""""""""""""""""""""""
Import your setting directly:.. code:: python
from conf import your_setting
Fetching your setting (option 3)
""""""""""""""""""""""""""""""""
You can provide a default value if you are not sure the setting will be present:.. code:: python
import conf
your_setting = conf.get('your_setting', 'your default value')Note: If you use an ArgumentParser in your own application for other purposes, you must use the ``parse_known_args()`` method of the parser.
Fetching your setting (option 4)
""""""""""""""""""""""""""""""""
You can get the configuration as a dictionary and get your setting as you would get any value from a ``dict``:.. code:: python
import conf
conf_dict = conf.asdict()
your_setting = conf_dict.get('your_setting', 'your default value')Meta
''''
This lib was designed and written in 2018 by `finetuned89 `_ and `ramonhagenaars `_... |PyPI version| image:: https://badge.fury.io/py/conf.svg
:target: https://badge.fury.io/py/conf.. |Build Status| image:: https://api.travis-ci.org/ramonhagenaars/conf.svg?branch=master
:target: https://travis-ci.org/ramonhagenaars/conf