{ "info": { "author": "Gino Jacob", "author_email": "gvjacob@outlook.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# **Contracts for Python Functions**\n\nContracts can be used to validate the input or output of a function. Data flow among components can be hard to keep track or maintained, sometimes forcing us to write print statements everywhere trying to catch malformed data. This contracts library solves this by intercepting data that is piped into or out of a function and checking if they satisfy the specified requirements.\n\n\n## **Getting Started**\n\nInstall contracts through pip.\n\n```console\n$ pip3 install python-contracts\n```\n\nOnce contracts is installed, you can import the input and output contract decorators, and other convenient qualifier functions.\n\n```py\n# Imports ic (input contract) and oc (output contract) \nfrom contracts import ic, oc\n\n# Examples of some qualifiers\nfrom contracts import natural, integer\n```\n\nRefer to Qualifiers for list of available qualifiers.\n\n\n## **Contracts**\nInput contract is a function decorater that takes in kwargs as a mapping of parameter names to their qualifier(s).\n\nOutput contract is another decorator that takes in a single qualifier and checks the result of calling the decorated function.\n\n#### **Using Input Contract**\n```py\nfrom contracts import ic, natural\n\n@ic(val = natural)\ndef func(val):\n return val\n```\n*func* takes in \"val\" as a parameter. *ic*'s arguments should correspond to the function's parameter names. In this case, the contract states that arguments for \"val\" should be natural numbers.\n\n*ic* can take in as many arguments as the number of parameters for the decorated function. All keys should map to the correct parameter names. If the contract is violated, you will get an InputContractException error message listing out the arguments that failed and their given values.\n\n```\ncontracts.exceptions.InputContractException:\nArguments that failed the contracts\nval: -1\n```\n\n#### **Using Output Contract**\n```py\nfrom contracts import oc, natural\n\n@oc(natural)\ndef func(val):\n return val\n```\n*oc* validates the result of calling a function. In this case, it checks that the result is a natural number. The decorator takes a single qualifier. If the contract is violated, the following error will be given.\n```\ncontracts.exceptions.OutputContractException: The result of -1 broke the output contract\n```\n\n\n## **Qualifiers**\nQualifiers are functions that take in a single value and return `True` if conditions are satisfied, and `False` otherwise.\n\nFor convenience, the contracts library provides a range of basic qualifiers on some data types.\n\n* Numbers: number, positive_number, negative_number\n* Integers: integer, natural, positive_integer, negative_integer\n* Floats: floating_point, positive_float, negative_float\n\n#### **Composing Multiple Qualifiers**\n\nTo compose multiple qualifiers, you can import the *compose* function and pass as many qualifiers as needed to make a single qualifier.\n\n```py\nfrom contracts import natural, positive_integer, compose\n\n@ic(val = compose(natural, positive_integer))\ndef func(val):\n return val\n```\n\nThe input contract above will check that the argument for \"val\" is a natural number and a positive integer.\n\n#### **Custom Qualifiers**\nUsers of the library can plug in their own qualifiers as long as they adhere to the right data signature. If you're using this library throughout your code base, writing your collection of qualifiers in a separate file will keep things clean.\n\n\n## **Built With**\nContracts library is built with Python 3.6. Code has been tested only in this version. Compatibility with other versions has not been tested.\n\nLibraries used:\n* [inspect](https://docs.python.org/3.6/library/inspect.html)\n* [functools](https://docs.python.org/3.6/library/functools.html)\n* [pytest](https://docs.pytest.org/en/latest/)\n\n\n## Author\nGino Jacob - [Github](https://github.com/gvjacob)\n\nFeedback is very much welcomed. Please write issues.\n\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details\n\n\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/gvjacob/contracts", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "python-contracts", "package_url": "https://pypi.org/project/python-contracts/", "platform": "", "project_url": "https://pypi.org/project/python-contracts/", "project_urls": { "Homepage": "https://github.com/gvjacob/contracts" }, "release_url": "https://pypi.org/project/python-contracts/0.1.4/", "requires_dist": null, "requires_python": "", "summary": "Function contracts for Python", "version": "0.1.4" }, "last_serial": 4789160, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "79a8a964081cac8929972d487d1fad57", "sha256": "a9794d8a2d34c0e17c67ff82b57c639e982ff91beb557e57f9521a819283b647" }, "downloads": -1, "filename": "python_contracts-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "79a8a964081cac8929972d487d1fad57", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6941, "upload_time": "2018-12-20T23:38:17", "url": "https://files.pythonhosted.org/packages/9b/2e/a4e44c4157af885cf0a240b6bece21f71a4b8278f3ea99c288aeb9395be9/python_contracts-0.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6cb7e54c81400181d8cb4cdcaaa2d834", "sha256": "e1eb0722d93a36443c39c2134a290142720ed3e7d29ec65cbecb286765c389e6" }, "downloads": -1, "filename": "python-contracts-0.0.1.tar.gz", "has_sig": false, "md5_digest": "6cb7e54c81400181d8cb4cdcaaa2d834", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4474, "upload_time": "2018-12-20T23:38:20", "url": "https://files.pythonhosted.org/packages/f9/a5/9eb7c89bb533f5edd5f02d452304d4ef1ee98bd4bf8066002286434da34a/python-contracts-0.0.1.tar.gz" } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "f87689af2247b827baf9b245bfe98ae0", "sha256": "6d93508179f72be8f9d6dbf5052428ec50877e14752d6480fb712f8f56891149" }, "downloads": -1, "filename": "python_contracts-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "f87689af2247b827baf9b245bfe98ae0", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6917, "upload_time": "2018-12-20T23:48:52", "url": "https://files.pythonhosted.org/packages/de/e9/b15d290b4c2df0c38273875d8d5047520894aa3e7f93c5c3c030bc61a23b/python_contracts-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "10b4c653a1dfc17c48e01bc8dd4f6cc5", "sha256": "6f568dd911a2fdb4ab4f91bde89aa872696386150b155812c3842be9bcd2d476" }, "downloads": -1, "filename": "python-contracts-0.1.0.tar.gz", "has_sig": false, "md5_digest": "10b4c653a1dfc17c48e01bc8dd4f6cc5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4462, "upload_time": "2018-12-20T23:48:54", "url": "https://files.pythonhosted.org/packages/dc/d6/4110f110c6386070727f10e63ab2cbef5948f906cd7180f6c958573e9399/python-contracts-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "fe5f9fadaaecbe2029d782c61d3bf51b", "sha256": "87b57139df2879f4fb7978af9c673cfda9652dd8d2245814c341a78e04f0145a" }, "downloads": -1, "filename": "python_contracts-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "fe5f9fadaaecbe2029d782c61d3bf51b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5869, "upload_time": "2018-12-21T00:52:24", "url": "https://files.pythonhosted.org/packages/ba/4c/d69391691a04d6c2fbb8e182c68144e94a13a872164dcc0ce7222fc9eb25/python_contracts-0.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "48c6c410a5b3adf08f9a55a17f8350d9", "sha256": "4a7b25b82b4d82f33f5abfae1c5d05726806ccff12f1b5b2a975b8478a8c5573" }, "downloads": -1, "filename": "python-contracts-0.1.1.tar.gz", "has_sig": false, "md5_digest": "48c6c410a5b3adf08f9a55a17f8350d9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4283, "upload_time": "2018-12-21T00:52:25", "url": "https://files.pythonhosted.org/packages/74/16/b7e87d5177bf301e237ec2d3c6980bfedfbf5dd3cc51411e365ef9623433/python-contracts-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "5e1698eb8ec993191cd180a7d6bd7437", "sha256": "5e81b51b440008fbc2d20b76b188ad1f5ffbc88048615e2ba597571faddeab43" }, "downloads": -1, "filename": "python_contracts-0.1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "5e1698eb8ec993191cd180a7d6bd7437", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7995, "upload_time": "2019-02-06T05:49:02", "url": "https://files.pythonhosted.org/packages/c4/d7/88072abb090d35807c6132c0a17a16985132b00e36b08a307f1e20d28e33/python_contracts-0.1.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "22321699e8d0989efb1c52e762ba5f7b", "sha256": "c8e80b66e6b25fc117f180fe16fa06c0156a39d4f2c0b94d537fd03a2e4d02f9" }, "downloads": -1, "filename": "python-contracts-0.1.2.tar.gz", "has_sig": false, "md5_digest": "22321699e8d0989efb1c52e762ba5f7b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5731, "upload_time": "2019-02-06T05:49:04", "url": "https://files.pythonhosted.org/packages/db/a9/803c3fc5fd146cba5a69ee85496829f330a075eaf80f68baa1edec322267/python-contracts-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "f003b4efdafebca1011a76a968a6f927", "sha256": "5ef43606713f0e57ee30da98e6cd01df68bc9433e61e305de5a69a28efff2465" }, "downloads": -1, "filename": "python_contracts-0.1.3-py3-none-any.whl", "has_sig": false, "md5_digest": "f003b4efdafebca1011a76a968a6f927", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7903, "upload_time": "2019-02-06T05:52:17", "url": "https://files.pythonhosted.org/packages/95/fa/20d55deeace7cbd524d56e1cb3990af546967de2cc1e0e8319b12098f321/python_contracts-0.1.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "f11c6d1470e73a9f2cdac9ec333a483a", "sha256": "d52da9525ad1bda42973e6ff52648c48e35a6a3079c57eca40294a453aee91be" }, "downloads": -1, "filename": "python-contracts-0.1.3.tar.gz", "has_sig": false, "md5_digest": "f11c6d1470e73a9f2cdac9ec333a483a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5625, "upload_time": "2019-02-06T05:52:18", "url": "https://files.pythonhosted.org/packages/47/a2/dc0ca4e0e5816f1b511c03208d7c25dcfd86aad4ab1104b474098dba88ef/python-contracts-0.1.3.tar.gz" } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "7013ade172771448a07a722c1e7a7e2e", "sha256": "7d440913897c7090fabb38d562efdb433bfe0f2cdcd516808fe53e25940d5e12" }, "downloads": -1, "filename": "python_contracts-0.1.4-py3-none-any.whl", "has_sig": false, "md5_digest": "7013ade172771448a07a722c1e7a7e2e", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 8049, "upload_time": "2019-02-07T00:36:13", "url": "https://files.pythonhosted.org/packages/9a/20/25d212011451355a8a87bb2c5b299e8ae0e8c77e80ba28e038d1233ac48c/python_contracts-0.1.4-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "9f4fa42f3db3dd5ac41e711752b2fbcd", "sha256": "53a53e0b5fe62f05c4e947bc75e5f2933135b4c06c804f5cf88e0de66baf57f9" }, "downloads": -1, "filename": "python-contracts-0.1.4.tar.gz", "has_sig": false, "md5_digest": "9f4fa42f3db3dd5ac41e711752b2fbcd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5747, "upload_time": "2019-02-07T00:36:15", "url": "https://files.pythonhosted.org/packages/15/81/e436967f34250570e8c2632723f26aec1958f75fef160a9aa0dcff98301d/python-contracts-0.1.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "7013ade172771448a07a722c1e7a7e2e", "sha256": "7d440913897c7090fabb38d562efdb433bfe0f2cdcd516808fe53e25940d5e12" }, "downloads": -1, "filename": "python_contracts-0.1.4-py3-none-any.whl", "has_sig": false, "md5_digest": "7013ade172771448a07a722c1e7a7e2e", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 8049, "upload_time": "2019-02-07T00:36:13", "url": "https://files.pythonhosted.org/packages/9a/20/25d212011451355a8a87bb2c5b299e8ae0e8c77e80ba28e038d1233ac48c/python_contracts-0.1.4-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "9f4fa42f3db3dd5ac41e711752b2fbcd", "sha256": "53a53e0b5fe62f05c4e947bc75e5f2933135b4c06c804f5cf88e0de66baf57f9" }, "downloads": -1, "filename": "python-contracts-0.1.4.tar.gz", "has_sig": false, "md5_digest": "9f4fa42f3db3dd5ac41e711752b2fbcd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5747, "upload_time": "2019-02-07T00:36:15", "url": "https://files.pythonhosted.org/packages/15/81/e436967f34250570e8c2632723f26aec1958f75fef160a9aa0dcff98301d/python-contracts-0.1.4.tar.gz" } ] }