pyaconf


Namepyaconf JSON
Version 0.7.1 PyPI version JSON
download
home_pagehttps://bitbucket.org/ikh/pyaconf
SummaryYet another config library that is built around python dictionary and supports dynamic python, json, yaml, and ini formats with inheritance with Jinji2 templates
upload_time2020-09-18 01:52:39
maintainer
docs_urlNone
authorikh software, inc.
requires_python>= 3.7
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pyaconf - yet another config library built around python dictionary

Pyaconf is a config library that is built around python dictionary and supports dynamic python, json, yaml, and ini formats with inheritance.
It features:

## Features

* 4 formats (pyaconf [python], yaml, json, ini) that can be layered on top of each other,
* dynamic pyaconf (python) format,
* __include__ feature that can layer combine the 4 formats hierarchically,
* “merge” capability that allows to override values by the topmost layer,
* jinja2 template substitution capability that can be injected at various layers of override and dictionary hierarchies, 
* simple 3 function (load, merge, and dump) Python API, and  
* command line utility that allows us to use all these features from the command line 


## Notes

* All configs are json compatible dicts.
* Supports layered configs (inheritance) via `__include__` dict entry, for example, the following yaml config would read the dictionary defined from config `boo.json` and then will update it with `user` and `password` from this config:

```yaml
__include__: boo.json
user: romeo
password: romeoalpha
```

* Includes may be used at any level and apply only to its layer. 
* Simple API: `load`, `dump`, and for more advanced use `merge`.
* Supports dynamic configs written in Python `.pyaconf`, for example:

```python
import os
def config():
   return dict(
      __include__ = ["secret.yml"],
      user = "romeo", 
      password = os.environ['PASSWORD'],
      database = dict(
         __include__ = "db.ini",
      ),
   )
```

* Allows to output configs in `.json` and `.yaml`. Provides two shell scripts.
* Supports `.ini` input format as understood by python's `configparser`.
* Supports Jinji2 templates, you just need to add `.j2` or `.jinji2` extension to your config file and it will be processed by Jinji2. For example:

```yaml
user: {{ username }}
password = {{ password }}
```

* The dictionary that contains includes serves as a context for these includes. For template includes, the dictionary is passed as a context to the template processing. For non-template includes, the dictionary merges with the include. When all includes processed this way, they all merge together.

```yaml
__include__: [a.yaml.j2, b.yaml]
x: 1
y: 2
```

* Another example with template:

```yaml
# common.yaml.j2
host: local
user: {{ username }}
password: {{ password }}
credentials: [{{ password }}, {{username}}]
```

```yaml
# devel.yaml
__include__: common.yaml.j2
username: Donald
password: Trump
office: 113D
```

```yaml
# pyaconf_render -f json devel.yaml
{
  "credentials": [
     "Trump",
     "Donald"
  ],
  "host": "local",
  "password": "Trump",
  "user": "Donald"
}
```

## API

### load

```python
def load(src, *, format='auto', path=None, context={}):
   """ loads a dict that may include special keyword '__include__' at multiple levels,
   and resolves these includes and returns a dict without includes. It can also read the input dict from a file
   src -- dict|Mapping, FILE|io.StringIO(s), pathlib.Path|str
   format -- 'auto' | 'pyaconf' | 'json' | 'yaml' | 'ini'
   path -- is used only when src doesn't contain path info, it is used for error messages and resolve relative include paths
   context -- is a dict that is used as context for template rendering if src is a template
   """
```

### dump

```python
def dump(x, dst=sys.stdout, *, format='auto'):
   """ Dumps resolved (without includes) config in json or yaml format. It doesn't preserve comments either. 
   x -- dict|Mapping
   dst -- FILE|io.StringIO(s), pathlib.Path|str
   format -- 'auto' | 'json' | 'yaml'
   """
```


### merge

