beetbox / confuse

painless YAML config files for Python
https://pypi.org/project/confuse/
MIT License
414 stars 51 forks source link

configuration from environment variables #10

Open thejohnfreeman opened 9 years ago

thejohnfreeman commented 9 years ago

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

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 commented 9 years ago

Sounds good!

thejohnfreeman commented 9 years ago

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 commented 6 years ago

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 commented 3 years ago

@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 commented 3 years ago

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