{ "info": { "author": "Jason Webb", "author_email": "bigjasonwebb@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 2.7" ], "description": "============================\nPython Data Contracts\n============================\nA declarative data contract container type for Python\n------------------------------------------------------\n\n*Pycontracts is currently an internal alpha and not ready for production use.*\n\n\nPython data contracts (pycontracts in PyPi) is a library for exchanging data between\nsystems. It is loosely based on the django forms api to help ease adoption. A simple example::\n\n from pycontract import DataContract, StringField, NumberField\n \n class Person(DataContract):\n name = StringField()\n phone = StringField(null=True)\n age = NumberField(null=True)\n \n bob = Person()\n bob[\"name\"] = \"Bob Smith\"\n bob[\"phone\"] = \"999-555-1234\"\n bob[\"age\"] = 32\n \nIn this example the contract for person is declared and the record for bob is instantiated. In \naddition to the basic data we can add ``processors`` which manipulate or clean the data as well \nas ``validators`` which validate the data similar to django validators.\n\n--------\nFeatures\n--------\n* Customizable validation (compatible with django validators).\n* Data processors to clean up and format data.\n* Declarative field definitions.\n* Enforced value assignment helps avoid regression errors.\n* Licensed under the `MIT License`_.\n\nBasic Usage\n-----------\nThe first step is define a basic contract. This is done by inheriting from ``pycontract.DataContract``. Next\nwe decide if there is standard processing that is needed for each field. For example we could use the \n``strip_white_space`` processor to call pythons ``strip`` on each value. Finally we decide if there is any \nextra validation that is needed on the values. For example to ensure that the persons name starts with an \"a\"\nwe could use the ``RegexValidator``. So with this information we would declare this DataContract like this::\n\n from pycontract import DataContract, StringField, NumberField, strip_white_space, RegexValidator\n \n class Person(DataContract):\n name = StringField(processors=(strip_white_space,), validators=(RegexValidator(r\"[aA].+\"),))\n phone = StringField(null=True)\n age = NumberField(null=True)\n\nNow at runtime we can set the values, check for a valid contract and finally access the values. That would like something\nlike this::\n\n\t>>> manny = Person()\n\t>>> manny[\"name\"] = \"Angel Man \"\n\t>>> manny[\"phone\"] = \"999555-1234\"\n\t>>> manny[\"age\"] = 22\n\t>>> manny.is_valid()\n\tTrue\n\t>>> print manny.name\n\t'Angel Man'\n\t\nThis is early release and the code base is very short, so for more information see the code. The source \ncode can be found at github_.\n\n.. _github: https://github.com/bigjason/pycontract\n.. _MIT License: http://en.wikipedia.org/wiki/MIT_License", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/bigjason/pycontract", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "pycontract", "package_url": "https://pypi.org/project/pycontract/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/pycontract/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/bigjason/pycontract" }, "release_url": "https://pypi.org/project/pycontract/0.1.4/", "requires_dist": null, "requires_python": null, "summary": "A data contracts system for python loosly modeled after django forms.", "version": "0.1.4" }, "last_serial": 797071, "releases": { "0.1.3": [ { "comment_text": "", "digests": { "md5": "80706a8faf469201e9f9fcee6279bea9", "sha256": "5cd53f2cbf93c4ae2a15fdf1828d33c860e1e11e584815bafb5c7e8d1e31dc72" }, "downloads": -1, "filename": "pycontract-0.1.3.tar.gz", "has_sig": false, "md5_digest": "80706a8faf469201e9f9fcee6279bea9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8671, "upload_time": "2010-11-22T18:24:07", "url": "https://files.pythonhosted.org/packages/b2/71/e70f3e940384e8bb0727884af0b0e423c27e5eddb02d143bbd15bac23c18/pycontract-0.1.3.tar.gz" } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "c1bb2766a1458f25eb87e425c75d1889", "sha256": "f08aa2cb2b3cf484c1d5c0e7dd5226d5a7beae9054c99822ecb977fa0c1a4de5" }, "downloads": -1, "filename": "pycontract-0.1.4.tar.gz", "has_sig": false, "md5_digest": "c1bb2766a1458f25eb87e425c75d1889", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8616, "upload_time": "2010-11-22T18:37:45", "url": "https://files.pythonhosted.org/packages/59/2b/27662e049928cbf246ac1898c6af5f1f45315a3c8e04807b2360fb450e25/pycontract-0.1.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "c1bb2766a1458f25eb87e425c75d1889", "sha256": "f08aa2cb2b3cf484c1d5c0e7dd5226d5a7beae9054c99822ecb977fa0c1a4de5" }, "downloads": -1, "filename": "pycontract-0.1.4.tar.gz", "has_sig": false, "md5_digest": "c1bb2766a1458f25eb87e425c75d1889", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8616, "upload_time": "2010-11-22T18:37:45", "url": "https://files.pythonhosted.org/packages/59/2b/27662e049928cbf246ac1898c6af5f1f45315a3c8e04807b2360fb450e25/pycontract-0.1.4.tar.gz" } ] }