DEV Community

prostomarkeloff
prostomarkeloff

Posted on

11 7

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!

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more