Simple YAML configuration file parser with easy access for structured data
Project description
EnvYAML |
Simple YAML configuration file parser with easy access for structured data
Why
Modern configuration file become to be more complex, flexible and readable. YAML file format are perfect to store configuration file but had no option to pass environment variables. This project try to simplify usage YAML file and environment variables as program configuration file with easy config key access.
Basic usage
Let's assume we had a project with this config file env.yaml
# env.yaml
database:
host: $DATABASE_HOST
port: 3301
username: username
password: $DATABASE_PASSWORD
database: test
table:
user: table_user
blog: table_blog
redis:
host: $REDIS_HOST
port: 5040
config:
expire: 300
prefix: $REDIS_PREFIX
and environment variables set to
$DATABASE_HOST=xxx.xxx.xxx.xxx
$DATABASE_PASSWORD=super-secret-password
$REDIS_PREFIX=state
parse file with EnvYAML
from envyaml import EnvYAML
# read file env.yaml and parse config
env = EnvYAML('env.yaml')
# access whole database section
print(env.database)
# {
# 'database': 'test',
# 'host': 'xxx.xxx.xxx.xxx',
# 'password': 'super-secret-password',
# 'port': 3301,
# 'table':
# {
# 'blog': 'table_blog',
# 'user': 'table_user'
# },
# 'username': 'username'
# }
# access database host value as properties name
print(env.database__host)
# >> xxx.xxx.xxx.xxx
# access database user table value as properties name
print(env.database__table__user)
# >> table_user
access config parameters with key option ['name']
print(env['database__port'])
# >> 3301
access config with get
function and default value
print(env.get('not__exist__value', 'default'))
# >> default
License
MIT licensed. See the LICENSE file for more details.
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
Built Distribution
File details
Details for the file envyaml-0.1901rc4.tar.gz
.
File metadata
- Download URL: envyaml-0.1901rc4.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24a543b543889277e95dba607e89c8146211b4ab7b4c73077cdfbc67c4e93d7c |
|
MD5 | ab330371acb7cf0331010f07eca74e97 |
|
BLAKE2b-256 | 4bb1412a2c356aa7087ce5e56fefb5a7c6bf3cc0a79d716158ae450eeeb92f2e |
File details
Details for the file envyaml-0.1901rc4-py3-none-any.whl
.
File metadata
- Download URL: envyaml-0.1901rc4-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a1502f686dfa84a8ae43c08fc489903a826f778821373104af817bd466df88f |
|
MD5 | 76c0ba5cf4b338283a936ebe26dbe5c8 |
|
BLAKE2b-256 | d9738a91761f2f26c35eb7bd24ef4e0f59b75efcfaf070b32c452b43bf99420f |