Re:Best Practices for Working with Configuration in Python A...
by ungawatkt on Friday April 24, 2020 @04:41AM
(#22965882)
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/
Re:Best Practices for Working with Configuration in Python A...
by mianos on Friday April 24, 2020 @08:31AM
(#22967246)
I use a similar library called Schema at 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.
Re:Best Practices for Working with Configuration in Python A...
by albi_lander on Friday April 24, 2020 @08:45AM
(#22967352)
dataclass_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.
Re:Best Practices for Working with Configuration in Python A...
by madman_bob on Friday April 24, 2020 @10:29AM
(#22968281)
I 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-serializati...
Re:Best Practices for Working with Configuration in Python A...
by mands on Friday April 24, 2020 @12:06PM
(#22969543)
I do something similar with dataclasses using the `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.
Re:Best Practices for Working with Configuration in Python A...
by sandGorgon on Friday April 24, 2020 @06:10AM
(#22966417)
Yes. Fastapi also uses the same - https://fastapi.tiangolo.com/advanced/settings/#pydantic-set...
Re:Best Practices for Working with Configuration in Python A...
by andyljones on Friday April 24, 2020 @04:36AM
(#22965856)
The two big ones in machine learning at least are Google's Gin:
https://github.com/google/gin-config
and Facebook's Hydra:
Re:Best Practices for Working with Configuration in Python A...
by kyawzazaw on Friday April 24, 2020 @10:56AM
(#22968616)
the name usage of "gin" is quite common, it seems:
Re:Best Practices for Working with Configuration in Python A...
by rb808 on Friday April 24, 2020 @04:41PM
(#22972701)
This and the list of other libraries in responses is a great reason to avoid Python. Its nearly as bad as Javascript, how are you supposed to live with this.
Re:Best Practices for Working with Configuration in Python A...
by krut-patel on Friday April 24, 2020 @01:26PM
(#22970676)
There's also confuse[0], used by beets. I've found it to be a good way to handle configuration when the end-user is not a programmer.
Re:Best Practices for Working with Configuration in Python A...
by lsorber on Friday April 24, 2020 @09:03AM
(#22967488)
Dynaconf [1], though I think this article's approach in combination with pydantic is better.
Re:Best Practices for Working with Configuration in Python A...
by pydry on Friday April 24, 2020 @05:41AM
(#22966257)
https://github.com/crdoconnor/strictyaml - typesafe YAML parser (solves the issues mentioned in 2 and 1).
Re:Best Practices for Working with Configuration in Python A...
by BerislavLopac on Friday April 24, 2020 @04:57AM
(#22966020)
Here's my tiny contribution to the field: https://github.com/berislavlopac/figga
Re:Best Practices for Working with Configuration in Python A...
by BerislavLopac on Friday April 24, 2020 @04:59AM
(#22966025)
And I also like the .env approach: https://github.com/theskumar/python-dotenv
Re:Best Practices for Working with Configuration in Python A...
by macintux on Friday April 24, 2020 @10:39AM
(#22968417)
Cerberus for schema validation.
Re:Best Practices for Working with Configuration in Python A...
by rochacbruno on Wednesday April 29, 2020 @10:16AM
(#23019498)
- Python application configuration -> https://github.com/edaniszewski/bison
- Configuration with env variables for Python -> https://github.com/hynek/environ_config
- Configuration library for python projects -> https://github.com/willkg/everett
- Strict separation of config from code -> https://github.com/henriquebastos/python-decouple
This is from my personal notes. See also: https://github.com/vinta/awesome-python#configuration
Anything else that we've missed ?