Skip to main content

easy to define and reference config options

Project description

Introduction

econf make it easy to define config options and reference them. The options can be provided through command line or config file.

Install

$ pip install http://github.com/wangst321/econf.git

How to Use

define options

First, import econf

from econf import *

For default options, that belong to ‘default’ section:

from econf import BaseConf

class DefaultConf(BaseConf):
    host = StrOpt(default='0.0.0.0', cmdline=True,
                  help='ip address')
    port = IntOpt(default=9090, cmdline=True,
                  help='tcp port')

For options belong to other section:

class ZKConf(BaseConf):
    __section__ = 'zk'

    hosts = StrOpt(
        required=True,
        help='list of zookeeper ip:port pair. i.e. localhost:2181')
    max_retry = IntOpt(
        default=3,
        help='number of tries before giving up connecting')

use options in your code

There are two ways to reference an option. First, use the specific Conf Class:

host, port = DefaultConf.host, DefaultConf.port

Second, use the general CONF:

host, port = CONF.host, CONF.port
zk_hosts = CONF.zk.hosts

parse cli options and config file

If a default config is supplied:

from econf import CONF
CONF('path/to/your/default.conf')

or,

from econf import CONF
CONF()

Usually, this code is executed just before your service gonna start.

def run():
    from econf import CONF
    CONF()

    my_service.init(CONF.host, CONF.port, ...)
    my_service.start()

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

econf-0.1.4.tar.gz (5.4 kB view details)

Uploaded Source

File details

Details for the file econf-0.1.4.tar.gz.

File metadata

  • Download URL: econf-0.1.4.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for econf-0.1.4.tar.gz
Algorithm Hash digest
SHA256 b2f06b914b98a3925d1afa6d3575685a27551615df7e7abc01bf9d09e3a62217
MD5 1be919bbf8e0cf59470d2d21bf7959e5
BLAKE2b-256 0e5eedd22686937a67c504442e0f2dde16565238b5d198e15ba7738ecee80f41

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page