{ "info": { "author": "Klimov Konstantin", "author_email": "moelius1983@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "==============\nData-validator\n==============\n\nValidator with feature to change unexpected values.\n\nFeatures\n--------\n\n- recursive validation dictionary values\n- expanding the list of validators with custom validators\n- ability to assign handler functions globally or on single validator to change unexpected values\n- ability to throw exceptions on first error or after complete validation process\n- ability to return unexpected results and info about them\n\nInstallation\n------------\n\nAs usually use pip:\n\n.. code-block:: bash\n\n pip install data-validator\n\nUsage examples\n--------------\n\nBasic dictionary validation:\n\n.. code-block:: python\n\n # user to validate\n user = {\n 'first_name': 'Very long name to validate',\n 'last_name': 'Smith',\n 'email': 'smith@gmail.com',\n 'second_email': 'bad email',\n 'address': {'state': 'Texas', 'city': 'Dallas'},\n 'career': [{'name': 'google', 'from': 2012, 'until': 'now'}, {'name': 'facebook', 'from': -1,\n 'until': 44444444444444}]\n }\n\n # We want to validate:\n # user['first_name'] and user['last_name'] length must be more then 2 and less then 10\n # user['email'] and user['second_email'] must match regex pattern r\"^[\\w\\.\\+\\-]+\\@[\\w]+\\.[a-z]{2,3}$\"\n # user['address']['state'] may be Texas, Alabama or Alaska and it case sensitive\n # user['address']['city'] may be New York, Los Angeles or Washington and it not case sensitive\n # user['career'][*]['from'] and user['career'][*]['until'] must be int16. P.s. * is list index\n\n # And if we have unexpected values we need to change them with handler function - lambda x: -1\n # and if user['career']['until'] is unexpected we need to change this with handler function - lambda x: -2\n\n # user validation rules\n rules = {\n 'first_name': [validators.StringLength([2, 10])],\n 'last_name': [validators.StringLength([2, 10])],\n 'email': [validators.Regex(r\"^[\\w\\.\\+\\-]+\\@[\\w]+\\.[a-z]{2,3}$\")],\n 'second_email': [validators.Regex(r\"^[\\w\\.\\+\\-]+\\@[\\w]+\\.[a-z]{2,3}$\")],\n 'address.state': [validators.Variants(['Texas', 'Alabama', 'Alaska'])],\n 'address.city': [validators.Variants(['New York', 'Los Angeles','Washington'], case_sensitive=False)],\n 'career.from': [validators.IntNumberType(numpy.int16)],\n 'career.until': [validators.IntNumberType(numpy.int16, handler=lambda x: -2)]\n }\n\n # validate user\n validator = Validator(rules, common_handler=lambda x: -1)\n validator_result = validator.validate(user)\n if not validator_result:\n [print(unexpected) for unexpected in validator.unexpected_values]\n\n # result will be\n # path: career.0.until, value: now, validator: , expected: , unexpected: \n # path: career.1.until, value: 2015555555, validator: , expected: , unexpected: \n # path: address.city, value: Dallas, validator: , expected: ['new york', 'los angeles'], unexpected: dallas\n # path: second_email, value: bad email, validator: , expected: ^[\\w\\.\\+\\-]+\\@[\\w]+\\.[a-z]{2,3}$, unexpected: bad email\n # path: first_name, value: Very long name to validate, validator: , expected: [2, 10], unexpected: 26\n\n # We can find original item in validator.original_item and changed dict in validator.processed_item:\n {\n 'first_name': -1,\n 'last_name': 'Smith',\n 'email': 'smith@gmail.com',\n 'second_email': -1,\n 'address': {'state': 'Texas', 'city': -1},\n 'career': [{'name': 'google', 'from': -1, 'until': -2}, {'name': 'facebook', 'from': -1, 'until': -2}]\n }\n\n\n", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/moelius/data-validator", "keywords": "", "license": "BSD", "maintainer": "", "maintainer_email": "", "name": "data-validator", "package_url": "https://pypi.org/project/data-validator/", "platform": "", "project_url": "https://pypi.org/project/data-validator/", "project_urls": { "Homepage": "https://github.com/moelius/data-validator" }, "release_url": "https://pypi.org/project/data-validator/0.1.2/", "requires_dist": null, "requires_python": "", "summary": "'Package for validate'", "version": "0.1.2" }, "last_serial": 3167140, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "564022b23d721611dd6bcf057645c2fb", "sha256": "f50cb751cfe2972f8c90a503d8fcaf9aac1223c1143a210c703a7ff5dee34ba4" }, "downloads": -1, "filename": "data-validator-0.1.0.tar.gz", "has_sig": false, "md5_digest": "564022b23d721611dd6bcf057645c2fb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5363, "upload_time": "2017-04-16T10:30:29", "url": "https://files.pythonhosted.org/packages/1e/e8/1a8ba900ae38f363c516e0a670715f1e4524e7da9abefeaedc7efc4e62a8/data-validator-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "7260fb4428784cdacdc1cccc73af43fe", "sha256": "cfb351e543d6f8c518a211d8f4330ea0a02330324742ba9d1770c20da250a339" }, "downloads": -1, "filename": "data-validator-0.1.1.tar.gz", "has_sig": false, "md5_digest": "7260fb4428784cdacdc1cccc73af43fe", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5376, "upload_time": "2017-04-16T11:29:32", "url": "https://files.pythonhosted.org/packages/f7/03/2a73d9c738115a07fffa67df2a33cce32564f637a75289edda67db5053fb/data-validator-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "13dc441dc6d79c4ae823bff92086c229", "sha256": "22ab289985335bba5731c05ac6a67a2b729f33860c7f5b851662cd072cd0c6fe" }, "downloads": -1, "filename": "data-validator-0.1.2.tar.gz", "has_sig": false, "md5_digest": "13dc441dc6d79c4ae823bff92086c229", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6397, "upload_time": "2017-09-12T06:47:00", "url": "https://files.pythonhosted.org/packages/80/ea/0751a6dad0bf9b033dbe5c95b5e04063b05e2c132127c5f6aa5c7161aff0/data-validator-0.1.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "13dc441dc6d79c4ae823bff92086c229", "sha256": "22ab289985335bba5731c05ac6a67a2b729f33860c7f5b851662cd072cd0c6fe" }, "downloads": -1, "filename": "data-validator-0.1.2.tar.gz", "has_sig": false, "md5_digest": "13dc441dc6d79c4ae823bff92086c229", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6397, "upload_time": "2017-09-12T06:47:00", "url": "https://files.pythonhosted.org/packages/80/ea/0751a6dad0bf9b033dbe5c95b5e04063b05e2c132127c5f6aa5c7161aff0/data-validator-0.1.2.tar.gz" } ] }