Skip to content

viniciuschiele/central

Repository files navigation

Central

Central is a configuration library for Python inspirited by Netflix Archaius that provides APIs to access and utilize properties that can change dynamically at runtime.

Coverage Travis

Features

  • Read configuration from anywhere (Env variables, File system, web services, S3, ...) using a single interface
  • Auto configuration reload, no longer need to restart your application to fetch new configurations
  • Dynamic properties where the values are of specific types and can change at runtime
  • Composite configurations with ordered hierarchy for applications willing to use convention based configuration locations

Quick Start

Assuming you are using requests library to access an external web service, you may want to change the max number of connections to tune your application, using Central you can do it without having to restart your application.

import requests
import requests.adapters

from central.config.file import FileConfig
from central.property import PropertyManager

config = FileConfig('./config.json').reload_every(600)  # 10 minutes in seconds
config.load()

properties = PropertyManager(config)
pool_maxsize = properties.get_property('pool_maxsize').as_int(5)

adapter = requests.adapters.HTTPAdapter(pool_maxsize=pool_maxsize.get())
session = requests.Session()
session.mount('http://', adapter)


@pool_maxsize.on_updated
def pool_maxsize_updated(value):
    adapter = requests.adapters.HTTPAdapter(pool_maxsize=value)
    session.mount('http://', adapter)


response = session.get('http://date.jsontest.com')

Get It Now

$ pip install central

Requirements

  • Python >= 2.7 or >= 3.4

Central has no external dependencies outside of the Python standard library.

Roadmap

  • Improve documentation
  • Add Cassandra as a configuration
  • Add Redis as a configuration
  • Add Google Datastore as a configuration
  • Add Consul as a configuration
  • Add Couchbase as a configuration
  • Add Aerospike as a configuration
  • Add support for file change detection

License

MIT licensed. See the bundled LICENSE file for more details.