{
"info": {
"author": "Josef Lange",
"author_email": "josef.d.lange@me.com",
"bugtrack_url": null,
"classifiers": [
"License :: OSI Approved :: MIT License",
"Topic :: Utilities"
],
"description": "``validict``\n============\n\nDescription\n-----------\n\n``validict`` is a Python module for comparing an unknown value to a\ndesired template. It is intended for the top-level type to be a\n``dict``, but should be flexible enough to deal with ``list``\\ s or\nscalars (though if you're dealing at scalars, might I suggest running\naway from this and just using Python's ``isinstance``). *Important: this\nlibrary specifically does not treat ``tuple``\\ s as template\nexpectations but instead as a set of expectations for a given position\nin a template.*\n\nUsage\n-----\n\nInstall with `pip `__.\n\n::\n\n shell~$ pip install validict\n\nUsing ``validict`` is simple. First, declare your template:\n\n.. code:: python\n\n from validict import validate\n\n template = {\n 'name': str,\n 'age': int,\n 'pets': [\n {\n 'name': str,\n 'kind': str\n }\n ],\n 'parents': ([{'name': str}], int, None)\n }\n\n kid = {\n 'name': \"Bart Simpson\",\n 'age': 10,\n 'pets': [\n {'name': \"Santa's Little Helper\", 'kind': \"Dog\"},\n {'name': \"Snowball II\", 'kind': \"Cat\"}\n ],\n 'parents': [\n {'name': \"Homer Simpson\"},\n {'name': \"Marge Simpson\"}\n ]\n }\n\n validate(template, kid) # returns True\n\n bad_kid = {\n 'name': \"Nelson Muntz\",\n 'age': 12\n }\n\n validate(template, bad_kid) # raises FailedValidationError\n validate(template, bad_kid, quiet=True) # returns False\n\n optional_kid = {\n 'name': \"Milhouse Van Houten\",\n 'age': 10,\n 'pets': [\n {'name': \"Lhasa Apso\", 'kind': \"Dog\"}\n ],\n 'parents': None # Okay, not really, but for demonstration purposes...\n }\n\n validate(template, optional_kid) # returns True\n\nYou might be asking yourself -- or me -- \"what the hell is this\ngarbage?\" Allow me to briefly explain, and you'll see that the template\nlanguage is pretty simple.\n\n1. We use plain, naked Python ``type``\\ s to indicate that the expected\n value for the given key should be an object of that type. So, if the\n passed-in dict has a value for ``'name'`` that isn't a ``str``,\n validation fails.\n\n2. When we are expecting a ``list`` of elements, we only need to declare\n in our template one instance of that item, if the ``list``'s children\n are expected to be homogenous. Therefore, ``'pets'`` is expected to\n be a ``list`` of ``dict``\\ s, all containing ``str`` value for keys\n ``'name'`` and ``'kind'``.\n\n3. We can use a ``tuple`` to declare that there may be multiple types of\n values, even including (but not demonstrated) further depth of\n structure. In the above, the value of ``'parents'`` can be a ``dict``\n with parents' names, an ``int`` (perhaps representing the number of\n parents), or ``None`` (if you're Batman).\n\n4. Calling ``validate`` with the template and unvalidated value,\n positionally, will result either in a return value of ``True`` or a\n raise of ``FailedValidationError``.\n\n5. Calling ``validate`` as above with the keyword parameter\n ``quiet=True`` will return ``False`` instead of raising\n ``FailedValidationError`` on validation failure.\n\n6. Allowing a ``None`` type as a ``dict`` value or as a member of a\n ``tuple`` signifies that the value is optional. Using it in a\n ``tuple`` allows you to declare that the value can either be matching\n some type or otherwise can be nothing at all.\n\n7. (*Undemonstrated*) Your template can declare scalar values as well.\n So if all inputs must have some specific K/V pair, you can declare\n that.\n\nWhy do I want to use this?\n--------------------------\n\nIf you're using a web framework like, say,\n`Falcon `__ and you wanted to set up a\n`before hook `__\nto validate the body of the incoming HTTP request, the function in this\nmethod is for you. At least that's why it's for me.\n\nBonus!\n------\n\nThere is an experimental (read: *not heavily tested*) function in this\nmodule called ``deep_merge``, which takes as its arguments two\ndictionaries. The second will be merged into the first, in a fashion\nsuch that keys are merged on every level instead of top-level key-values\nclobbering over all nested data.",
"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/josefdlange/validict",
"keywords": "validation dictionary validate valid list json request validator",
"license": "MIT",
"maintainer": null,
"maintainer_email": null,
"name": "validict",
"package_url": "https://pypi.org/project/validict/",
"platform": "UNKNOWN",
"project_url": "https://pypi.org/project/validict/",
"project_urls": {
"Download": "UNKNOWN",
"Homepage": "https://github.com/josefdlange/validict"
},
"release_url": "https://pypi.org/project/validict/1.5/",
"requires_dist": null,
"requires_python": null,
"summary": "A simple validation module",
"version": "1.5"
},
"last_serial": 1906449,
"releases": {
"1.0": [],
"1.1": [],
"1.2": [
{
"comment_text": "",
"digests": {
"md5": "613195cd518426399ae06732e53bf248",
"sha256": "9060640f0bff78384b5efd70660761922c657b2f0e123b0e2e83fbf17697a0b0"
},
"downloads": -1,
"filename": "validict-1.2.tar.gz",
"has_sig": false,
"md5_digest": "613195cd518426399ae06732e53bf248",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4066,
"upload_time": "2015-05-08T22:40:01",
"url": "https://files.pythonhosted.org/packages/c9/c7/b60acfd0c5e6a0ae86c57e5720a7c9d80b603a26c2eea382efeff589f8de/validict-1.2.tar.gz"
}
],
"1.3": [
{
"comment_text": "",
"digests": {
"md5": "7c73e7dc626d739faece582968b1f948",
"sha256": "89095e3b6be3e6d875aace3c77e59a9677b195543affae5c4ff8a0e2768b0552"
},
"downloads": -1,
"filename": "validict-1.3.tar.gz",
"has_sig": false,
"md5_digest": "7c73e7dc626d739faece582968b1f948",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4149,
"upload_time": "2015-05-09T23:37:35",
"url": "https://files.pythonhosted.org/packages/56/06/c911316fea00df1401bd843ea8d7f803bd43dead6d9282dcbc769135f013/validict-1.3.tar.gz"
}
],
"1.4": [
{
"comment_text": "",
"digests": {
"md5": "0b9e708de2fbde87e63fe027ee179ee5",
"sha256": "1974fa52ed65064f466137ce54f1821e1cd5460fa11a7fe683facf99c51b3646"
},
"downloads": -1,
"filename": "validict-1.4.tar.gz",
"has_sig": false,
"md5_digest": "0b9e708de2fbde87e63fe027ee179ee5",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4485,
"upload_time": "2015-05-21T01:56:19",
"url": "https://files.pythonhosted.org/packages/f2/a5/2214baafb4c89c4f52d31ba7e782cd15ed36b0bc69a7403daa2190a36a2b/validict-1.4.tar.gz"
}
],
"1.5": [
{
"comment_text": "",
"digests": {
"md5": "2c51fe4463df9a734e27184332cc7e2d",
"sha256": "2f8062400f552e827fb37349d880d7d4c7424f61b25961fcdc7f8e2b7e9c61f2"
},
"downloads": -1,
"filename": "validict-1.5.tar.gz",
"has_sig": false,
"md5_digest": "2c51fe4463df9a734e27184332cc7e2d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4692,
"upload_time": "2016-01-15T17:54:31",
"url": "https://files.pythonhosted.org/packages/0d/72/9a3d825512eddbf3effcd7df95c158f859889f99b678310be2fc53c64d71/validict-1.5.tar.gz"
}
]
},
"urls": [
{
"comment_text": "",
"digests": {
"md5": "2c51fe4463df9a734e27184332cc7e2d",
"sha256": "2f8062400f552e827fb37349d880d7d4c7424f61b25961fcdc7f8e2b7e9c61f2"
},
"downloads": -1,
"filename": "validict-1.5.tar.gz",
"has_sig": false,
"md5_digest": "2c51fe4463df9a734e27184332cc7e2d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4692,
"upload_time": "2016-01-15T17:54:31",
"url": "https://files.pythonhosted.org/packages/0d/72/9a3d825512eddbf3effcd7df95c158f859889f99b678310be2fc53c64d71/validict-1.5.tar.gz"
}
]
}