https://github.com/paylogic/settei
Config system which based on setuptools' entry points.
https://github.com/paylogic/settei
Last synced: about 1 year ago
JSON representation
Config system which based on setuptools' entry points.
- Host: GitHub
- URL: https://github.com/paylogic/settei
- Owner: paylogic
- License: mit
- Archived: true
- Created: 2013-12-13T12:25:53.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2014-06-28T20:50:32.000Z (almost 12 years ago)
- Last Synced: 2025-02-21T21:38:09.544Z (over 1 year ago)
- Language: Python
- Size: 282 KB
- Stars: 1
- Watchers: 20
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGES.rst
- License: LICENSE.txt
Awesome Lists containing this project
README
Settei: Config system which bases on entry points of setuptools
===============================================================
The ``settei`` package is a library which gives you possibility to get config settings from entry points for
specific application and environment.
Generic purpose python settings library which uses entry points as a registry.
Introduces terms ``application`` and ``environment``:
- ``application`` is part of group's name in which you are storing entry points
- ``environment`` is name of entry point
.. image:: https://api.travis-ci.org/paylogic/settei.png
:target: https://travis-ci.org/paylogic/settei
.. image:: https://pypip.in/v/settei/badge.png
:target: https://crate.io/packages/settei/
.. image:: https://coveralls.io/repos/paylogic/settei/badge.png?branch=master
:target: https://coveralls.io/r/paylogic/settei
Installation
------------
.. sourcecode::
pip install settei
Usage
-----
First of all you need to create entry points and put them into group, group comprises from two parts first of them is prefix
``settings_`` and second one is name of your application, e.g. ``settings_backoffice`` or ``settings_frontoffice``
where ``backoffice`` or ``frontoffice`` is your application.
.. code-block:: python
# in your setup.py
setup (
# ...
entry_points = {
'settings_frontoffice': [
'default = path.to.package.of.frontoffice.default_settings:generate_config',
'local= path.to.package.of.frontoffice.local_settings:generate_config',
],
'settings_backoffice': [
'default = path.to.package.of.backoffice.default_settings:generate_config',
'local= path.to.package.of.backoffice.local_settings:generate_config',
]
}
# ...
)
The ``generate_config`` function should return instance of ``settei.config.Config`` class.
.. code-block:: python
# default_settings.py
from settei.config import Config
def generate_config():
config = Config()
# adding some settings
config['QUESTION'] = 'The Ultimate Question of Life, the Universe, and Everything'
config['ANSWER'] = 41
# or loading them from object
config.from_pyfile('full/path/to/file.py')
# or from object
config.from_object('path.to.object')
return config
You can also do inheriting one settings by others but only inside group of entry points, e.g if you want to inherit
default settings by local settings you just should mention name of entry point which you want to inherit
.. code-block:: python
# in your local_settings.py file
def generate_config(default):
# changing settings, the right answer is 42
default['ANSWER'] = 42
return default
And if in your code you will get local settings and check them
.. code-block:: python
>> from settei import get_config
>> config = get_config('frontoffice', 'local')
>> print config['QUESTION']
The Ultimate Question of Life, the Universe, and Everything
>> print config['ANSWER']
42
Then you will need to install your package and after it with ``settei`` you will be able to get config settings for your
application.
.. code-block:: python
from settei import get_config
# get config settings for frontoffice application and local environment
config = get_config('frontoffice', 'local')
# get config settings for backoffice application and local environment
config = get_config('backoffice', 'local')
# now you can use it as you want
DEBUG = config['DEBUG']
.. code-block:: bash
# you can also get environment from CONFIG_ENVIRONMENT
# just run your script/application in this way
$ env CONFIG_ENVIRONMENT='dev' python my_incredible_script.py
.. code-block:: python
# and in script you can use get_config like
from settei import get_config
# get config settings for frontoffice application and dev environment because we have already specified environment
config = get_config('frontoffice')
Contact
-------
If you have questions, bug reports, suggestions, etc. please create an issue on
the `GitHub project page `_.
License
-------
This software is licensed under the `MIT license `_
See ``_
© 2013 Paylogic International.