Utility library to implement composable YAML configuration files.


License
MIT
Install
pip install nr.config==0.2.0

Documentation

Deprecated. Use the nr.types.structured module instead.


nr.config

The nr.config package provides an API to define models to parse JSON/CSON/YAML configuration files.

from nr.config import Field, Partial, extract, dump

class User(Partial):
  name = Field(str)
  realm = Field(str)

class AuthConfig(Partial):
  authorized_users = Field((list, User), name='authorized-users')

data = {'authorized-users': [{'name': 'me', 'realm': 'sso'}]}
config = extract(AuthConfig, data)
print(config.authorized_users[0].name)
assert dump(AuthConfig, config) == data

Changelog

v1.2.3 (2019-07-20)

  • Deprecated. Use nr.types.structured instead (available as of nr.types 2.5.0)

v1.2.2 (2019-06-05)

  • Fix Python 2 compatible super() call in Field constructor

v1.2.1 (2019-05-21)

  • Add Partial._from_config()
  • Fix handling of Field.config_name in the Partial constructor and the PartialTypeHandler.load() method

v1.2.0 (2019-05-21)

  • Add Key class that can be used to track the location of an element in a nested structure
  • Add key argument to extract() method
  • Add bool class to be handled by the GenericTypeHandler
  • Context.key is not a Key instance and is no longer protected by a setter method
  • Setting Context.key is no longer supported

v1.1.0 (2019-04-16)

  • Update nr.types dependency to >=2.0.1
  • Removed nr.stream dependency
  • Field.get_default() now raises a RuntimeError instead of NotImplementedError if the field has no default value

v1.0.3 (2019-04-06)

  • extract() now accepts an optional kwargs parameter that overrides the top-level values of the input data
  • add Partial.as_dict()

v1.0.2 (2019-03-21)

  • Add nr.types>=1.1.0 dependency
  • Use yaml.safe_load() in nr.config.extract() if possible
  • Use OrderedDict with json.load()

v1.0.1 (2019-03-21)

  • Fix Python 3 compatibility in GenericTypeHandler

v1.0.0 (2019-03-21)

  • Initial version