Skip to main content

Simple YAML configuration file parser with easy access for structured data

Project description

EnvYAML | Latest Version Build Status Coverage Status

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.1902.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

envyaml-0.1902-py2.py3-none-any.whl (6.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file envyaml-0.1902.tar.gz.

File metadata

  • Download URL: envyaml-0.1902.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3

File hashes

Hashes for envyaml-0.1902.tar.gz
Algorithm Hash digest
SHA256 1f0e08f1f10d19721eeb70e03f66d51202360eaa7bab02a051e2b7aaefe77097
MD5 dd506fbcc4e4e6946ea39e9b59a0bfde
BLAKE2b-256 c92dd05e69e1e1a3a392c69b6fb8c7c2438ae20994574d13656a5a3a0cebcf9d

See more details on using hashes here.

File details

Details for the file envyaml-0.1902-py2.py3-none-any.whl.

File metadata

  • Download URL: envyaml-0.1902-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3

File hashes

Hashes for envyaml-0.1902-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3c84879b5f6083f51e37456edfda7414ee5431ff04e5da90595038a1de062cdc
MD5 5a0189d80b905975cc5a8648f374f3d8
BLAKE2b-256 88c14ac9871c19fe36ff8a15e85f55c9b064aa145817e04d0829b77592a2efaf

See more details on using hashes here.

Supported by

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