Add the ability to load only a specified list of keys from envvars
See original GitHub issueDescribe the bug
Migrating from other configuration systems I’d need to configure envvar_prefix
to empty string (""
) so I can load any environment variable I used before. But it doesn’t seem to work with dynaconf.
To Reproduce Steps to reproduce the behavior:
- Create a basic dynaconf configuration
In config.py
:
from dynaconf import Dynaconf
settings = Dynaconf(
# This is the important line.
envvar_prefix="",
)
print(settings.FOO)
- Now create some settings file.
In settings.py
:
FOO = 'bar'
- Finally try running.
export SETTINGS_FILE_FOR_DYNACONF=settings
FOO='ham' python config.py
You will get:
bar
Expected behavior
The print output states:
ham
This means the value from environment variable has overridden the default value from settings.py
module
Environment (please complete the following information):
- OS: Ubuntu Linux 20.04
- Python version: 3.8.5
- Dynaconf version: 3.1.2
- Frameworks in use: none.
Additional context Interestingly running in a “hacky” way changes the variable value:
_FOO='ham' python config.py
This is not what I’d expect though. The point is to modify the bare FOO
variable.
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (11 by maintainers)
Top Results From Across the Web
Add the ability to load only a specified list of keys from envvars
I noticed, using envvar_prefix=False causes Dynaconf to load absolutely all environment variables into the result LazySettings , e.g.: PATH / ...
Read more >Environment variables to configure the AWS CLI
Environment variables provide another way to specify configuration options and credentials, and can be useful for scripting or temporarily setting a named ...
Read more >Using Environment Variables | Cloud Functions Documentation
Runtime environment variables are key/value pairs deployed alongside a function. These variables are scoped to the function and are not visible to other ......
Read more >How to Use Environment Variables in VanillaJS
In this article, you will learn about environment variables in Vanilla JavaScript. You'll also learn how to serve API keys to your ...
Read more >Use environment variables in solutions - Power Apps
Environment variables store the parameter keys and values, ... The same is true when selecting SharePoint lists for a given site.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
test case can be added here: https://github.com/rochacbruno/dynaconf/blob/master/tests/test_env_loader.py
and optionally a functional example in the example folder like this one https://github.com/rochacbruno/dynaconf/tree/master/example/envvar_prefix
First you need to add the flag, any new variable on
default_settings.py
named in the patternIGNORE_UNKNOWN_ENVVARS_FOR_DYNACONF
will be a flag in `Dynaconf(…, ignore_unknown_envvars=True)Here:
https://github.com/rochacbruno/dynaconf/blob/master/dynaconf/default_settings.py#L73-L222
Then you can access the variable using
obj.get('IGNORE_UNKNOWN_ENVVARS_FOR_DYNACONF')
here where the envvars are loaded.https://github.com/rochacbruno/dynaconf/blob/master/dynaconf/loaders/env_loader.py#L24-L63