Skip to main content
Help us improve PyPI by participating in user testing. All experience levels needed!

YAML parser

Project description

YAML access on chained attribute names.


$ pip install yachain

Suppose we have:

# config
   name: developers
      - yum
      - gcc

With yachain we can access this as:

>>> import yachain

>>> c = yachain.Config().load("netw.cfg")
>>> print(c["network::gitserver::gateway"])
>>> print(c["network::gitserver::packages"])
['yum', 'gcc']

References to files / paths independent from environment

References to files and paths can be used relative and absolute. In case an attribute ends on path or file then the path can be prefixed automatically when operation from a virtual environment is detected. The works by default upper and lower case and can be overriden.

Using the prefix makes it possible to use the same config in different environments.

import yachain
import yaml
import sys
import os

# yaml config:
yc = """
  logfile: var/log/app.log
  textrules: var/
  database_path: var/app/db
  database_file: /var/app/db/db.txt
  database_name: db.txt

PREFIX = "/" if not hasattr(sys, 'real_prefix') else sys.prefix
# CONFIG_FILE = os.path.join(PREFIX, "etc/app/app.cfg")
config = yachain.Config(prefix=PREFIX, configdata=yaml.load(yc))

for A in ["logfile",
    k = "app::{}".format(A)
    print config[k]

When run from a virtual environment, this will give us:


So, as expected, the logfile and database_path got the PREFIX.

When run from a non-virtual environment, this will give us:


So, as expected, prefixed with “/”.

Project details

Release history Release notifications

This version
History Node


Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
yachain-0.1.3-py2.py3-none-any.whl (6.4 kB) Copy SHA256 hash SHA256 Wheel py2.py3 Jun 12, 2017
yachain-0.1.3.tar.gz (5.2 kB) Copy SHA256 hash SHA256 Source None Jun 12, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page