yamlreader


Nameyamlreader JSON
Version 3.0.4 PyPI version JSON
download
home_pagehttps://github.com/ImmobilienScout24/yamlreader
SummaryMerge YAML data from given files, dir or file glob
upload_time2017-01-18 15:14:02
maintainer
docs_urlNone
authorSchlomo Schapiro
requires_python
licenseApache License 2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            .. image:: https://travis-ci.org/ImmobilienScout24/yamlreader.png?branch=master
   :alt: Travis build status image
   :align: left
   :target: https://travis-ci.org/ImmobilienScout24/yamlreader

==========
yamlreader
==========
Merge YAML data from a directory, a list of files or a file glob. With a
directory, the YAML files (`*.yaml`) are sorted alphabetically. The YAML
files are expected to contain a complex key-value structure and merged
with the following rules:

* lists get appended
* hashes get merged by key
* scalars (numbers, strings) are overwritten
* everything else will fail

The purpose is to allow several YAML files instead of a single YAML file. We
use it to help our software read configuration data from an arbitrary amount
of YAML files instead of a single YAML file.

Read the unit test to see some examples.

Building and Installation
=========================
Using pip
---------
**yamlreader** is available with ``pip``:
::

    pip install yamlreader

Manual build and installation
-----------------------------
If you want to make changes or use e.g. ``fpm`` for packaging this, you need to
prepare the development environment to make further steps.

Prepare the source
~~~~~~~~~~~~~~~~~~
::

    git clone https://github.com/ImmobilienScout24/yamlreader.git
    cd yamlreader
    virtualenv venv
    source venv/bin/activate
    pip install pybuilder
    pyb install_dependencies

Running tests
~~~~~~~~~~~~~
::

    pyb verify

Generating a setup.py
~~~~~~~~~~~~~~~~~~~~~
::

    pyb
    cd target/dist/yamlreader-<VERSION>
    ./setup.py <whatever you want>

Running
=======
The package installs a command line script ``yamlreader`` that can be used to
read one or many YAML files and dump the merge result as a YAML document.

Use it in your software
=======================
Wherever you had been using the ``safe_load`` function of
`PyYAML <http://pyyaml.org/>`_ to read a single YAML file you can use
the ``yamlreader.yaml_load`` function as a replacement to read all ``*.yaml``
files in a directory::

    from yamlreader import yaml_load

    defaultconfig = {
            "loglevel" : "error",
            "some" : "value"
    }

    config = yaml_load("/etc/myapp", defaultconfig)

