No Description

gwillz 10dfca5c52 version bump 0.4 2 years ago
autoyaml 822a879dfb added number, underscore, dashes support for yaml keys 2 years ago
tests 822a879dfb added number, underscore, dashes support for yaml keys 2 years ago
.gitignore 0184dd0a16 added gitignore, fix missing path in verify 3 years ago
.gitlab-ci.yml f15a4238cd version bump 0.2 3 years ago
README.md c9a7d6ddab updated readme 2 years ago
requirements.txt e6b9860d32 fix requirements 3 years ago
setup.py 10dfca5c52 version bump 0.4 2 years ago

README.md

AutoYAML

build status coverage report

A thing that neatly loads config files as nested modules.

  • creates the default config file if needed
  • throws KeyError on variations from the default config
  • hides away ugly dicts and excessive configuration
  • read-only access to config properties

Usage

First create a config.py or whatever in your project.

from autoyaml import Config

PATH = 'config/anywhere.yml'
DEFAULTS = {
    'something': {
        'etc': 1234,
        'thing': False
    },
    'more': 'and more',
    'settings': True
}

# shorthand
Config.load_hijack(__name__, PATH, DEFAULTS)

# OR

# the .add() call is useful for inserting configs that are dynamic
Config(DEFAULTS).load_or_create(PATH).add(extra=(1+3)).hijack(globals())

# OR

# to not save/load a config file, useful for testing
Config(DEFAULTS).hijack(globals())

Then use it in your project like so:

from project import config

config.something.etc # => 1234
config.more          # => 'and more'
config.settings      # => True
config.extra         # => 4