{ "info": { "author": "Tormod Landet", "author_email": "tormod@landet.net", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Programming Language :: Python :: 3", "Topic :: Software Development :: Libraries", "Topic :: Software Development :: Pre-processors", "Topic :: Software Development :: Quality Assurance" ], "description": "YSchema\n=======\n\nYSchema is a terse and simple schema format with a reference validator\nimplementation for YAML, JSON and other dictionary based data structures.\n\nYSchema is quite minimal (in terms of lines of code) and is continuously tested\nagainst a set of of valid and invalid example data (see the ``examples``\ndirectory). The code works nicely for its intended purpose, but may not be the\nmost powerful or popular, even if it does what it was intended for very well.\nThe main assumption (at least for now) is that all keys are strings without\nwhitespace.\n\nYSchema is written in Python (v. 3) and validates dictionaries containing basic\ndatatypes like strings, ints, floats, lists and nested dictionaries. The schema\nis also a dictionary, so both the data and the schema can be written in Python,\nJSON, YAML, TOML, ... formats. YSchema cannot validate all possible YAML / JSON\ndata, in fact it cannot even validate its own schema files since those use\nsignificant white space in dictionary keys to describe expected data types and\nwhether the data is required or not.\n\nTo install the YSchema Python library along with the ``yschema`` command line\nprogram run:\n\n.. code:: bash\n\n python3 -m pip install -U yschema\n\nConsider using a virtual environment or adding ``--user`` to the ``pip`` command\nif you do not want to install into the system's site-packages directory. PS: You\nmay also want to look at older and more established schema and validators such\nas Yamale_ or json-schema_ in case those serve your needs better.\n\n.. _Yamale: https://github.com/23andMe/Yamale\n.. _json-schema: http://json-schema.org\n\n\n.. contents::\n\n\nIntroduction to YSchema\n-----------------------\n\nA simple example schema:\n\n.. code:: yaml\n\n # There must be a key \"name\" that maps to a string\n required name: str\n\n # There can be an integer age, but it is not required\n optional age: int\n\n # The optional height must be above 0\n optional height: float(min_val=0)\n\nTo validate this, first load the schema above into a dictionary, then load the\ndata to validate into another dictionary, and finally run:\n\n.. code:: python\n\n import yschema\n\n # possibly loaded from json or yaml or just a plain old dict\n schema = my_load_schema_function()\n data_dict = {'name': 'Tormod'}\n\n yschema.validate(data_dict, schema_dict)\n\nIf the function does not raise ``yschema.ValidationError`` then the data is\nvalid according to the given schema. You can also use the ``yschema`` command\nto validate YAML files from the command line.\n\nA more complicated example, showing constants and nested dictionaries:\n\n.. code:: yaml\n\n # Example of a constant that can be used in validation functions\n constant minimum_string_length: 5\n\n # A sub-dictionary\n type Whale: \n # The name is a string of a given minimum length\n required name: str(min_len=minimum_string_length)\n\n # The length must be between 0 and 500 meters\n optional length: float(min_val=0, max_val=500.0)\n\n required whales: list(type=Whale)\n\nThe above schema validates data like this:\n\n.. code:: yaml\n\n whales:\n - name: Unknown Whale\n - name: Enormous Whale\n length: 200.0\n\nNote that when working with aliases and types the order of the keys in the\ndictionary starts to matter. Either use a Python 3.6 or later, or load your\nschema into an OrderedDict. YSchema contains a helper function for ordered safe\nloading of YAML files:\n\n.. code:: python\n\n with open(schema_file_name, 'rt') as yml:\n schema = yschema.yaml_ordered_load(yml)\n\n\nMore advanced features\n----------------------\n\n**Built in types**: the following types are implemented. Optional parameters\nare listed below each type:\n\n* Any\n* bool\n* str\n - min_len\n - max_len\n - equals - e.g. ``str(equals='Hi!')`` or matching one of several\n pissibilities with ``str(equals=('a', 'b', 'c'))``\n - prefix\n* int\n - min_val\n - max_val\n - equals - e.g. ``int(equals=3)`` or ``int(equals=(2, 4, 6))``\n* float\n - min_val\n - max_val\n - equals - e.g. ``float(equals=3.2)`` or ``float(equals=(2.1, 4.4))``\n* list\n - min_len\n - max_len\n - type - e.g. ``list(type=int)`` or ``list(type=Whale)``\n* one_of\n - types - e.g. ``one_of(types=(int, str))`` or\n ``one_of(types=(str(prefix='Moby'), Whale))``\n* any_of\n - types - see ``one_of`` (``any_of`` matches if any of the types match, \n ``one_of`` requires exactly one match)\n\n**Alias**: you can give an alias to avoid typing the same type definition over\nand over again:\n\n.. code:: yaml\n\n alias Cat: one_of(types=(HouseCat, Tiger, Lynx))\n alias Cats: list(type=Cat)\n\n**Glob**: you can allow undefined keys by using a glob. The following will\nvalidate OK for all documents\n\n.. code:: yaml\n\n optional *: Any\n\n**Inherit**: a sub-schema introduced by ``type`` can contain a key ``inherit``\nwith the name of a previously defined sub-schema to avoid repeating \ndefinitions that are shared among several types:\n\n.. code:: yaml\n\n type MeshBase:\n optional move: list(type=str)\n optional sort_order: list(type=int)\n optional mesh_file: str\n type MeshDolfinFile:\n inherit: MeshBase\n required type: str(equals=('XML', 'XDMF', 'HDF5'))\n required mesh_file: str\n optional facet_region_file: str\n type MeshMeshio:\n inherit: MeshBase\n required type: str(equals='meshio')\n required mesh_file: str\n optional meshio_type: str\n required mesh: one_of(types=(MeshMeshio, MeshDolfinFile))\n\n\nReleases\n--------\n\nVersion 1.0.2 - June 11. 2018\n\nImprove error messages and add convinience function to safe-load YAML into an\nOrderedDict\n\nVersion 1.0.1 - June 7. 2018\n............................\n\nCompleted v 1.0 implementation goals. The YSchema language is powerful enough to\nexpress most of what I wanted for validating Ocellaris_ input files. The code\nbase is decently tested (using the fantastic CircleCI service) and a command\nline tool is also included for validating YAML files from the shell.\n\nThere may not be a large number of additional releases if no more features are\nfound to be necessary for the author's uses. It is relatively easy to add new\ntype validators from user code, but feel free to submit a pull request if you\nare finding YSchema useful and have implemented some general purpose validators.\nYSchema does not intend to compete with complex and more fully featured schema\nlanguages like json-schema_.\n\n.. _Ocellaris: https://bitbucket.org/trlandet/ocellaris\n\nCopyright and license\n---------------------\n\nYSchema is copyright Tormod Landet, 2018. YSchema is licensed under the Apache\n2.0 license, a permissive free software license compatible with version 3 of\nthe GNU GPL. See the file LICENSE for the details.\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://bitbucket.org/trlandet/yschema", "keywords": "yaml json schema validation", "license": "Apache 2.0", "maintainer": "", "maintainer_email": "", "name": "yschema", "package_url": "https://pypi.org/project/yschema/", "platform": "", "project_url": "https://pypi.org/project/yschema/", "project_urls": { "Homepage": "https://bitbucket.org/trlandet/yschema" }, "release_url": "https://pypi.org/project/yschema/1.0.2/", "requires_dist": [ "PyYAML" ], "requires_python": "", "summary": "A YAML/JSON/dictionary schema validator with terse schema definitions", "version": "1.0.2" }, "last_serial": 3948897, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "f9fc85f12e262330a75cb27868b51a69", "sha256": "6cccef8019420ec8bef34512ef04814cbcd38197e19ae6afef9e9e808eef57b2" }, "downloads": -1, "filename": "yschema-1.0.0-py3.6.egg", "has_sig": false, "md5_digest": "f9fc85f12e262330a75cb27868b51a69", "packagetype": "bdist_egg", "python_version": "3.6", "requires_python": null, "size": 20003, "upload_time": "2018-06-07T15:00:36", "url": "https://files.pythonhosted.org/packages/ed/fe/b00295a3a82e731cb29c2e21707183825cb46ab7c59ca9f9b86ec2bed370/yschema-1.0.0-py3.6.egg" }, { "comment_text": "", "digests": { "md5": "53cdb950da386cf3c2055d24033d3b19", "sha256": "909d994bdfad2458ba89b94238a047e66c18b40e2be2fc8bf4b628fe2e28aa21" }, "downloads": -1, "filename": "yschema-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "53cdb950da386cf3c2055d24033d3b19", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 10829, "upload_time": "2018-06-07T15:01:00", "url": "https://files.pythonhosted.org/packages/08/be/e6b926daf4b7e620a77c3a9508b75e318d5d011b933efb93d828f8709e76/yschema-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c2b6849e097ff40023f086c4143bbd70", "sha256": "925b6568832ae3ab130530b8102c4a821abf01205ca9cfdbe8f669239c23eb5c" }, "downloads": -1, "filename": "yschema-1.0.0.tar.gz", "has_sig": false, "md5_digest": "c2b6849e097ff40023f086c4143bbd70", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10403, "upload_time": "2018-06-07T15:00:37", "url": "https://files.pythonhosted.org/packages/55/6e/0385ebe63c2c1042e41ce8ce2ea7ef8df1a26c48b8c091663ba65bf7e6a8/yschema-1.0.0.tar.gz" } ], "1.0.0.dev0": [ { "comment_text": "", "digests": { "md5": "ff6897a1da01ede8d8f9f28d39b34a95", "sha256": "d470dcfd338f15184800d55a0140a8ba354c2dd942e8484a95e2ae99ec6288b0" }, "downloads": -1, "filename": "yschema-1.0.0.dev0-py3-none-any.whl", "has_sig": false, "md5_digest": "ff6897a1da01ede8d8f9f28d39b34a95", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 8545, "upload_time": "2018-06-06T13:39:44", "url": "https://files.pythonhosted.org/packages/4c/fd/b59b42ff1334a5f217a29a7e20ae2555b7a216e15dbbdc962be5d985f1f3/yschema-1.0.0.dev0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d68b03f25742c217879ee0b969737afa", "sha256": "d65e1676380eb6f1e5134f85eb7e805b81971b711c8f5b2845b3e8f347d599aa" }, "downloads": -1, "filename": "yschema-1.0.0.dev0.tar.gz", "has_sig": false, "md5_digest": "d68b03f25742c217879ee0b969737afa", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8407, "upload_time": "2018-06-06T13:39:45", "url": "https://files.pythonhosted.org/packages/e3/22/c2c3b22b3cd0ba355e33de7274fde0645eeac6f7ce784555eb90efe9d419/yschema-1.0.0.dev0.tar.gz" } ], "1.0.0.dev1": [ { "comment_text": "", "digests": { "md5": "6e110c69acdd2d858161f21f2c879e65", "sha256": "1ae8dbfe90cf55500534017cd69da9a8d3855d22a98b1d6a4d38c209d4ceccc6" }, "downloads": -1, "filename": "yschema-1.0.0.dev1-py3.6.egg", "has_sig": false, "md5_digest": "6e110c69acdd2d858161f21f2c879e65", "packagetype": "bdist_egg", "python_version": "3.6", "requires_python": null, "size": 16040, "upload_time": "2018-06-06T18:33:41", "url": "https://files.pythonhosted.org/packages/fb/dc/666461b74dd65e23765ba90d9480f7f77fb983648315fcd0498b6875892e/yschema-1.0.0.dev1-py3.6.egg" }, { "comment_text": "", "digests": { "md5": "4a282feee6758219a1103525c6a8ccde", "sha256": "ac00387a3a6b017fee5ddcbe4162218ffe12828609c96df16e546a9613d579a6" }, "downloads": -1, "filename": "yschema-1.0.0.dev1.tar.gz", "has_sig": false, "md5_digest": "4a282feee6758219a1103525c6a8ccde", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8699, "upload_time": "2018-06-06T18:33:43", "url": "https://files.pythonhosted.org/packages/f8/62/0f8150a9ebcdf6688b5c41afd7bbdce187ede0ab3e399ad0fa659966b7cf/yschema-1.0.0.dev1.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "9847c355bf33842aa05819b026f10eec", "sha256": "28b18367e962467d6d452f36d22b212234b0336410c8f43b202f92632e0cadc7" }, "downloads": -1, "filename": "yschema-1.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "9847c355bf33842aa05819b026f10eec", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 10823, "upload_time": "2018-06-07T15:17:05", "url": "https://files.pythonhosted.org/packages/9b/3b/9b765b8503dd2f7620c6e2ef64bf861a2f11fbc15a2879d7952f6e6c341b/yschema-1.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "986cd29c54d546628ef31c2dab8006fd", "sha256": "931d6633574e470535a197bdf0cc26ef7ccbad25948db0eb1ac56f065aa2de6c" }, "downloads": -1, "filename": "yschema-1.0.1.tar.gz", "has_sig": false, "md5_digest": "986cd29c54d546628ef31c2dab8006fd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10408, "upload_time": "2018-06-07T15:17:06", "url": "https://files.pythonhosted.org/packages/9c/0e/a9d928d15d7ab0c9cda8e7934d5c8926d523f97585c45d32e0d0021363a8/yschema-1.0.1.tar.gz" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "672ac917ad858bf4335dc1c4f74caf37", "sha256": "50607f0d68a8950789c752fda4661ec67420330cd55ce5376360b7358fb03de4" }, "downloads": -1, "filename": "yschema-1.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "672ac917ad858bf4335dc1c4f74caf37", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11001, "upload_time": "2018-06-11T06:03:05", "url": "https://files.pythonhosted.org/packages/90/45/c2273dbd291890acad7e2b18028b2dac38e5e8e1936021bb76870d890d53/yschema-1.0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a00e7efd67bfe1c4a4f06128e41f5b1d", "sha256": "f2142cd986a608a314dd14847780e0a09123f94dcf42e3201e50b8de78dc8f74" }, "downloads": -1, "filename": "yschema-1.0.2.tar.gz", "has_sig": false, "md5_digest": "a00e7efd67bfe1c4a4f06128e41f5b1d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10605, "upload_time": "2018-06-11T06:03:06", "url": "https://files.pythonhosted.org/packages/8b/8a/69a730a64cf823af4eb8f3f68ef669f918cb937a381319536fe7292c577c/yschema-1.0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "672ac917ad858bf4335dc1c4f74caf37", "sha256": "50607f0d68a8950789c752fda4661ec67420330cd55ce5376360b7358fb03de4" }, "downloads": -1, "filename": "yschema-1.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "672ac917ad858bf4335dc1c4f74caf37", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11001, "upload_time": "2018-06-11T06:03:05", "url": "https://files.pythonhosted.org/packages/90/45/c2273dbd291890acad7e2b18028b2dac38e5e8e1936021bb76870d890d53/yschema-1.0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a00e7efd67bfe1c4a4f06128e41f5b1d", "sha256": "f2142cd986a608a314dd14847780e0a09123f94dcf42e3201e50b8de78dc8f74" }, "downloads": -1, "filename": "yschema-1.0.2.tar.gz", "has_sig": false, "md5_digest": "a00e7efd67bfe1c4a4f06128e41f5b1d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10605, "upload_time": "2018-06-11T06:03:06", "url": "https://files.pythonhosted.org/packages/8b/8a/69a730a64cf823af4eb8f3f68ef669f918cb937a381319536fe7292c577c/yschema-1.0.2.tar.gz" } ] }