{ "info": { "author": "Osvaldo Santana Neto", "author_email": "dicteval@osantana.me", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy" ], "description": "\ndicteval\n========\n\nLibrary to evaluate expressions in dict/json objects.\n\n\nRequirements\n------------\n\n* Python 3.6+\n\n\nBasic Usage\n-----------\n\nModule ``dicteval`` will evaluate basic types with no modifications but it will\nevaluate dicts (or json objects) containing keys started with ``=`` (equal)\nsymbol as an expression:\n\n >>> from dicteval import dicteval\n >>> dicteval(3)\n 3\n >>> dicteval([3, 5])\n [3, 5]\n >>> dicteval((5, 3))\n [5, 3]\n >>> dicteval({\"=sum\": [3, 5]})\n 8\n >>> dicteval({\"=\": 5}) # = symbol alone is a 'nop' function\n 5\n\nYou can provide a dictionary with context to be used during evaluation process.\n\n >>> dicteval({\"=\": \"!{var}\"}, context={\"var\": 1.0})\n 1.0\n\nYou can also wrap your string content with ``@{}`` to force a Python ``eval()``\nwith the context provided:\n\n >>> dicteval({\"=sum\": [3, \"@{var + 2}\"]}, context={\"var\": 3})\n 8\n\n.. warning::\n This functionality will be removed (or changed) in future releases for\n security reasons.\n\n\nFunctions\n---------\n\nYou can use the following builtin functions in your expressions:\n\n\nFunction ``=any``\n'''''''''''''''''\n\nReturns ``True`` if any element of sequence is true.\n\n >>> dicteval({\"=any\": [1, 2, 3]})\n True\n >>> dicteval({\"=any\": [0, 0]})\n False\n\n\nFunction ``=eq``\n''''''''''''''''\n\nReturns ``True`` if all elements of sequence are equals:\n\n >>> dicteval({\"=eq\": [1, 1, 1, 1]})\n True\n\n\nFunction ``=if``\n''''''''''''''''\n\nEvaluates condition and returns first value if true, otherwise, returns second value.\nIf no false value is supplied, it is assumed to be ``None``.\n\n >>> dicteval({\"=if\": [{\"=\": \"@{var > 5}\"}, \"yes\", \"no\"]}, context={\"var\": 6})\n 'yes'\n >>> dicteval({\"=if\": [{\"=\": \"@{var > 5}\"}, \"yes\", \"no\"]}, context={\"var\": 4})\n 'no'\n >>> dicteval({\"=if\": [{\"=\": \"@{var > 5}\"}, \"yes\"]}, context={\"var\": 4})\n\n\nFunction ``=neq``\n'''''''''''''''''\n\nReturns ``True`` if elements of sequence are different:\n\n >>> dicteval({\"=neq\": [1, 1, 1, 5]})\n True\n\n\nFunction ``=`` (or ``nop``)\n'''''''''''''''''''''''''''\n\nReturns the same values passed as arguments:\n\n >>> dicteval({\"=\": [1, 2, 3, 4]})\n [1, 2, 3, 4]\n >>> dicteval({\"=nop\": \"spam\"})\n 'spam'\n\n\nFunction ``=not``\n'''''''''''''''''\n\nReturns the boolean inverse of argument:\n\n >>> dicteval({\"=not\": False})\n True\n >>> dicteval({\"=not\": True})\n False\n >>> dicteval({\"=not\": None})\n True\n >>> dicteval({\"=not\": \"XYZ\"})\n False\n\n\nFunction ``=sum``\n'''''''''''''''''\n\nReturns a number with the sum of arguments:\n\n >>> dicteval({\"=sum\": [3, 5]})\n 8\n\n\nFunction ``=mul``\n'''''''''''''''''\n\nReturns a number with the product of arguments:\n\n >>> dicteval({\"=mul\": [3, 5]})\n 15\n\n\nFunction ``=all``\n'''''''''''''''''\n\nReturn True if all elements of the iterable are true (or if the iterable is empty)\n\n >>> dicteval({\"=all\": (True, False)})\n False\n >>> dicteval({\"=all\": (True, True)})\n True\n\n\nFunction ``=divmod``\n''''''''''''''''''''\n\nReturns a tuple containing the quotient and remainder after division:\n\n >>> dicteval({\"=divmod\": [8,3]})\n (2, 2)\n >>> dicteval({\"=divmod\": [7.5,2.5]})\n (3.0, 0.0)\n\n\nFunction ``=zip``\n'''''''''''''''''\n\nReturn list of aggregate tuples constructed from elements of multiple iterables.\n\n >>> dicteval({\"=zip\": [[1, 2, 3], [4, 5], [6, 7, 8, 9]]})\n [(1, 4, 6), (2, 5, 7)]\n\n\nTo Do\n-----\n\n- Add more functions to the builtin language\n\n\nContribute\n----------\n\nTo contribute to `dicteval`: \n\n 1. Clone this repository and `cd` into it\n 2. Install dev dependencies with [pipenv](https://github.com/pypa/pipenv)\n ```bash\n pipenv install --dev\n ```\n 3. Create a branch, like `git checkout -b [feature_name]`\n 4. Git commit changes\n 5. Pull request\n\n\nLicense\n-------\n\nThis software is licensed under MIT license.\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/osantana/dicteval", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "dicteval", "package_url": "https://pypi.org/project/dicteval/", "platform": "", "project_url": "https://pypi.org/project/dicteval/", "project_urls": { "Homepage": "https://github.com/osantana/dicteval" }, "release_url": "https://pypi.org/project/dicteval/0.0.6/", "requires_dist": null, "requires_python": ">=3.7.0", "summary": "Evaluate expressions in dict/json objects", "version": "0.0.6" }, "last_serial": 4413823, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "2e323156d7cfababb7212820fbc7972a", "sha256": "6eb0c8a1c62ff19817141f509bd6d60a38f8bef0751157501c97300d7542ddd1" }, "downloads": -1, "filename": "dicteval-0.0.1.tar.gz", "has_sig": false, "md5_digest": "2e323156d7cfababb7212820fbc7972a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3250, "upload_time": "2018-04-12T03:53:24", "url": "https://files.pythonhosted.org/packages/61/57/c5a1d0ddc96d6a9e9022ec4b6c79de7986ea78066b8865d81548a16ff783/dicteval-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "afc856b836c01110859eb4e14c4b59ba", "sha256": "725bc335da7e54e22281d210df4b56a77c22123be81ba28ff66ff37e18bd21f1" }, "downloads": -1, "filename": "dicteval-0.0.2.tar.gz", "has_sig": false, "md5_digest": "afc856b836c01110859eb4e14c4b59ba", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3720, "upload_time": "2018-04-12T17:52:46", "url": "https://files.pythonhosted.org/packages/bb/88/789d5fe5122548d965df1e7379d639d77e52e463043955f4ebc302b4b137/dicteval-0.0.2.tar.gz" } ], "0.0.5": [ { "comment_text": "", "digests": { "md5": "48959197d58dfa12817545f76d27b0ea", "sha256": "3f4002e314bc84b3811d38e78736f164e28c7c7937ac1bae3ead468547e738b9" }, "downloads": -1, "filename": "dicteval-0.0.5-py3-none-any.whl", "has_sig": true, "md5_digest": "48959197d58dfa12817545f76d27b0ea", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 4709, "upload_time": "2018-10-25T05:53:51", "url": "https://files.pythonhosted.org/packages/14/e0/9b149b088a93f690280a8aa96300571be54d151472d4c146e6b935f48ea2/dicteval-0.0.5-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "4e9712ca8080b7defd6410467e0cbf0c", "sha256": "49a8f07ea8fc685be5e6c1862cd8b7805c475104dd5eebedba9c80cd359523ae" }, "downloads": -1, "filename": "dicteval-0.0.5.tar.gz", "has_sig": false, "md5_digest": "4e9712ca8080b7defd6410467e0cbf0c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4906, "upload_time": "2018-10-25T05:46:42", "url": "https://files.pythonhosted.org/packages/37/79/1d914ef0e710f426840526e9e68aa9191f1a8179d19c0434a62d43ddf283/dicteval-0.0.5.tar.gz" } ], "0.0.6": [ { "comment_text": "", "digests": { "md5": "fed2ff46255d4b9880ae506fae653b0d", "sha256": "8172c80b3ed259d18d4c622bb45b8a9e5fcc67845135e01619f415efb98ae87d" }, "downloads": -1, "filename": "dicteval-0.0.6-py3-none-any.whl", "has_sig": true, "md5_digest": "fed2ff46255d4b9880ae506fae653b0d", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7.0", "size": 4714, "upload_time": "2018-10-25T05:56:21", "url": "https://files.pythonhosted.org/packages/f7/06/9b69ad3d9ed100f849e4d212fd7c0d1d47a4b2129f170a261ed86661a550/dicteval-0.0.6-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "f6939600190005f50d6d037d77010f98", "sha256": "20ab0af2ac567f970ed82aadd9fcdbb63695a18be4cda112029b0fc4d1ed6933" }, "downloads": -1, "filename": "dicteval-0.0.6.tar.gz", "has_sig": true, "md5_digest": "f6939600190005f50d6d037d77010f98", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7.0", "size": 4912, "upload_time": "2018-10-25T05:56:24", "url": "https://files.pythonhosted.org/packages/fd/aa/48e49200798686d16aae8ecbb120f640ddc0d52ceb5a8be2616b3f50a43b/dicteval-0.0.6.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "fed2ff46255d4b9880ae506fae653b0d", "sha256": "8172c80b3ed259d18d4c622bb45b8a9e5fcc67845135e01619f415efb98ae87d" }, "downloads": -1, "filename": "dicteval-0.0.6-py3-none-any.whl", "has_sig": true, "md5_digest": "fed2ff46255d4b9880ae506fae653b0d", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7.0", "size": 4714, "upload_time": "2018-10-25T05:56:21", "url": "https://files.pythonhosted.org/packages/f7/06/9b69ad3d9ed100f849e4d212fd7c0d1d47a4b2129f170a261ed86661a550/dicteval-0.0.6-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "f6939600190005f50d6d037d77010f98", "sha256": "20ab0af2ac567f970ed82aadd9fcdbb63695a18be4cda112029b0fc4d1ed6933" }, "downloads": -1, "filename": "dicteval-0.0.6.tar.gz", "has_sig": true, "md5_digest": "f6939600190005f50d6d037d77010f98", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7.0", "size": 4912, "upload_time": "2018-10-25T05:56:24", "url": "https://files.pythonhosted.org/packages/fd/aa/48e49200798686d16aae8ecbb120f640ddc0d52ceb5a8be2616b3f50a43b/dicteval-0.0.6.tar.gz" } ] }