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 details)
Built Distribution
File details
Details for the file env-yaml-0.0.3.tar.gz
.
File metadata
- Download URL: env-yaml-0.0.3.tar.gz
- Upload date:
- Size: 2.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6b55b18c28fb623793137a8e55bd666d6483af7fd0162a41a62325ce662fda6 |
|
MD5 | e4c50ab02c2e311dfb08c23f4de36854 |
|
BLAKE2b-256 | 6a6636d46d7b2a667f5de6396c61e7a313a4d6e67c5e61aa1ca9c2392cfc2058 |
File details
Details for the file env_yaml-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: env_yaml-0.0.3-py3-none-any.whl
- Upload date:
- Size: 2.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f56723c8997bea1240bf634b9e29832714dd9745a42cbc2649f1238a6a576244 |
|
MD5 | 51555339ad670cc07e9e9451f30a89d0 |
|
BLAKE2b-256 | a03aadfa951f5e659b103be9a15f5d9572780f501c1c02351695ff5f8bf5569f |