Skip to main content

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


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.2.tar.gz (1.8 kB view hashes)

Uploaded Source

Built Distribution

env_yaml-0.0.2-py3-none-any.whl (1.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page