Skip to main content

Simple YAML configuration file parser with easy access for structured data

Project description

EnvYAML | Latest Version Build Status Coverage Status Versions License

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.

Install

pip install envyaml

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 list items by number
print(env.list_test[0])

# >> one

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

envyaml-0.1903.tar.gz (5.2 kB view hashes)

Uploaded Source

Built Distribution

envyaml-0.1903-py2.py3-none-any.whl (6.4 kB view hashes)

Uploaded Python 2 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