Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

read configuration files, conf.d style

Project Description

read configuration files, conf.d style

Requirements

  • Python 2.6+

Installation

Using PIP:

From Github:

pip install git+git://github.com/josegonzalez/conf_d.git#egg=conf_d

From PyPI:

pip install conf_d==0.0.3

Usage

usage:

# in your /etc/derp/conf file
[derp]
no: sleep
til: brooklyn

[herp]
sleep: 1
wait: 5.0
timeout: seventy

# From your fictional derp module
from conf_d import Configuration

def digitize(config):
    for key in config:
        if not config[key].isdigit():
            try:
                config[key] = float(config[key])
            except ValueError:
                pass
        else:
            try:
                config[key] = int(config[key])
            except ValueError:
                pass

        return config

# All defaults must be strings
conf = Configuration(
    name="derp",
    path="/etc/derp/conf",
    main_defaults={
        "no": "one",
        "expected": "the spanish inquisition",
        "cats": "1",
    },
    section_parser=digitize
)

what_not_to_do = conf.get(section='derp', key='no', default="jumping")
# "sleep"

until_when = conf.get(section='derp', key='til')
# "brooklyn"

cats = conf.get(section='derp', key='cats')
# "1"

dogs = conf.get(section='derp', key='dogs')
# None

sleep = conf.get(section='herp', key='sleep')
# 1

wait = conf.get(section='herp', key='wait')
# 5.0

timeout = conf.get(section='herp', key='timeout')
# "seventy"

section_exists = conf.has(section='derp')
# True

section_exists = conf.has(section='derp', key='no')
# True

raw_data = conf.raw()
# {
#    'sections': {
#       'herp': {
#          'sleep': 1,
#          'wait': 5.0,
#          'timeout': 'seventy'
#       }
#    },
#    'derp': {
#       'expected': 'the spanish inquisition',
#       'til': 'brooklyn',
#       'cats': '1',
#       'no': 'sleep'
#    }
# }

Changelog

0.0.4 (2013-11-19)

  • Allow passing in a custom config parser

0.0.3 (2013-05-22)

  • Allow overriding the confd_path from an entry in the main config

0.0.2 (2013-04-18)

  • Fix issue where main section was not always created

0.0.1 (2013-04-13)

  • Initial commit
Release History

Release History

This version
History Node

0.0.4

History Node

0.0.3

History Node

0.0.2

History Node

0.0.1

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
conf_d-0.0.4.tar.gz (4.3 kB) Copy SHA256 Checksum SHA256 Source Dec 13, 2013

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting