All Projects → zerwes → Hiyapyco

zerwes / Hiyapyco

Licence: gpl-3.0
HiYaPyCo - A Hierarchical Yaml Python Config

Programming Languages

python
139335 projects - #7 most used programming language
python3
1442 projects

Projects that are alternatives of or similar to Hiyapyco

Dynaconf
Configuration Management for Python ⚙
Stars: ✭ 2,082 (+3489.66%)
Mutual labels:  config, configuration, yaml
Konf
A type-safe cascading configuration library for Kotlin/Java/Android, supporting most configuration formats
Stars: ✭ 225 (+287.93%)
Mutual labels:  config, yaml, configuration
Config Lite
A super simple & flexible & useful config module.
Stars: ✭ 78 (+34.48%)
Mutual labels:  config, yaml, configuration
Dasel
Query, update and convert data structures from the command line. Comparable to jq/yq but supports JSON, TOML, YAML, XML and CSV with zero runtime dependencies.
Stars: ✭ 759 (+1208.62%)
Mutual labels:  config, yaml, configuration
goodconf
Transparently load variables from environment or JSON/YAML file.
Stars: ✭ 80 (+37.93%)
Mutual labels:  config, yaml, configuration
Strictyaml
Type-safe YAML parser and validator.
Stars: ✭ 836 (+1341.38%)
Mutual labels:  config, yaml, configuration
Simple Settings
A simple way to manage your project settings.
Stars: ✭ 165 (+184.48%)
Mutual labels:  config, yaml, configuration
cfg-rs
A Configuration Library for Rust Applications
Stars: ✭ 18 (-68.97%)
Mutual labels:  config, yaml, configuration
parse it
A python library for parsing multiple types of config files, envvars & command line arguments that takes the headache out of setting app configurations.
Stars: ✭ 86 (+48.28%)
Mutual labels:  config, yaml, configuration
climatecontrol
Python library for loading settings and config data from files and environment variables
Stars: ✭ 20 (-65.52%)
Mutual labels:  config, yaml, configuration
Hoplite
A boilerplate-free library for loading configuration files as data classes in Kotlin
Stars: ✭ 322 (+455.17%)
Mutual labels:  config, yaml, configuration
yaask
Make your yaml configurable with interactive configurations!
Stars: ✭ 15 (-74.14%)
Mutual labels:  config, yaml, configuration
Koanf
Light weight, extensible configuration management library for Go. Built in support for JSON, TOML, YAML, env, command line, file, S3 etc. Alternative to viper.
Stars: ✭ 450 (+675.86%)
Mutual labels:  config, yaml, configuration
V2ray Examples
v2ray-core 的模板们
Stars: ✭ 778 (+1241.38%)
Mutual labels:  config, configuration
Carvel Ytt
YAML templating tool that works on YAML structure instead of text
Stars: ✭ 816 (+1306.9%)
Mutual labels:  yaml, configuration
Config
Yii2 application runtime configuration support
Stars: ✭ 54 (-6.9%)
Mutual labels:  config, configuration
Config Rs
⚙️ Layered configuration system for Rust applications (with strong support for 12-factor applications).
Stars: ✭ 915 (+1477.59%)
Mutual labels:  config, configuration
Configuron
Clojure(Script) config that reloads from project.clj when in dev mode
Stars: ✭ 24 (-58.62%)
Mutual labels:  config, configuration
Yamlsettings
Yaml Settings Configuration Module
Stars: ✭ 12 (-79.31%)
Mutual labels:  yaml, configuration
Mconfig
MCONFIG is a lightweight Golang library for integrating configs files like (json, yml, toml) and environment variables into one config struct.
Stars: ✭ 28 (-51.72%)
Mutual labels:  config, yaml

hiyapyco

HiYaPyCo - A Hierarchical Yaml Python Config

Description

A simple python lib allowing hierarchical overlay of config files in YAML syntax, offering different merge methods and variable interpolation based on jinja2.

The goal was to have something similar to puppets hiera merge_behavior: deeper for python.

Key Features

  • hierarchical overlay of multiple YAML files
  • multiple merge methods for hierarchical YAML files
  • variable interpolation using jinja2

Requirements

  • PyYAML aka. python-yaml
  • Jinja2 aka. python-jinja2
  • ordereddict for python2.6 (if you like to use the Ordered Dict Yaml Loader / Dumper aka. ODYLDo)

Python Version


HiYaPyCo was designed to run on both current major python versions
without changes. Tested versions:

-  2.7
-  3.2
-  3.4
-  3.5

Usage
-----

A simple example:

::

    import hiyapyco
    conf = hiyapyco.load('yamlfile1' [,'yamlfile2' [,'yamlfile3' [...]]] [,kwargs])
    print(hiyapyco.dump(conf, default_flow_style=False))

real life example:

yaml1.yaml:

::

---
first: first element
second: xxx
deep:
    k1:
        - 1
        - 2

yaml2.yaml:

