{ "info": { "author": "d.muth", "author_email": "d.muth@gmx.net", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Software Development :: Libraries" ], "description": "# dictmentor\n\n[![PyPI version](https://badge.fury.io/py/dictmentor.svg)](https://badge.fury.io/py/dictmentor)\n[![Build Status](https://travis-ci.org/HazardDede/dictmentor.svg?branch=master)](https://travis-ci.org/HazardDede/dictmentor)\n[![Coverage Status](https://coveralls.io/repos/github/HazardDede/dictmentor/badge.svg?branch=master)](https://coveralls.io/github/HazardDede/dictmentor?branch=master)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n\nA python utility framework to augment dictionaries\n\n1\\. [Installation](#installation) \n2\\. [Getting started](#gettingstarted) \n3\\. [Extensions](#extensions) \n3.1\\. [Variables](#variables) \n3.2\\. [Environment](#environment) \n3.3\\. [ExternalResource](#externalresource) \n3.4\\. [ExternalYamlResource](#externalyamlresource) \n\n\n\n## 1\\. Installation\n\nInstallation is straightforward via pip:\n\n```bash\npip install dictmentor\n```\n\n\n\n## 2\\. Getting started\n\nUsing `dictmentor` is simple. Just create an instance of `DictMentor` and bind some extensions to it. The extensions\ndo the hard work augmenting the dictionary. `DictMentor` does not have any extensions that are enabled by default. This\nis because some extensions need some additional arguments passed that control their behaviour. If you bind no extensions\non your own and augment a dictionary, it will actually do nothing and return the dictionary as it is.\n\n**Example usage:**\n\n```python\nimport os\nfrom dictmentor import DictMentor, extensions as ext, utils\n\n\nbase_path = os.path.dirname(__file__)\ndm = DictMentor(\n ext.Environment(),\n ext.ExternalResource(base_path=base_path),\n ext.ExternalYamlResource(base_path=base_path)\n)\n\nyml = \"\"\"\nproducts:\n - external: item1.yaml\n - external: item2.yaml\nhome_directory: \"{{env::HOME}}\"\nextraction_sql: \"{{external::products.sql}}\"\n\"\"\"\n\nwith utils.modified_environ(HOME=\"/home/pi\"):\n res = dm.load_yaml(yml)\n\nfrom pprint import pprint\npprint(res)\n\n# Result:\n# {'extraction_sql': '-- Contents of products.sql\\nSELECT *\\nFROM products\\n;',\n# 'home_directory': '/home/pi',\n# 'products': [{'item1': {'price': 50, 'stock': 100}},\n# {'item2': {'price': 99, 'stock': 10}}]}\n\n```\n\nFor a list of provided extensions please see the chapter Extensions. You can easily write your own extensions as well.\nPlease see existing extensions for a how-to.\n\n\n\n\n## 3\\. Extensions\n\n\n\n### 3.1\\. Variables\n\nAugment the given dictionary by resolving pre-defined variables on the fly\n\nExample\n\n```python\n# Import DictMentor and extensions\nimport dictmentor.extensions as ext\nfrom dictmentor import DictMentor, utils\n\nyml = \"\"\"\nstatements:\n my_env: \"{{var::my_env}}\"\n home: \"{{var::home}}\"\n unknown: \"{{var::unknown}}\"\n combined: \"{{var::my_env}}@{{var::home}}\"\n\"\"\"\n\nvar_ext = ext.Variables(\n my_env='development',\n home=\"/home/pi\",\n)\nresult = DictMentor().bind(var_ext).load_yaml(yml)\n\nfrom pprint import pprint\npprint(result)\n\n# Result:\n# {'statements': {'combined': 'development@/home/pi',\n# 'home': '/home/pi',\n# 'my_env': 'development',\n# 'unknown': 'none'}}\n\n```\n\n\n\n### 3.2\\. Environment\n\nAugment the given dictionary by resolving environment variables on the fly\n\nExample\n\n```python\n# Import DictMentor and extensions\nimport dictmentor.extensions as ext\nfrom dictmentor import DictMentor, utils\n\nyml = \"\"\"\nstatements:\n my_env: \"{{env::MY_ENV}}\"\n home: \"{{env::HOME}}\"\n unknown: \"{{env::UNKNOWN}}\"\n with_default: \"{{env::UNKNOWN:=the_default}}\"\n\"\"\"\n\n# Make sure that MY_ENV is set and that UNKNOWN is unset\nwith utils.modified_environ(\"UNKNOWN\", MY_ENV='development'):\n result = DictMentor().bind(ext.Environment()).load_yaml(yml)\n\nfrom pprint import pprint\npprint(result)\n\n# Result:\n# {'statements': {'home': '/home/pi',\n# 'my_env': 'development',\n# 'unknown': 'none'\n# 'with_default': 'the_default'}}\n\n```\n\n\n\n### 3.3\\. ExternalResource\n\nAugment the given dictionary by resolving files on disk (whether absolute or relative) and integrating their content.\nIf the path to the file is specified in a relative manner you should pass a `base_path` to the `ExternalResource`\ninstance when instantiating it. Otherwise the current working directory will be assumed.\n\nExample\n\n```sql\n-- Contents of all.sql\nSELECT *\nFROM foo\n;\n```\n\n```sql\n-- Contents of single.sql\nSELECT *\nFROM foo\nWHERE id = {placeholder}\n;\n```\n\n```python\n# Import DictMentor and extensions\nimport dictmentor.extensions as ext\nfrom dictmentor import DictMentor\n\nimport os\nbase_path = os.path.dirname(__file__)\n\nyml = \"\"\"\nstatements:\n all: \"{{external::all.sql}}\"\n single: \"{{external::single.sql}}\"\n\"\"\"\n\nresult = DictMentor().bind(ext.ExternalResource(base_path)).load_yaml(yml)\n\nfrom pprint import pprint\npprint(result)\n\n# Result:\n# {'statements': {'all': '-- Contents of all.sql\\nSELECT *\\nFROM foo\\n;',\n# 'single': '-- Contents of single.sql\\nSELECT *\\nFROM foo\\nWHERE id = {placeholder}\\n;'}}\n\n```\n\n\n\n### 3.4\\. ExternalYamlResource\n\nAugment the given dictionary by resolving by yaml file on disk (whether absolute or relative) and integrating\nits content (as a dictionary) as the current node. The yaml's contents will be augmented as well.\n\nIf the path to the file is specified in a relative manner you should pass a `base_path` to the `ExternalYamlResource`\ninstance when instantiating it. Otherwise the current working directory will be assumed.\n\nExample\n\n```yaml\n# Contents of inner.yaml\ninner:\n item1:\n item2:\n external: item3.yaml\n```\n\n```yaml\n# Contents of item3.yaml\nitem2:\n price: 50 # You may also update nodes from the parent node\nitem3:\n price: 100\n count: 5\n sold: 200\n```\n\n```python\n# Import DictMentor and extensions\nimport dictmentor.extensions as ext\nfrom dictmentor import DictMentor\n\nimport os\nbase_path = os.path.dirname(__file__)\n\nyml = \"\"\"\nstatements:\n external: \"inner.yaml\"\n\"\"\"\n\nresult = DictMentor().bind(ext.ExternalYamlResource(base_path=base_path)).load_yaml(yml)\n\nfrom pprint import pprint\npprint(result)\n\n# Result:\n# {'statements': {'inner': {'item1': None,\n# 'item2': {'price': 50},\n# 'item3': {'count': 5, 'price': 100, 'sold': 200}}}}\n\n```", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/HazardDede/dictmentor", "keywords": "dict dictionary augmentation augment style", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "dictmentor", "package_url": "https://pypi.org/project/dictmentor/", "platform": "", "project_url": "https://pypi.org/project/dictmentor/", "project_urls": { "Documentation": "https://github.com/HazardDede/dictmentor/blob/master/README.md", "Homepage": "https://github.com/HazardDede/dictmentor", "Source": "https://github.com/HazardDede/dictmentor/", "Tracker": "https://github.com/HazardDede/dictmentor/issues" }, "release_url": "https://pypi.org/project/dictmentor/0.2.2/", "requires_dist": null, "requires_python": ">=3.4", "summary": "A python dictionary augmentation utility", "version": "0.2.2" }, "last_serial": 5315322, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "f53852fe8a33b099ce172691be7e345a", "sha256": "478469c368dd93f1efc241d42cc429c7af1b8a6f5eee89b6e9ffdce31733f261" }, "downloads": -1, "filename": "dictmentor-0.1.0.tar.gz", "has_sig": false, "md5_digest": "f53852fe8a33b099ce172691be7e345a", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.4", "size": 12742, "upload_time": "2018-10-07T18:25:28", "url": "https://files.pythonhosted.org/packages/f2/d4/466e5b169ca7a80d30c53fb1d8fdc29ed03008627d2061d263bd3dc6e011/dictmentor-0.1.0.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "b0a6f9a745b6b5e98e3b1da89ffa5a7d", "sha256": "dd3f067ca1e890b5382eeaeb237c50ccb21e2f9b2e7b1768df4934f03e8c5b6f" }, "downloads": -1, "filename": "dictmentor-0.2.0.tar.gz", "has_sig": false, "md5_digest": "b0a6f9a745b6b5e98e3b1da89ffa5a7d", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.4", "size": 13170, "upload_time": "2019-01-04T19:29:12", "url": "https://files.pythonhosted.org/packages/b7/cf/85a6728dec2b0153b350affdddbb7eebf2a15328e979c053bb467fdc064e/dictmentor-0.2.0.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "b6158b769ae2866a712408fb7e75ccf0", "sha256": "57235c286e3549e955164399344c5a00b59f1934758bd342b435454c011aac82" }, "downloads": -1, "filename": "dictmentor-0.2.1.tar.gz", "has_sig": false, "md5_digest": "b6158b769ae2866a712408fb7e75ccf0", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.4", "size": 16348, "upload_time": "2019-05-20T04:32:53", "url": "https://files.pythonhosted.org/packages/3d/6f/ce78211fc40e774f382b8d5d3dee1ab85eb971134f67c9b80017f3cd8a5c/dictmentor-0.2.1.tar.gz" } ], "0.2.2": [ { "comment_text": "", "digests": { "md5": "b3c3bb46a5b122a3ca11400d01977dd8", "sha256": "5d3e424af6be6361b2c8e0e0888c968b3ebbc2c9e074f796da182763667f5935" }, "downloads": -1, "filename": "dictmentor-0.2.2.tar.gz", "has_sig": false, "md5_digest": "b3c3bb46a5b122a3ca11400d01977dd8", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.4", "size": 16581, "upload_time": "2019-05-25T03:59:03", "url": "https://files.pythonhosted.org/packages/cf/7b/4cef82e3915877a69cc0736c1e22814ed6c3c01dd8be2f6edfde9727cf3f/dictmentor-0.2.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "b3c3bb46a5b122a3ca11400d01977dd8", "sha256": "5d3e424af6be6361b2c8e0e0888c968b3ebbc2c9e074f796da182763667f5935" }, "downloads": -1, "filename": "dictmentor-0.2.2.tar.gz", "has_sig": false, "md5_digest": "b3c3bb46a5b122a3ca11400d01977dd8", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.4", "size": 16581, "upload_time": "2019-05-25T03:59:03", "url": "https://files.pythonhosted.org/packages/cf/7b/4cef82e3915877a69cc0736c1e22814ed6c3c01dd8be2f6edfde9727cf3f/dictmentor-0.2.2.tar.gz" } ] }