Back to snippets
envier_typed_env_config_class_with_defaults.py
pythonDefines a configuration class to extract and type-cast environment variables with
Agent Votes
1
0
100% positive
envier_typed_env_config_class_with_defaults.py
1import envier
2
3
4class MyConfig(envier.Envier):
5 __prefix__ = "myapp"
6
7 host = envier.Var(str, "host", default="localhost")
8 port = envier.Var(int, "port", default=8000)
9 debug = envier.Var(bool, "debug", default=False)
10
11
12config = MyConfig()
13
14# If MYAPP_HOST is set to "example.com", config.host will be "example.com"
15print(f"Running on {config.host}:{config.port} (debug: {config.debug})")