::

---
second: again {{ first }}
deep:
    k1:
        - 4 
        - 6
    k2:
        - 3
        - 6

load ...

::

>>> import pprint
>>> import hiyapyco
>>> conf = hiyapyco.load('yaml1.yaml', 'yaml2.yaml', method=hiyapyco.METHOD_MERGE, interpolate=True, failonmissingfiles=True)
>>> pprint.PrettyPrinter(indent=4).pprint(conf)
{   'deep': {   'k1': [1, 2, 4, 6], 'k2': [3, 6]},
    'first': u'first element',
    'ma': {   'ones': u'12', 'sum': u'22'},
    'second': u'again first element'}

real life example using yaml documents as strings


::

    >>> import hiyapyco
    >>> y1="""
    ... yaml: 1
    ... y:
    ...   y1: abc
    ...   y2: xyz
    ... """
    >>> y2="""
    ... yaml: 2
    ... y:
    ...   y2: def
    ...   y3: XYZ
    ... """
    >>> conf = hiyapyco.load([y1, y2], method=hiyapyco.METHOD_MERGE)
    >>> print (conf)
    OrderedDict([('yaml', 2), ('y', OrderedDict([('y1', 'abc'), ('y2', 'def'), ('y3', 'XYZ')]))])
    >>> hiyapyco.dump(conf, default_flow_style=True)
    '{yaml: 2, y: {y1: abc, y2: def, y3: XYZ}}\n'

args
~~~~

All ``args`` are handled as *file names* or *yaml documents*. They may
be strings or list of strings.

kwargs
~~~~~~

-  ``method``: bit (one of the listed below):

   -  ``hiyapyco.METHOD_SIMPLE``: replace values (except for lists a
      simple merge is performed) (default method)
   -  ``hiyapyco.METHOD_MERGE``: perform a deep merge
   -  ``hiyapyco.METHOD_SUBSTITUTE``: perform a merge w/ lists substituted (unsupoerted)

- ``mergelists``: boolean try to merge lists of dict (default: ``True``)

-  ``interpolate``: boolean : perform interpolation after the merge
   (default: ``False``)

-  ``castinterpolated``: boolean : try to perform a *best possible
   match* cast for interpolated strings (default: ``False``)

-  ``usedefaultyamlloader``: boolean : force the usage of the default
   *PyYAML* loader/dumper instead of *HiYaPyCo*\ s implementation of a
   OrderedDict loader/dumper (see: Ordered Dict Yaml Loader / Dumper
   aka. ODYLDo) (default: ``False``)

- ``encoding``: string : encoding used to read yaml files (default: ``utf-8``)

-  ``failonmissingfiles``: boolean : fail if a supplied YAML file can
   not be found (default: ``True``)

-  ``loglevel``: int : loglevel for the hiyapyco logger; should be one
   of the valid levels from ``logging``: 'WARN', 'ERROR', 'DEBUG', 'I
   NFO', 'WARNING', 'CRITICAL', 'NOTSET' (default: default of
   ``logging``)

-  ``loglevelmissingfiles``: int : one of the valid levels from
   ``logging``: 'WARN', 'ERROR', 'DEBUG', 'INFO', 'WARNING', 'CRITICAL',
   'NOTSET' (default: ``logging.ERROR`` if
   ``failonmissingfiles = True``, else ``logging.WARN``)

interpolation
~~~~~~~~~~~~~

For using interpolation, I strongly recomend *not* to use the default
PyYAML loader, as it sorts the dict entrys alphabetically, a fact that
may break interpolation in some cases (see ``test/odict.yaml`` and
``test/test_odict.py`` for an example). See Ordered Dict Yaml Loader /
Dumper aka. ODYLDo

default
^^^^^^^

The default jinja2.Environment for the interpolation is

::

    hiyapyco.jinja2env = Environment(undefined=Undefined)

This means that undefined vars will be ignored and replaced with a empty
string.

change the jinja2 Environment
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

If you like to change the jinja2 Environment used for the interpolation,
set ``hiyapyco.jinja2env`` **before** calling ``hiyapyco.load``!

use jinja2 DebugUndefined
^^^^^^^^^^^^^^^^^^^^^^^^^

If you like to keep the undefined var as string but raise no error, use

::

    from jinja2 import Environment, Undefined, DebugUndefined, StrictUndefined
    hiyapyco.jinja2env = Environment(undefined=DebugUndefined)

use jinja2 StrictUndefined
^^^^^^^^^^^^^^^^^^^^^^^^^^

If you like to raise a error on undefined vars, use

::

    from jinja2 import Environment, Undefined, DebugUndefined, StrictUndefined
    hiyapyco.jinja2env = Environment(undefined=StrictUndefined)

This will raise a ``hiyapyco.HiYaPyCoImplementationException`` wrapped
arround the ``jinja2.UndefinedError`` pointing at the string causing the
error.

more informations
^^^^^^^^^^^^^^^^^

