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 ofnr.types 2.5.0
)
v1.2.2 (2019-06-05)
- Fix Python 2 compatible
super()
call inField
constructor
v1.2.1 (2019-05-21)
- Add
Partial._from_config()
- Fix handling of
Field.config_name
in thePartial
constructor and thePartialTypeHandler.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 toextract()
method - Add
bool
class to be handled by theGenericTypeHandler
-
Context.key
is not aKey
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 aRuntimeError
instead ofNotImplementedError
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()
innr.config.extract()
if possible - Use
OrderedDict
withjson.load()
v1.0.1 (2019-03-21)
- Fix Python 3 compatibility in GenericTypeHandler
v1.0.0 (2019-03-21)
- Initial version