{ "info": { "author": "Teriks", "author_email": "Teriks@users.noreply.github.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Natural Language :: English", "Operating System :: OS Independent", "Topic :: Software Development :: Libraries" ], "description": "About dschema\n=============\n\n.. |codecov| image:: https://codecov.io/gh/Teriks/dschema/branch/master/graph/badge.svg\n :target: https://codecov.io/gh/Teriks/dschema\n\n.. |Master Documentation Status| image:: https://readthedocs.org/projects/dschema/badge/?version=latest\n :target: http://dschema.readthedocs.io/en/latest/?badge=latest\n\n.. |pypi| image:: https://badge.fury.io/py/dschema.svg\n :target: https://badge.fury.io/py/dschema\n\n|pypi| |Master Documentation Status| |codecov|\n\ndschema is a small library for validating the content of python dictionary objects against a schema.\n\nThe schema can be defined in code or entirely as text (parsed from json generally)\n\ndschema was mainly made for validating config files written in JSON.\n\n\nExample\n=======\n\nSee documentation link for more examples\n\n.. code-block:: python\n\n import re\n import phonenumbers\n import dschema\n\n\n # https://github.com/daviddrysdale/python-phonenumbers\n # pip install phonenumbers\n\n\n def phone_type(number):\n # Exceptions are validation errors\n # Very similar design to the \"argparse\" module\n return phonenumbers.parse(number)\n\n\n def ssn_type(ssn):\n if re.match('^\\d{3}-?\\d{2}-?\\d{4}$', ssn):\n return ssn\n else:\n raise ValueError('\"{}\" is not a valid SSN.')\n\n\n schema = {\n 'person': {\n 'first_name': dschema.prop(required=True),\n 'last_name': dschema.prop(required=True),\n 'phone': dschema.prop(required=True, type=phone_type),\n 'ssn': dschema.prop(required=True, type='ssn_type'),\n\n dschema.Required: True\n # \"person\" namespace is required, you must specify\n # even if \"person\" itself contains required properties\n },\n\n # Allow a raw dictionary value to pass through\n\n 'other_info': dschema.prop(default=dict(), dict=True),\n\n # default to False if not present\n\n 'subscribed': dschema.prop(default=False, type=bool)\n }\n\n validator = dschema.Validator(schema)\n\n # you can use this to add types that are recognized by name.\n # which is useful if you want your schema to be entirely textual\n\n validator.add_type('ssn_type', ssn_type)\n\n # you will need to define default types on your own\n # if you want to reference them by name\n\n # validator.add_type('int', int)\n\n\n data = {\n 'person': {\n 'first_name': \"John\",\n 'last_name': \"Smith\",\n 'phone': '+1 234 5678 9000',\n 'ssn': '123-45-6789'\n },\n\n 'other_info': {\n 'website': 'www.johnsmith.com',\n }\n }\n\n # If namespace is left False, a plain dictionary is returned\n\n result = validator.validate(data, namespace=True)\n\n print(result)\n\n # Prints: (un-indented)\n\n # Namespace(\n # person=Namespace(\n # first_name='John',\n # last_name='Smith',\n # phone=PhoneNumber(...),\n # ssn='123-45-6789'),\n # other_info={'website': 'www.johnsmith.com'},\n # subscribed=False\n # )\n\n\n # Each Namespace is just a dynamic object\n\n print(result.person.first_name) # -> John\n print(result.person.last_name) # -> Smith\n\n print(result.person.phone)\n # - > Country Code: 1 National Number: 23456789000\n\n print(result.person.ssn) # -> 123-45-6789\n\n print(result.other_info) # -> {'website': 'www.johnsmith.com'}\n\n print(result.subscribed) # -> False (default)", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/Teriks/dschema", "keywords": "", "license": "BSD 3-Clause", "maintainer": "", "maintainer_email": "", "name": "dschema", "package_url": "https://pypi.org/project/dschema/", "platform": "", "project_url": "https://pypi.org/project/dschema/", "project_urls": { "Homepage": "https://github.com/Teriks/dschema" }, "release_url": "https://pypi.org/project/dschema/0.3.1.3a1/", "requires_dist": null, "requires_python": ">=3.4", "summary": "Python dictionary validation by schema.", "version": "0.3.1.3a1" }, "last_serial": 5719685, "releases": { "0.3.1.3a1": [ { "comment_text": "", "digests": { "md5": "ba43e4a972525e298445080e9dddc2db", "sha256": "68088c2f342d192c30c737b80c5e2fde9a54f73f79dc63513ac4da5bef346ebc" }, "downloads": -1, "filename": "dschema-0.3.1.3a1.tar.gz", "has_sig": false, "md5_digest": "ba43e4a972525e298445080e9dddc2db", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.4", "size": 8122, "upload_time": "2019-08-23T09:08:36", "url": "https://files.pythonhosted.org/packages/64/94/1d0d8c671a73d42e355365538130da27260539a22bb1b7c6aa988ecff190/dschema-0.3.1.3a1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "ba43e4a972525e298445080e9dddc2db", "sha256": "68088c2f342d192c30c737b80c5e2fde9a54f73f79dc63513ac4da5bef346ebc" }, "downloads": -1, "filename": "dschema-0.3.1.3a1.tar.gz", "has_sig": false, "md5_digest": "ba43e4a972525e298445080e9dddc2db", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.4", "size": 8122, "upload_time": "2019-08-23T09:08:36", "url": "https://files.pythonhosted.org/packages/64/94/1d0d8c671a73d42e355365538130da27260539a22bb1b7c6aa988ecff190/dschema-0.3.1.3a1.tar.gz" } ] }