See:
`jinja2.Environment <http://jinja.pocoo.org/docs/dev/api/#jinja2.Environment>`_

cast interpolated strings
~~~~~~~~~~~~~~~~~~~~~~~~~

As you must use interpolation as strings (PyYAML will weep if you try to
start a value with ``{{``), you can set ``castinterpolated`` to *True*
in order to try to get a ``best match`` cast for the interpolated
values. **The ``best match`` cast is currently only a q&d implementation
and may not give you the expected results!**

Ordered Dict Yaml Loader / Dumper aka. ODYLDo
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This is a simple implementation of a PyYAML loader / dumper using
``OrderedDict`` from collections.
**Because chaos is fun but order matters on loading dicts from a yaml
file.**

In order to use this on python 2.6, please install ordereddict:

::

    sudo pip-2.6 install ordereddict

Install
-------

From Source
~~~~~~~~~~~

GitHub
^^^^^^

`https://github.com/zerwes/hiyapyco <https://github.com/zerwes/hiyapyco>`_

::

    git clone https://github.com/zerwes/hiyapyco
    cd hiyapyco
    sudo python setup.py install

PyPi
^^^^

Download the latest or desired version of the source package from
`https://pypi.python.org/pypi/HiYaPyCo <https://pypi.python.org/pypi/HiYaPyCo>`_.
Unpack the archive and install by executing:

::

    sudo python setup.py install

pip
~~~

Install the latest wheel package using:

::

    pip install HiYaPyCo

debian packages
~~~~~~~~~~~~~~~

install the latest debian packages from http://repo.zero-sys.net/hiyapyco::

    echo "deb http://repo.zero-sys.net/hiyapyco/deb ./" > /etc/apt/sources.list.d/hiyapyco.list
    gpg --keyserver keys.gnupg.net --recv-key 77DE7FB4
    # or use:
    wget https://repo.zero-sys.net/77DE7FB4.asc -O - | gpg --import -
    gpg --armor --export 77DE7FB4 | apt-key add -
    apt-get update
    apt-get install python3-hiyapyco python-hiyapyco

rpm packages
~~~~~~~~~~~~

use
`http://repo.zero-sys.net/hiyapyco/rpm <http://repo.zero-sys.net/hiyapyco/rpm>`_
as URL for the yum repo and
`https://repo.zero-sys.net/77DE7FB4.asc <https://repo.zero-sys.net/77DE7FB4.asc>`_
as the URL for the key.

Arch Linux
~~~~~~~~~~

An `AUR package <https://aur.archlinux.org/packages/python-hiyapyco/>`_
is available.

License
-------

Copyright |copy| 2014 - 2020 Klaus Zerwes `zero-sys.net <https://zero-sys.net>`_

.. |copy| unicode:: 0xA9 .. copyright sign

This package is free software.
This software is licensed under the terms of the GNU GENERAL PUBLIC
LICENSE version 3 or later, as published by the Free Software
Foundation.
See
`https://www.gnu.org/licenses/gpl.html <https://www.gnu.org/licenses/gpl.html>`_

Changelog
---------

0.4.16
~~~~~~

MERGED: #37 alex-ber

0.4.15
~~~~~~

MERGED: #30 lesiak:issue-30-utf

MERGED: #28 lesiak:issue-28

0.4.14
~~~~~~

FIXED: issue #33

MERGED: issue #32

0.4.13
~~~~~~

IMPLEMENTED: [issue #27] support multiple yaml documents in one file

0.4.12
~~~~~~

FIXED: logging by Regev Golan

0.4.11
~~~~~~

IMPLEMENTED: mergelists (see issue #25)

0.4.10
~~~~~~

FIXED: issue #24 repo signing

0.4.9
~~~~~

FIXED: issue #23 loglevelonmissingfiles

0.4.8
~~~~~

Fixed pypi doc

0.4.7
~~~~~

Reverted: logger settings to initial state

Improved: dump

Merged:

- flatten mapping from Chris Petersen [email protected]
- arch linux package info from Peter Crighton [email protected]

0.4.6
~~~~~

MERGED: fixes from mmariani

0.4.5
~~~~~

FIXED: issues #9 and #11

0.4.4
~~~~~

deb packages:

- removed support for python 2.6
- include examples as doc

0.4.3
~~~~~

FIXED: issue #6 *import of hiyapyco **version** in setup.py causes pip
install failures*

0.4.2
~~~~~

Changed: moved to GPL

Improvements: missing files handling, doc

0.4.1
~~~~~

Implemented: ``castinterpolated``

0.4.0
~~~~~

Implemented: loading yaml docs from string

0.3.2
~~~~~

Improved tests and bool args checks

0.3.0 / 0.3.1
~~~~~~~~~~~~~

Implemented a Ordered Dict Yaml Loader

0.2.0
~~~~~

Fixed unicode handling

0.1.0 / 0.1.1
~~~~~~~~~~~~~

Initial release
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].