yaml_load
---------
::

    def yaml_load(source,defaultdata=None):
        """merge YAML data from files found in source

        Always returns a dict. The YAML files are expected to contain some kind of
        key:value structures, possibly deeply nested. When merging, lists are
        appended and dict keys are replaced. The YAML files are read with the
        yaml.safe_load function.

        source can be a file, a dir, a list/tuple of files or a string containing
        a glob expression (with ?*[]).

        For a dir all *.yaml files will be read in alphabetical order.

        defaultdata can be used to initialize the data.
        """
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ImmobilienScout24/yamlreader",
    "name": "yamlreader",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Schlomo Schapiro",
    "author_email": "schlomo.schapiro@immobilienscout24.de",
    "download_url": "https://files.pythonhosted.org/packages/84/4b/3af5480c26b3235dcd0984b9664b48115c2308c8c4f22e7162322be4ec0f/yamlreader-3.0.4.tar.gz",
    "platform": "UNKNOWN",
    "description": ".. image:: https://travis-ci.org/ImmobilienScout24/yamlreader.png?branch=master\n   :alt: Travis build status image\n   :align: left\n   :target: https://travis-ci.org/ImmobilienScout24/yamlreader\n\n==========\nyamlreader\n==========\nMerge YAML data from a directory, a list of files or a file glob. With a\ndirectory, the YAML files (`*.yaml`) are sorted alphabetically. The YAML\nfiles are expected to contain a complex key-value structure and merged\nwith the following rules:\n\n* lists get appended\n* hashes get merged by key\n* scalars (numbers, strings) are overwritten\n* everything else will fail\n\nThe purpose is to allow several YAML files instead of a single YAML file. We\nuse it to help our software read configuration data from an arbitrary amount\nof YAML files instead of a single YAML file.\n\nRead the unit test to see some examples.\n\nBuilding and Installation\n=========================\nUsing pip\n---------\n**yamlreader** is available with ``pip``:\n::\n\n    pip install yamlreader\n\nManual build and installation\n-----------------------------\nIf you want to make changes or use e.g. ``fpm`` for packaging this, you need to\nprepare the development environment to make further steps.\n\nPrepare the source\n~~~~~~~~~~~~~~~~~~\n::\n\n    git clone https://github.com/ImmobilienScout24/yamlreader.git\n    cd yamlreader\n    virtualenv venv\n    source venv/bin/activate\n    pip install pybuilder\n    pyb install_dependencies\n\nRunning tests\n~~~~~~~~~~~~~\n::\n\n    pyb verify\n\nGenerating a setup.py\n~~~~~~~~~~~~~~~~~~~~~\n::\n\n    pyb\n    cd target/dist/yamlreader-<VERSION>\n    ./setup.py <whatever you want>\n\nRunning\n=======\nThe package installs a command line script ``yamlreader`` that can be used to\nread one or many YAML files and dump the merge result as a YAML document.\n\nUse it in your software\n=======================\nWherever you had been using the ``safe_load`` function of\n`PyYAML <http://pyyaml.org/>`_ to read a single YAML file you can use\nthe ``yamlreader.yaml_load`` function as a replacement to read all ``*.yaml``\nfiles in a directory::\n\n    from yamlreader import yaml_load\n\n    defaultconfig = {\n            \"loglevel\" : \"error\",\n            \"some\" : \"value\"\n    }\n\n    config = yaml_load(\"/etc/myapp\", defaultconfig)\n\nyaml_load\n---------\n::\n\n    def yaml_load(source,defaultdata=None):\n        \"\"\"merge YAML data from files found in source\n\n        Always returns a dict. The YAML files are expected to contain some kind of\n        key:value structures, possibly deeply nested. When merging, lists are\n        appended and dict keys are replaced. The YAML files are read with the\n        yaml.safe_load function.\n\n        source can be a file, a dir, a list/tuple of files or a string containing\n        a glob expression (with ?*[]).\n\n        For a dir all *.yaml files will be read in alphabetical order.\n\n        defaultdata can be used to initialize the data.\n        \"\"\"",
    "bugtrack_url": null,
    "license": "Apache License 2.0",
    "summary": "Merge YAML data from given files, dir or file glob",
    "version": "3.0.4",
    "project_urls": {
        "Homepage": "https://github.com/ImmobilienScout24/yamlreader"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "844b3af5480c26b3235dcd0984b9664b48115c2308c8c4f22e7162322be4ec0f",
                "md5": "542179b5b5bedae941245b8b673119db",
                "sha256": "765688036d57104ac26e4500ab088d42f4f2d06687ce3daa26543d7ae38c2470"
            },
            "downloads": -1,
            "filename": "yamlreader-3.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "542179b5b5bedae941245b8b673119db",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4611,
            "upload_time": "2017-01-18T15:14:02",
            "upload_time_iso_8601": "2017-01-18T15:14:02.722404Z",
            "url": "https://files.pythonhosted.org/packages/84/4b/3af5480c26b3235dcd0984b9664b48115c2308c8c4f22e7162322be4ec0f/yamlreader-3.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2017-01-18 15:14:02",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ImmobilienScout24",
    "github_project": "yamlreader",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "lcname": "yamlreader"
}
        
Elapsed time: 0.52706s