Provides a yaml loader which substitutes environment variables and supports defaults
Project description
evn-yaml
This is similar to what is done in Quarkus: https://quarkus.io/guides/config-reference#property-expressions
Allows for substitution of environment variables when loading a yaml file, while providing defaults, for e.g.:
database:
mongodb:
connection_string: ${MONGODB_CONNECTION_STRING:localhost:27017}
database: ${MONGODB_DATABASE_NAME:test}
Usage
Create config.yaml
:
a:
b: ${ENV_B:default_used_b}
c: ${ENV_C:default_used_c}
d: ${ENV_D}
Read file and use EnvLoader
:
import os
from env_yaml import EnvLoader
import yaml
os.environ['ENV_B'] = 'default_not_used_b'
with open('config.yaml', 'r') as f:
file_contents = f.read()
result = yaml.load(file_contents, EnvLoader)
print(result)
Results in:
{'a': {'b': 'default_not_used_b', 'c': 'default_used_c', 'd': None}}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
env-yaml-0.0.3.tar.gz
(2.3 kB
view hashes)