Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configuration from environment variables #10

Open
thejohnfreeman opened this issue Mar 28, 2015 · 5 comments
Open

configuration from environment variables #10

thejohnfreeman opened this issue Mar 28, 2015 · 5 comments

Comments

@thejohnfreeman
Copy link
Collaborator

There should be a function to generate a configuration from environment variables. Overriding configuration in the environment is handy for

  • scripts that cannot create a configuration file (or cannot edit an existing one) and cannot change the command line, and
  • modules that want to read configuration but do not control sys.argv (e.g. logging and security modules).

I believe Confit already supports an optional environment variable naming a configuration path. That's good, but I'd extend it to be a colon-separated path (like PATH, CLASSPATH, or PYTHONPATH) of configurations to load in order.

@sampsyo
Copy link
Member

sampsyo commented Mar 29, 2015

Sounds good!

@thejohnfreeman
Copy link
Collaborator Author

One important caveat is that most shells have a limited character set for environment variable names. Usually the OS will support all non null characters, but shells will only support letters, numbers, and underscores. I think that will translate to only allowing overrides of variables with "well behaved names".

@neumond
Copy link

neumond commented Mar 13, 2018

That should be easy to implement yourself due to good code design of confuse. You can combine layers of data gathered from different sources.

from confuse import RootView, ConfigSource
c = RootView([])
# Higher priority first
c.add(ConfigSource.of({
    'corn': 300,
    'potato': 200,
    'berries': ['blue', 'red'],
    'map': {
        'x': 3,
        'y': 4,
    }
}))
# Lower priority last
c.add(ConfigSource.of({
    'banana': 150,
    'apple': 240,
    'corn': 200,
    'berries': ['green', 'purple'],
    'map': {
        'y': 6,
        'z': 5,
        'm': 1,
    }
}))

@mvadu
Copy link

mvadu commented Feb 25, 2021

@sampsyo any plan to support this? This would be an incredible addition in docker environment since its preferred to add config entries in docker compose files. Dynaconf does this exact thing, but for someone who already invested in confuse having this capability might be really helpful.

@sampsyo
Copy link
Member

sampsyo commented Feb 26, 2021

I would be happy to review a PR, but I do not have the bandwidth to implement this myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants