DEV Community

prostomarkeloff
prostomarkeloff

Posted on

 

Python configs for humans.

Hello everybody!

Have you got troubles with configs? I have. And it's problem for me.

I have created simple and awesome library for configs parsing.

You can install it with pip:

pip install betterconf

Simple config:

from betterconf import field, Config

class MyConfig(Config):
    my_var = field("my_var")

cfg = MyConfig()
print(cfg.my_var)

And.. run it!

my_var=1 python our_file.py

Also you can find it at github

Happy coding!

Top comments (8)

Collapse
 
reritom profile image
Tomas Sheers

As a suggestion, it would be useful for you to elaborate when one would use this, and what the problems it solves are.

Currently, If I don't look at the code, I imagine that it is a way of creating static classes to define variables we expect to find in the env, so I would then guess that is a class that wraps the os.environ, so maybe add to try to clarify in the readme.

Also you could state what sort of behaviour would be expected when values aren't found in the env.

Looking at the code, I see your function 'field' just returns a Field class. This seems like it was inspired by the dataclasses module, which is fun because you could then look at adding the 'default' parameter to handle values not found in the env. πŸ™‚

Collapse
 
prostomarkeloff profile image
prostomarkeloff

Thanks! I will add default, it looks good for me.

Collapse
 
ben profile image
Ben Halpern

Great first post, really valuable πŸ™‚

Collapse
 
prostomarkeloff profile image
prostomarkeloff

Thanks!

Collapse
 
ajnasz profile image
Lajos Koszti

Is it something around os.getenv, where you can have default values? Or what is the point?

Collapse
 
prostomarkeloff profile image
prostomarkeloff

Hi! Now - not. You can see on github what i have updated.

Collapse
 
harshanas profile image
Harshana Serasinghe

Great Work :)

Collapse
 
prostomarkeloff profile image
prostomarkeloff

Thanks!

18 Useful Github Repositories Every Developer Should Bookmark

18 Useful GitHub repositories every developer should bookmark: everything from learning resources and roadmaps to best practices, system designs, and tools.