Simple DictObject config from YAML

Requirements

pip install DictObject

Source

yamlconfig.py:

import yaml
from DictObject import DictObject

class YamlConfig(DictObject):
    def __init__(self, yamlfile):
        with open(yamlfile) as fp:
            parsed_config = yaml.load(fp)
            super(YamlConfig, self).__init__(parsed_config)

Usage

config.yml:

title: 'Example'
branch:
  leaf: 'green'

example.py:

from yamlconfig import YamlConfig

config = YamlConfig('config.yml')

print config.title  # Example
print config.branch.leaf  # green