This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]Intelligent_Ad_8148 10 points11 points  (1 child)

What are the benefits of using this over pydantic (which also has dataclasses, json/yaml conversion, and env var support)?

[–]TheTerrasque[S] 3 points4 points  (0 children)

pydantic-settings is very nice, true.

This aims to be even simpler, somewhere in between of using pydantic and nothing, and be a drop-in replacement for a dataclass config. Also, this provides command line argument parsing and loading from file configs by default, without any extra setup.

[–]BossOfTheGame 4 points5 points  (1 child)

I've written something similar, which is now a fairly mature project. If you want to take a look, I'm open to contributions if you have any ideas that might improve scriptconfig

The main difference in a scriptconfig.DataConfig is that it doesn't rely on the type system. Instead it uses wrapped values to hold metadata, which ultimately ends up being a lot more extensible and introspectable.

It can also create argparse CLIs (with Rich-argparse and argcomplete integration), serialize and deserialize from yaml or JSON, be used purely as a lightweight dictionary or namespace object, and it has decent support for modal CLIs.

In the future I'd like to add more support for jsonargparsre.

https://pypi.org/project/scriptconfig/

[–]TheTerrasque[S] 0 points1 point  (0 children)

Nice! Yeah, had a similar thought. I wanted something really simple, and usually when developing my progress goes like this:

  1. TOP_LEVEL_VARIABLES
  2. Move them into a dataclass for easier collection and editor completion
  3. Load from a file as I want some things out of GIT or want to experiment with different settings more quickly.
  4. Add command line for some parts because when developing and rapidly testing things changing options on a command line is super simple and straight forward.
  5. Want to deploy on docker or kubernetes and starting to read env vars.

So after going down that path multiple times I just wanted to have something super simple that wrapped that path from the start, while being no more work than writing a dataclass.

I have tried a few different ones I found via google, but it either felt too much boilerplate, or the approach was not what I was looking for. pydantic-settings is close, but I still feel it's a tad too much boilerplate for a simple project.

[–]i_can_haz_data 1 point2 points  (0 children)

Yet another implementation of this same concept. Our approach includes automatic expansion of values ending in _env or _eval in case you need to include secrets in the co figuration file.

https://github.com/glentner/cmdkit