{ "info": { "author": "Anton Chevychalov", "author_email": "cab@arenadata.io", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# yspec\n\nyspec is a deadly simple checker for structures. It is especially usefull for validation of different yaml/json files\n\n## Usage from cli\n\n```sh\nyspec ./schema.yaml /tmp/data.json\n```\n\nNOTE: yspec able to take json/yaml/toml for schema and for data\n\n## Usage from code\n\n```python\nfrom yspec.checker import process_rule\n\n# Some code that prepares data and rules\n\nprocess_rule(data, rules, 'root')\n```\n\n## Schema Format\n\nSchema is a dict of rules. Every rule do some check according to 'match' field. Schema must include 'root' rule which is applied on top object in structure.\n\nFor example structure (in YAML):\n\n```yaml\n---\n- 'string1'\n- 'string2'\n\n```\n\nwill be valid for schema (in YAML):\n\n```yaml\n---\nroot:\n match: dict\n item: string\n\nstring:\n match: string\n```\n\n## Match Rules\n\n### Simple type matches\n\n#### String\n\n```yaml\nmy_awesome_string:\n match: string\n```\n\n#### Boolean\n\n```yaml\nmy_awesome_bool:\n match: bool\n```\n\n#### Integer\n\n```yaml\nmy_awesome_int:\n match: int\n```\n\n#### Float\n\n```yaml\nmy_awesome_float:\n match: float\n```\n\n### Recursion type matches\n\nThere are two of them: dict and list. Both has the same recursion logic. At first we apply some checks on object itself, and then apply another (or the same) rule to childrens (list elements, or values of dict).\n\n#### List\n\n```yaml\nmy_list:\n match: list\n item: some_other_rule\n```\n\nList is a recurent type. Fist it checks is the object a list, then it check every element according to rule in 'item' attr.\n\n\n#### Dict\n\n```yaml\nmy_list:\n match: dict\n items:\n key1: string_rule\n key2: integer_rule\n default_item: some_other_rule\n required_items:\n - key2\n```\n\nThat is a rule that describe a dict that has two keys (key1 and key2). One of keys (key2) is mandatory. Key1 should be checked according to 'string_rule' rule, while any other keys with any other (non key1 or key2) name will be checked according to some_other_rule.\n\n\nIf we has remove default_item\n```yaml\nmy_list:\n match: dict\n items:\n key1: string_rule\n key2: integer_rule\n required_items:\n - key2\n```\n\nA dict could be with two keys (key1, key2) maximum\n\n\n### Sample of simple and recursion matches\n\nSchema:\n\n```yaml\n---\nboolean:\n match: bool\n\nstring:\n match: string\n\ninteger:\n match: int\n\nfloat:\n match: float\n\nlist:\n match: list\n item: string\n\nroot:\n match: dict\n items:\n key1: boolean\n key2: string\n key3: integer\n key4: float\n key5: list\n```\n\nData:\n```yaml\n---\nkey1: true\nkey2: \"That is a string\"\nkey3: 1\nkey4: 1.0\nkey5:\n - \"One more string\"\n - \"Another string\"\n```\n\n### Special matches\n\n#### OneOf match\n\n```yaml\nconstraint_list_item:\n match: one_of\n variants:\n - integer_rule\n - some_other_rule\n```\n\nOneOf match success if any of rules from \"variants\" success.\n\n#### Dict key selection\n\nSome times you need to do a separate checks for dict that have some key/value pair.\n\nFor example you have the following data:\n```yaml\n---\n- type: type1\n payload:\n - 1\n - 1\n- type: type2\n payload:\n - \"that is a string\"\n - \"that is a string2\"\n```\n\nIn that example you have a dict wich has diffent payload depends of type key. That is possible to describe with following schema:\n\n```yaml\n---\nroot:\n match: list\n item: list_item\n\nlist_item:\n match: dict_key_selection\n selector: type\n variants:\n type1: dict_with_int\n type2: dict_with_string\n\ndict_with_int:\n match: dict\n items:\n type: string\n payload: list_of_int\n required_items:\n - type\n - payload\n\ndict_with_string:\n match: dict\n items:\n type: string\n payload: list_of_string\n required_items:\n - type\n - payload\n\n\nlist_of_int:\n match: list\n item: int\n\nint:\n match: int\n\nlist_of_string:\n match: list\n item: string\n\nstring:\n match: string\n```\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/arenadata/yspec", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "yspec", "package_url": "https://pypi.org/project/yspec/", "platform": "", "project_url": "https://pypi.org/project/yspec/", "project_urls": { "Homepage": "https://github.com/arenadata/yspec" }, "release_url": "https://pypi.org/project/yspec/0.0.7/", "requires_dist": [ "pyyaml" ], "requires_python": "", "summary": "YAML structure validator", "version": "0.0.7" }, "last_serial": 5988873, "releases": { "0.0.7": [ { "comment_text": "", "digests": { "md5": "21c78d645285d760e6616fb38a9c964b", "sha256": "c3ac981f954aa790ea96b1959907a1517168678fa975017bf9ccddb9561908b9" }, "downloads": -1, "filename": "yspec-0.0.7-py3-none-any.whl", "has_sig": false, "md5_digest": "21c78d645285d760e6616fb38a9c964b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 10082, "upload_time": "2019-08-07T16:08:37", "url": "https://files.pythonhosted.org/packages/54/eb/bea10c0e450e78616c16156475a5d99f5706058a82e1b898022e1d3550fb/yspec-0.0.7-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "2d295ef4bbb60d872b722b29404bcd6d", "sha256": "b35d6d80b07aa1892ec23b0f082d4d15ee60894089ae523cab6e40b33de8cd8c" }, "downloads": -1, "filename": "yspec-0.0.7.tar.gz", "has_sig": false, "md5_digest": "2d295ef4bbb60d872b722b29404bcd6d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4943, "upload_time": "2019-08-07T16:08:40", "url": "https://files.pythonhosted.org/packages/31/df/c9b81b8355d80cd80dc0e0ae9ff7135d2364a7232cc1294dea11349b0fcf/yspec-0.0.7.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "21c78d645285d760e6616fb38a9c964b", "sha256": "c3ac981f954aa790ea96b1959907a1517168678fa975017bf9ccddb9561908b9" }, "downloads": -1, "filename": "yspec-0.0.7-py3-none-any.whl", "has_sig": false, "md5_digest": "21c78d645285d760e6616fb38a9c964b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 10082, "upload_time": "2019-08-07T16:08:37", "url": "https://files.pythonhosted.org/packages/54/eb/bea10c0e450e78616c16156475a5d99f5706058a82e1b898022e1d3550fb/yspec-0.0.7-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "2d295ef4bbb60d872b722b29404bcd6d", "sha256": "b35d6d80b07aa1892ec23b0f082d4d15ee60894089ae523cab6e40b33de8cd8c" }, "downloads": -1, "filename": "yspec-0.0.7.tar.gz", "has_sig": false, "md5_digest": "2d295ef4bbb60d872b722b29404bcd6d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4943, "upload_time": "2019-08-07T16:08:40", "url": "https://files.pythonhosted.org/packages/31/df/c9b81b8355d80cd80dc0e0ae9ff7135d2364a7232cc1294dea11349b0fcf/yspec-0.0.7.tar.gz" } ] }