{ "info": { "author": "Peter M. Elias", "author_email": "petermelias@gmail.com", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Internet :: WWW/HTTP :: Dynamic Content", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "# Valhalla\n[![Build Status](https://travis-ci.org/petermelias/valhalla.png?branch=master)](https://travis-ci.org/petermelias/valhalla) \n[![Coverage Status](https://coveralls.io/repos/petermelias/valhalla/badge.png?branch=master)](https://coveralls.io/r/petermelias/valhalla?branch=master) \n[![Downloads](https://pypip.in/d/valhalla/badge.png)](https://pypi.python.org/pypi/valhalla/) \n[![Downloads](https://pypip.in/v/valhalla/badge.png)](https://pypi.python.org/pypi/valhalla/)\n\nThe API is designed to afford the programmer the least amount of typing for each\nuse case, with the option to be more verbose when necessary.\n\nThere are 2 ways to build a schema:\n\n- Declarative\n- Dict-based\n\n### Declarative Schemas\n\n```python\n\nfrom valhalla import Schema\n\ns = Schema(match=['password', 'password_confirm'])\ns.email_address.email()\ns.first_name.text()\ns.last_name.text()\ns.password.text(min_len=8, max_len=20)\ns.password_confirm\ns.location.require(False)\n\n```\n\nNote: The field names are added dynamically, so long as you don't collide with any of the built-in ```Schema ``` attributes. Calling the field name is not necessary. Calling the filter functions IS necessary, as shown above.\n\nThe built-in ``` Schema ``` attributes are: [errors, valid, results, add_filter_chain, validate, reset] so collision should not be an issue.\n\n```python\n\ntest_data = {\n 'email_address': 'petermelias@gmail.com',\n 'first_name': 'Peter',\n 'last_name': 'Elias',\n 'password': '1234',\n 'password_confirm': '12345'\n}\n\ns.validate(test_data)\nassert_false(s.valid) # True\nassert_false(s.password.valid) # True\nprint s.password.errors # This field must match [password_confirm]\nassert_true(s.location.valid) # True, field is not required\n\nprint s.results # {u'email_address': u'petermelias@gmail.com'} etc... only yields valid values.\n\n# Field-wide options may specified at the Schema-level or at the Field-level, field-level takes precedence.\ns = Schema(require=['some_field'])\ns.some_field.require(False) # overrides the schema setting\n\n# a more useful example...\n\ns = Schema(require='all')\ns.i_am_required\ns.not_me_though.require(False)\n\n# Field-wide options: [blank, require, match, alts]\ns = Schema(match=[('match_me', 'to_me'), ('and_me', 'to_other_me')], \n\t\t blank='all', required='all', \n\t\t alts=[('match_me', 'some_random_name')])\n\n# these two must match\ns.match_me \ns.to_me\n\n# and these two must match\ns.and_me\ns.to_other_me\n\n# May also be used declaratively\ns = Schema()\ns.i_am_required.require(True) # all fields are required by default though\ns.i_can_be_blank.blank(True) # all fields CANNOT be blank by default\ns.i_should_match.match('i_am_required')\n\n'''\nThe difference between BLANK and REQUIRED is that a field must be included in the supplied DATA in order to be considered \"present\". If a value is not \"present\", and the field is required, an error is raised. If the value is \"present\", but BLANK (meaning some kind of empty value), and the field does NOT allow blanks, then an error is raised.\n\nSo, if a field is NOT REQUIRED, and NOT BLANK. Then you can omit the field entirely, but you cannot supply it with an empty value either.\n'''\ns.some_field.blank(False).require(False)\n# either supply me with a real value or leave me alone. this is the default.\n\n```\n### Dict-Based Schema Definitions (New in v0.0.7)\n\nSo these are really fun, especially if you are a functional programmer at heart...\n\n``` python\n\nmy_definition = {\n\t'email': ['require', ('alt', 'email_address'), 'email'], # email address with alternate name\n\t'age': ['require', 'numeric', ('range', 13, 100)] # age must be numeric between 13 and 100\n\t'password': [('text', 10, 50)],\n\t'password_confirm': [('match', 'password')]\n}\n\ns = Schema.from_dict(my_definition)\ns.validate(some_data) # Bam!\n\n```\n\nI know, really cool. Also probably really confusing if you didn't spot the pattern right away...\n\nExplanation: keys are field names, options follow in a list. If you want to call an option without arguments, \nsimply specify it as a string. If you want to call an option (filter or modifier) with arguments, you use a tuple.\n\nFor example, the following two blocks are equivalent:\n\n``` python\n\ns = Schema()\ns.my_happy_place.require().text(min_len=15, max_len=25)\n\n```\n\nsame as\n\n``` python\n\nsdict = {\n\t'my_happy_place': ['require', ('text', 15, 25)]\n}\n\ns = Schema.from_dict(sdict)\n\n```\n\nThe only and obvious downside of dict-based definitions is that they require you to know the argument order of most of the filters. Luckily, most filters do not even take arguments and the ones that do are fairly obvious / intuitive / documented :)\n\nThe ``` from_dict ``` method takes ``` **kwargs ``` so you can just pass your Schema level options like ``` force_unicode=True ``` there.\n\n### Schema API\n\n```python\n@classmethod\nSchema.from_dict(cls, dict_schema, **kwargs)\n\nSchema.__init__(self, match=[], require=[], blank=[],\n\t\t\t\talts=[], extras='discard', force_unicode=True,\n\t\t\t\tstrip_missing=True, strip_blank=True)\n@property\nSchema.errors\n\n@property\nSchema.valid\n\n@property\nSchema.results\n\nSchema.add_filter_chain(self, name, filter_chain)\n\nSchema.validate(self, data_dict, **kwargs)\n\nSchema.reset(self)\n\n```\n\n### Filters (validators)\n\nThere are currently 42 filter functions (validators) in this library. They are spread across modules categorically, but all end up in the same namespace because of the dynamic lookup system used for the API. This is not really much of an issue, since the filters use (and will continue to use) non-ambiguous names.\n\nThe list of filters is as follows, by category:\n\n### Web\n* email\n* ipv4\n* url\n* uri\n* cidr4\n* cidr6\n* macaddress\n\n### Money\n* credit_card(brands=[])\n\n### Strings\n* text\n* alphanumeric\n* alpha\n* numeric_string\n* nonblank\n* removespaces\n* strip\n* lower\n* upper\n* regex\n* canonize\n* slugify\n\n### Numerical\n* range(low, high)\n* minimum(number)\n* maximum(number)\n* between(low, high)\n* equal(number)\n* zero\n\n### Logical\n* constant\n\n### Constant\n* drop_keys\n* contains\n\n### Chrono\n* date(format='%m/%d/%Y')\n* time(format='%I:%M:%S')\n* datetime(format='%m/%d/%Y %I:%M:%S')\n* time_before(deadline)\n* time_after(milestone)\n* time_between(milestone, deadline)\n\n### Casting\n* boolean\n* strbool\n* integer\n* longint\n* numeric\n* string\n* none", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/petermelias/valhalla", "keywords": "", "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "valhalla", "package_url": "https://pypi.org/project/valhalla/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/valhalla/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/petermelias/valhalla" }, "release_url": "https://pypi.org/project/valhalla/0.1.4/", "requires_dist": null, "requires_python": null, "summary": "A slim validation library with a very elegant API designed to afford the least amount of typing.", "version": "0.1.4" }, "last_serial": 1176364, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "fd76a4a4e6799766dd7d07e426c557c0", "sha256": "77cc312b8a8de3e43abbc20a94fbb691770438a454dea07330fa0b3b1915eb16" }, "downloads": -1, "filename": "valhalla-0.0.1.tar.gz", "has_sig": false, "md5_digest": "fd76a4a4e6799766dd7d07e426c557c0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6703, "upload_time": "2013-09-06T09:26:04", "url": "https://files.pythonhosted.org/packages/4e/8c/395bd9f5bde0eeb3315ef2bbbd81f93ea8091ca1fc188ad1082fbae4f625/valhalla-0.0.1.tar.gz" } ], "0.0.10": [ { "comment_text": "", "digests": { "md5": "1b13716008f9ecc4723578fbe8e47dfa", "sha256": "43d3680777579809b65542526060a4ee19f0689673bcb5b873d616a17d70914d" }, "downloads": -1, "filename": "valhalla-0.0.10.tar.gz", "has_sig": false, "md5_digest": "1b13716008f9ecc4723578fbe8e47dfa", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17118, "upload_time": "2013-10-31T07:52:05", "url": "https://files.pythonhosted.org/packages/0a/38/c4f93f19a8b5406620a315db977fb3f376c45897cd6beb680f4edd70a2f0/valhalla-0.0.10.tar.gz" } ], "0.0.11": [ { "comment_text": "", "digests": { "md5": "a2b9d90324d6b10bd41836d9ef7cad65", "sha256": "64dec42f66c2f1b731d9971ae78c616a79ee4bf411b036b835dd6587fe20c330" }, "downloads": -1, "filename": "valhalla-0.0.11.tar.gz", "has_sig": false, "md5_digest": "a2b9d90324d6b10bd41836d9ef7cad65", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17109, "upload_time": "2013-11-01T13:10:52", "url": "https://files.pythonhosted.org/packages/d3/c2/edc85cd3f5a2d905f2c9fda3d2cf759d809cac72b581b3bb0a5bb654b59e/valhalla-0.0.11.tar.gz" } ], "0.0.12": [ { "comment_text": "", "digests": { "md5": "9ef16e1ed4e862356788f9ea4a42fcdb", "sha256": "55aa8ca1e0d3c8e3c7485e33ec1be61f2435744dd124ff1294b3ec71226c04cd" }, "downloads": -1, "filename": "valhalla-0.0.12.tar.gz", "has_sig": false, "md5_digest": "9ef16e1ed4e862356788f9ea4a42fcdb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17111, "upload_time": "2013-11-01T13:16:50", "url": "https://files.pythonhosted.org/packages/a2/9d/88acf016b061112e96934cf46808737c529cdcb1bf405a243a4f3101b8ab/valhalla-0.0.12.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "6ab4e859aaee25866ae345532c6a6bc9", "sha256": "36fa839419dfd86fbcb69f65cb758686e2924a16e8f199d86ad22c8153d37e32" }, "downloads": -1, "filename": "valhalla-0.0.2.tar.gz", "has_sig": false, "md5_digest": "6ab4e859aaee25866ae345532c6a6bc9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6109, "upload_time": "2013-09-09T23:24:44", "url": "https://files.pythonhosted.org/packages/96/46/53c35bd20f106fe942f5b7dc39441bacc184355d913844f27f27a4d6099a/valhalla-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "f112a128f430fbdd1f701f5870e5b73e", "sha256": "fc25036f3ccc8c771b4a1bcb19bd03f2f8abc75f9dc2dcbca06a8ddc58427757" }, "downloads": -1, "filename": "valhalla-0.0.3.tar.gz", "has_sig": false, "md5_digest": "f112a128f430fbdd1f701f5870e5b73e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9308, "upload_time": "2013-10-06T15:17:05", "url": "https://files.pythonhosted.org/packages/a8/b5/10e9ae49e06ec34532212131715c7a5e7eec0f85fd97191854ac0b49c2a1/valhalla-0.0.3.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "7ebea7432ca17a4e95e2a6bd2bb1751e", "sha256": "11d2be1525881f239b9b43dae7c05e5cff6b2e4ca03de4265f65de2a6db0c0cc" }, "downloads": -1, "filename": "valhalla-0.0.4.tar.gz", "has_sig": false, "md5_digest": "7ebea7432ca17a4e95e2a6bd2bb1751e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12139, "upload_time": "2013-10-15T18:58:45", "url": "https://files.pythonhosted.org/packages/92/45/aa28b439da0543145e8ab32ace79d471f89a35918b8cec4d1579721a73da/valhalla-0.0.4.tar.gz" } ], "0.0.6": [ { "comment_text": "", "digests": { "md5": "9da535549fe75b8cf2bb6fa83f7fbac6", "sha256": "12b9116ed6a1adb491ad6241829d4c82f4ef5705164d12d88f456e49b82938f5" }, "downloads": -1, "filename": "valhalla-0.0.6.tar.gz", "has_sig": false, "md5_digest": "9da535549fe75b8cf2bb6fa83f7fbac6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15256, "upload_time": "2013-10-22T19:01:43", "url": "https://files.pythonhosted.org/packages/50/9f/f37350dd84d09e0ec34204a855299629d553f36b08d4556d79efe9992ca4/valhalla-0.0.6.tar.gz" } ], "0.0.7": [ { "comment_text": "", "digests": { "md5": "7c43b61df885fca7ba82656afcc4586b", "sha256": "1a99bd18706ff0bcb2dbc4a77c9f44a70ec0e22d57bdae0c701653970eb7f988" }, "downloads": -1, "filename": "valhalla-0.0.7.tar.gz", "has_sig": false, "md5_digest": "7c43b61df885fca7ba82656afcc4586b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16853, "upload_time": "2013-10-22T21:44:31", "url": "https://files.pythonhosted.org/packages/d6/65/08acf4351af2ccea0186741e5d837922e6f53fef5e24191e8c6c157bb9dd/valhalla-0.0.7.tar.gz" } ], "0.0.8": [ { "comment_text": "", "digests": { "md5": "7f08084b90be32ee29c4344b3fab40b4", "sha256": "c71c944285a7089e896bf6845113d28417002c2cf5f4b33c57a5c85220867b3f" }, "downloads": -1, "filename": "valhalla-0.0.8.tar.gz", "has_sig": false, "md5_digest": "7f08084b90be32ee29c4344b3fab40b4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17070, "upload_time": "2013-10-24T22:21:09", "url": "https://files.pythonhosted.org/packages/36/49/636032e2a313c3c6ccf40160435e26079c4dfa27f8f750e4fc074b9f9da4/valhalla-0.0.8.tar.gz" } ], "0.0.9": [ { "comment_text": "", "digests": { "md5": "a5cf0889c76bc3d1509d16489cf18024", "sha256": "620e453ba9cd3cb2ee718f626016d67e7d13def08fd8fd9be5c54d7e17a0ed27" }, "downloads": -1, "filename": "valhalla-0.0.9.tar.gz", "has_sig": false, "md5_digest": "a5cf0889c76bc3d1509d16489cf18024", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17098, "upload_time": "2013-10-26T00:07:36", "url": "https://files.pythonhosted.org/packages/06/f3/af141e9c73f46f5df2d6ca2cd727949347adefdf524cf40165566e42e8d3/valhalla-0.0.9.tar.gz" } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "df3132a383724b19c28ce6b96e717cfd", "sha256": "36a4b42e05abaa110b888500c2dc50aa0f4420edc6b8011a36d149053c602210" }, "downloads": -1, "filename": "valhalla-0.1.0.tar.gz", "has_sig": false, "md5_digest": "df3132a383724b19c28ce6b96e717cfd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17492, "upload_time": "2013-11-05T14:45:53", "url": "https://files.pythonhosted.org/packages/ac/f1/d73038a3222874e83de7b6abee1319c9a070f7324169b6586ac4282c4be1/valhalla-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "e904fc7886a600913792b242818f50e9", "sha256": "de8b32524a0dd315a7dd8e97be169e581c3cbac70db4bb5bc75f8e3c9a0c8831" }, "downloads": -1, "filename": "valhalla-0.1.1.tar.gz", "has_sig": false, "md5_digest": "e904fc7886a600913792b242818f50e9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17521, "upload_time": "2013-11-05T15:00:50", "url": "https://files.pythonhosted.org/packages/eb/ae/8799ed9fa091722f4b8ef6721a97d0482d6984d2d94723b34610b53abab3/valhalla-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "c582bf65399a6b3d43b4a65a4715fb87", "sha256": "02f372f1ca172ab2ed3eef132305bd9a9b4d680cd4cb8c4ae607591a98723f04" }, "downloads": -1, "filename": "valhalla-0.1.2.tar.gz", "has_sig": false, "md5_digest": "c582bf65399a6b3d43b4a65a4715fb87", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17514, "upload_time": "2013-11-05T15:22:31", "url": "https://files.pythonhosted.org/packages/45/01/77776e04d993a51098d3a32525b6b630f17bb294d986106c010e92643d5b/valhalla-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "a02ab319e1d93176bdbd9f8384ac6f37", "sha256": "b364d09301d4c6648a05575bea343135f93c370e510f58c2c79bde743a4b176b" }, "downloads": -1, "filename": "valhalla-0.1.3.tar.gz", "has_sig": false, "md5_digest": "a02ab319e1d93176bdbd9f8384ac6f37", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17738, "upload_time": "2014-01-09T02:52:39", "url": "https://files.pythonhosted.org/packages/81/00/2c5a731a4867cd6c529d2daeb20d7d4e568de784c38736465f3e9922a44c/valhalla-0.1.3.tar.gz" } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "953f23a089358c56057b88750f622382", "sha256": "9d6a28d4a7847cc1fcd0a963524dfa92b8b9cdc1ee690c1f801fba63d42ae92b" }, "downloads": -1, "filename": "valhalla-0.1.4.tar.gz", "has_sig": false, "md5_digest": "953f23a089358c56057b88750f622382", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14924, "upload_time": "2014-08-01T04:51:56", "url": "https://files.pythonhosted.org/packages/d7/3e/9bf2831662a234fee371f2d5e1a34cf3869a296fed40aefd0f73254d4172/valhalla-0.1.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "953f23a089358c56057b88750f622382", "sha256": "9d6a28d4a7847cc1fcd0a963524dfa92b8b9cdc1ee690c1f801fba63d42ae92b" }, "downloads": -1, "filename": "valhalla-0.1.4.tar.gz", "has_sig": false, "md5_digest": "953f23a089358c56057b88750f622382", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14924, "upload_time": "2014-08-01T04:51:56", "url": "https://files.pythonhosted.org/packages/d7/3e/9bf2831662a234fee371f2d5e1a34cf3869a296fed40aefd0f73254d4172/valhalla-0.1.4.tar.gz" } ] }