4 ms·
Marshmallow. You can use its schema validation for any dict/json, which makes it a nice fit for validating json config files (which mitigates some of the json c
by ungawatkt 6y ago
Marshmallow. You can use its schema validation for any dict/json, which makes it a nice fit for validating json config files (which mitigates some of the json concerns from the article). Just immediately move the json.reads through a schema validate, build some classes around it for different config files.
marshmallow.readthedocs.io/en/
- mianos 6y agoI use a similar library called Schema at https://pypi.org/project/schema/ https://pypi.org/project/schema/ I love the expressive nature of it. Just this week I was validating both yaml and json configuration data with it. One thing missing from this article is to always use a proper external key value store for everything but the stage (dev test prod etc) and the connections to the kv store. Config files on disk and even in environment variables suck for anything but the most trivial platforms.
- albi_lander 6y agodataclass_json is also very useful for schema validation. It combines python's native dataclass objects with marshmallow's schema to provide additional functionalities simply through a @dataclass_json decorator on your dataclass. https://lidatong.github.io/dataclasses-json/ https://lidatong.github.io/dataclasses-json/
- madman_bob 6y agoI made the similar dataclasses_serialization library. It doesn't require a special decorator on your classes, and is extensible for custom classes, and custom serialization methods (JSON and BSON provided by default). https://github.com/madman-bob/python-dataclasses-serialization https://github.com/madman-bob/python-dataclasses-serializati...
- mands 6y agoI do something similar with dataclasses using the `dacite` (https://github.com/konradhalas/dacite https://github.com/konradhalas/dacite) library as a constructor for python dicts to dataclasses with runtime type-checking. Works really well with marshmallow for additional validation.