You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While developing a Python module, I noticed that the settings file (e.g. settings.yaml) is not always found (it depends how the module is called, i.e. from the VS debugger or the command line). I could also imagine other situations where the settings file is not found which leaves the application without a proper initialization. This made me wondering if it is possible to have initialized a dynaconf instance without having a settings file (or environment variables), just from within the program to assure that the settings are available (and have some meaningful standard values).
Here's an example of a structure (described as dictionary) that I would like to use:
which doesn't work (I assume the environments are not recognized correctly because settings.prefix is not found).
Second approach: using validators
I see that validators offer the option to specify a default value if the setting doesn't exist. I haven't tried this because I realized that I have no way to specify the environments, so I assume it doesn't work neither (please correct me if I'm wrong).
Third approach: default value
This approach uses the default value when retrieving a key that is not found, e.g.: value = settings.get('prefix', 'vs-')
This would work, but the default values would be spread all over the code.
Any other possibilities?
Feature request
I would like to see the possibility to initialize a dynaconf instance from a dictionary and having file and/or environments variables optionally in addition, e.g.:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
While developing a Python module, I noticed that the settings file (e.g. settings.yaml) is not always found (it depends how the module is called, i.e. from the VS debugger or the command line). I could also imagine other situations where the settings file is not found which leaves the application without a proper initialization. This made me wondering if it is possible to have initialized a dynaconf instance without having a settings file (or environment variables), just from within the program to assure that the settings are available (and have some meaningful standard values).
Here's an example of a structure (described as dictionary) that I would like to use:
As it can be seen from the dictionary, I'd like to use environments.
First approach: Dynaconf instance from dict
I followed the instructions of the Dynaconf instance from dict:
which doesn't work (I assume the environments are not recognized correctly because
settings.prefix
is not found).Second approach: using validators
I see that validators offer the option to specify a default value if the setting doesn't exist. I haven't tried this because I realized that I have no way to specify the environments, so I assume it doesn't work neither (please correct me if I'm wrong).
Third approach: default value
This approach uses the default value when retrieving a key that is not found, e.g.:
value = settings.get('prefix', 'vs-')
This would work, but the default values would be spread all over the code.
Any other possibilities?
Feature request
I would like to see the possibility to initialize a dynaconf instance from a dictionary and having file and/or environments variables optionally in addition, e.g.:
Beta Was this translation helpful? Give feedback.
All reactions