```python
def merge(xs):
   """ merges the list of dicts (that dont contain includes) and returns a new dict
   where the values of the first dict are updated recursively by the values of the second dict.
   xs -- a list of dicts
   """
```

## Scripts

* pyaconf_render -- loads and merges multiple configs and renders the result in json or yaml format

## License

OSI Approved 3 clause BSD License

## Prerequisites

* Python 3.7+

## Installation

If prerequisites are met, you can install `pyaconf` like any other Python package, using pip to download it from PyPI:

    $ pip install pyaconf

or using `setup.py` if you have downloaded the source package locally:

    $ python setup.py build
    $ sudo python setup.py install



            

Raw data

            {
    "_id": null,
    "home_page": "https://bitbucket.org/ikh/pyaconf",
    "name": "pyaconf",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">= 3.7",
    "maintainer_email": "",
    "keywords": "",
    "author": "ikh software, inc.",
    "author_email": "ikh@ikhsoftware.com",
    "download_url": "https://files.pythonhosted.org/packages/d8/de/408e11d416d05d350b8b4a12c8d3f0d5b3ec11c8854763d2ce4a6ffbd233/pyaconf-0.7.1.tar.gz",
    "platform": "",
    "description": "# pyaconf - yet another config library built around python dictionary\n\nPyaconf is a config library that is built around python dictionary and supports dynamic python, json, yaml, and ini formats with inheritance.\nIt features:\n\n## Features\n\n* 4 formats (pyaconf [python], yaml, json, ini) that can be layered on top of each other,\n* dynamic pyaconf (python) format,\n* __include__ feature that can layer combine the 4 formats hierarchically,\n* \u201cmerge\u201d capability that allows to override values by the topmost layer,\n* jinja2 template substitution capability that can be injected at various layers of override and dictionary hierarchies, \n* simple 3 function (load, merge, and dump) Python API, and  \n* command line utility that allows us to use all these features from the command line \n\n\n## Notes\n\n* All configs are json compatible dicts.\n* Supports layered configs (inheritance) via `__include__` dict entry, for example, the following yaml config would read the dictionary defined from config `boo.json` and then will update it with `user` and `password` from this config:\n\n```yaml\n__include__: boo.json\nuser: romeo\npassword: romeoalpha\n```\n\n* Includes may be used at any level and apply only to its layer. \n* Simple API: `load`, `dump`, and for more advanced use `merge`.\n* Supports dynamic configs written in Python `.pyaconf`, for example:\n\n```python\nimport os\ndef config():\n   return dict(\n      __include__ = [\"secret.yml\"],\n      user = \"romeo\", \n      password = os.environ['PASSWORD'],\n      database = dict(\n         __include__ = \"db.ini\",\n      ),\n   )\n```\n\n* Allows to output configs in `.json` and `.yaml`. Provides two shell scripts.\n* Supports `.ini` input format as understood by python's `configparser`.\n* Supports Jinji2 templates, you just need to add `.j2` or `.jinji2` extension to your config file and it will be processed by Jinji2. For example:\n\n```yaml\nuser: {{ username }}\npassword = {{ password }}\n```\n\n* The dictionary that contains includes serves as a context for these includes. For template includes, the dictionary is passed as a context to the template processing. For non-template includes, the dictionary merges with the include. When all includes processed this way, they all merge together.\n\n```yaml\n__include__: [a.yaml.j2, b.yaml]\nx: 1\ny: 2\n```\n\n* Another example with template:\n\n```yaml\n# common.yaml.j2\nhost: local\nuser: {{ username }}\npassword: {{ password }}\ncredentials: [{{ password }}, {{username}}]\n```\n\n```yaml\n# devel.yaml\n__include__: common.yaml.j2\nusername: Donald\npassword: Trump\noffice: 113D\n```\n\n```yaml\n# pyaconf_render -f json devel.yaml\n{\n  \"credentials\": [\n     \"Trump\",\n     \"Donald\"\n  ],\n  \"host\": \"local\",\n  \"password\": \"Trump\",\n  \"user\": \"Donald\"\n}\n```\n\n## API\n\n### load\n\n```python\ndef load(src, *, format='auto', path=None, context={}):\n   \"\"\" loads a dict that may include special keyword '__include__' at multiple levels,\n   and resolves these includes and returns a dict without includes. It can also read the input dict from a file\n   src -- dict|Mapping, FILE|io.StringIO(s), pathlib.Path|str\n   format -- 'auto' | 'pyaconf' | 'json' | 'yaml' | 'ini'\n   path -- is used only when src doesn't contain path info, it is used for error messages and resolve relative include paths\n   context -- is a dict that is used as context for template rendering if src is a template\n   \"\"\"\n```\n\n### dump\n\n```python\ndef dump(x, dst=sys.stdout, *, format='auto'):\n   \"\"\" Dumps resolved (without includes) config in json or yaml format. It doesn't preserve comments either. \n   x -- dict|Mapping\n   dst -- FILE|io.StringIO(s), pathlib.Path|str\n   format -- 'auto' | 'json' | 'yaml'\n   \"\"\"\n```\n\n\n### merge\n\n```python\ndef merge(xs):\n   \"\"\" merges the list of dicts (that dont contain includes) and returns a new dict\n   where the values of the first dict are updated recursively by the values of the second dict.\n   xs -- a list of dicts\n   \"\"\"\n```\n\n## Scripts\n\n* pyaconf_render -- loads and merges multiple configs and renders the result in json or yaml format\n\n## License\n\nOSI Approved 3 clause BSD License\n\n## Prerequisites\n\n* Python 3.7+\n\n## Installation\n\nIf prerequisites are met, you can install `pyaconf` like any other Python package, using pip to download it from PyPI:\n\n    $ pip install pyaconf\n\nor using `setup.py` if you have downloaded the source package locally:\n\n    $ python setup.py build\n    $ sudo python setup.py install\n\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Yet another config library that is built around python dictionary and supports dynamic python, json, yaml, and ini formats with inheritance with Jinji2 templates",
    "version": "0.7.1",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "ebb0f441d84c5e9b43d7d5390df7f5ca",
                "sha256": "24e5ce5d0b0f93c5269f72a8776aed004a13f7c672a30d91bec6226ae9793dc6"
            },
            "downloads": -1,
            "filename": "pyaconf-0.7.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ebb0f441d84c5e9b43d7d5390df7f5ca",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">= 3.7",
            "size": 9250,
            "upload_time": "2020-09-18T01:52:37",
            "upload_time_iso_8601": "2020-09-18T01:52:37.949767Z",
            "url": "https://files.pythonhosted.org/packages/c8/24/4b9d96d90340094ee2c9603c0d4398e26585e25caf3c2d1b5135c5e26ffb/pyaconf-0.7.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "268898966877cd7d38ee96c04835dfba",
                "sha256": "08a74aa1300f5297ae50dfc0d302855a6405aae56b23d5f3754fd3ad97711f94"
            },
            "downloads": -1,
            "filename": "pyaconf-0.7.1.tar.gz",
            "has_sig": false,
            "md5_digest": "268898966877cd7d38ee96c04835dfba",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">= 3.7",
            "size": 6758,
            "upload_time": "2020-09-18T01:52:39",
            "upload_time_iso_8601": "2020-09-18T01:52:39.495032Z",
            "url": "https://files.pythonhosted.org/packages/d8/de/408e11d416d05d350b8b4a12c8d3f0d5b3ec11c8854763d2ce4a6ffbd233/pyaconf-0.7.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-09-18 01:52:39",
    "github": false,
    "gitlab": false,
    "bitbucket": true,
    "bitbucket_user": null,
    "bitbucket_project": "ikh",
    "lcname": "pyaconf"
}
        
Elapsed time: 0.12912s