Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Fatal1ty/consul-options
Framework for using Consul as your project options storage
https://github.com/Fatal1ty/consul-options
configuration configuration-management consul consul-kv options options-framework python
Last synced: 13 days ago
JSON representation
Framework for using Consul as your project options storage
- Host: GitHub
- URL: https://github.com/Fatal1ty/consul-options
- Owner: Fatal1ty
- License: apache-2.0
- Created: 2017-02-28T09:22:03.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-11-08T08:11:07.000Z (about 7 years ago)
- Last Synced: 2024-10-25T21:55:50.485Z (19 days ago)
- Topics: configuration, configuration-management, consul, consul-kv, options, options-framework, python
- Language: Python
- Homepage:
- Size: 16.6 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
consul-options - Define and use your project settings without pain
===================================================================.. image:: https://travis-ci.org/Fatal1ty/consul-options.svg?branch=master
:target: https://travis-ci.org/Fatal1ty/consul-options.. image:: https://requires.io/github/Fatal1ty/consul-options/requirements.svg?branch=master
:target: https://requires.io/github/Fatal1ty/consul-options/requirements/?branch=master
:alt: Requirements Status.. image:: https://img.shields.io/pypi/v/consul-options.svg
:target: https://pypi.python.org/pypi/consul-options.. image:: https://img.shields.io/pypi/pyversions/consul-options.svg
:target: https://pypi.python.org/pypi/consul-options/.. image:: https://img.shields.io/badge/License-Apache%202.0-blue.svg
:target: https://opensource.org/licenses/Apache-2.0How often do you wonder where to store the project settings? When your project is small
it is not a big problem. But if your big project consists of dozens of microservices
then there is a problem of centralized configuration management. The Сonsul have a key/value
storage that is ideal for this.With **consul-options** you can define and use options in your code by a simple and elegant way.
Just take a look at the example:.. code-block:: python
class DB(ConsulKV):
passclass Users(DB):
host = '127.0.0.1'
port = 5432
user = 'postgres'
password = 'postgres'dbname = 'users'
class Orders(DB):
host = '127.0.0.1'
port = 5432
user = 'postgres'
password = 'postgres'dbname = 'orders'
Now you can access option values in a clear way:
.. code-block:: python
from consul_options import options
print options.db.users.host
print options.db.orders.dbname**consul-options** automagically creates folders and keys with default values defined above
in Consul and later read them from there. So if anyone will change the value of *db/orders/host* key
to something different in Consul then you will get that value.How project options stored in Consul
------------------------------------When you declare a new class based on **ConsulKV** default bahavior is
creation a *folder* in Consul key/value storage with name of your class in lowercase.
Each class attribute you define will have mapping to key *folder/key*.
If you don't agree with generated folder name you are free to choose any other
with reserved class attribute **__key__** as shown below:.. code-block:: python
class WorkerOptions(ConsulKV):
__key__ = 'worker'host = '127.0.0.1'
port = 80After that you can access to the option with "worker" in path:
.. code-block:: python
from consul_options import options
print options.worker.host
print options.worker.portTo create hierarchical key structure you can take advantage of usual class hierarchy:
.. code-block:: python
from consul_options import ConsulKV, options
class WorkerOptions(ConsulKV):
__key__ = 'worker'host = '127.0.0.1'
port = 80class DB(WorkerOptions):
host = '127.0.0.1'
port = 5432
user = 'postgres'
password = 'postgres'print options.worker.db.host # 'host'
print options.worker.db.port # 5432It is also possible to create keys at root level with class attribute **__root__**:
.. code-block:: python
class RootOptions(ConsulKV):
__root__ = Truehost = '127.0.0.1'
port = 80print options.host
print options.portCompatibility
-------------consul-options is compatible with both Python 2 and Python 3.
Installation
------------Use pip to install::
$ pip install consul-options
License
-------consul-options is developed and distributed under the Apache 2.0 license.