{ "info": { "author": "Radoslav Georgiev", "author_email": "radorado@hacksoft.io", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: Implementation :: CPython" ], "description": "\n# Simple schema validator\n\n- [Simple schema validator](#simple-schema-validator)\n - [Basic usage](#basic-usage)\n - [Type checking](#type-checking)\n - [Optional types](#optional-types)\n\n\nA dead-simple utility that validates if object has a certain structure. Used in some of our projects.\n\n## Basic usage\n\n```\npip install simple_schema_validator\n```\n\nAn example:\n\nLets say we have an API that returns the following data:\n\n```json\n{\n \"user\": 1,\n \"profile\": {\n \"email\": \"some@user.com\",\n \"name\": \"Some User\",\n \"age\": 20\n },\n \"tokens\": {\n \"jwt\": \"...\",\n \"refresh\": \"...\",\n \"firebase\": \"...\",\n }\n}\n```\n\nAnd we are writing a simple integration test, that wants to assure the response has a certain structure.\n\nThen we can use the schema validator like so:\n\n```python\nfrom simple_schema_validator import schema_validator\n\ndata = get_data_from_api()\n\nschema = {\n 'user': Any,\n 'profile': {\n 'email': Any,\n 'name': Any,\n 'age': Any\n },\n 'tokens': {\n 'jwt': Any,\n 'refresh': Any,\n 'firebase': Any\n }\n}\n\nvalidation = schema_validator(schema, data)\n\nif not result:\n print(f'Keys in data, but not in schema: {validation.additional_keys}')\n print(f'Keys in schema, but not in data: {validation.missing_keys}')\n print(f'Keys with different type from schema {validation.type_errors}')\n```\n\n* `missing_keys` are those keys that are required in the `schema`, but not found in `data`.\n* `additional_keys` are those keys present in `data`, but not required by the `schema`.\n* `validation_errors` are those keys, that are having a different type in `data`, from the defined in `schema`.\n\n**Nested keys are represented with \"dot\" notation - `profile.email`, `tokens.jwt`, etc.**\n\n## Type checking\n\nThe util supports simple schema type checking.\n\nCurrently, the supported types in the schema are:\n\n* `int`\n* `float`\n* `str`\n* `bool`\n* `typing.Any` (from Python `typing` library)\n* `simple_schema_validator.types.Optional` (custom type, define in the package)\n\nIf the type is `Any`, no type checking is done.\n\nIf there's a type mismatch, the errors are placed in the `type_errors` attribute of the result, which is a list of type errors.\n\nThe general format of a single type error is:\n\n```python\n{\n 'path': 'the.path.to.the.value.in.data',\n 'expected': the_expected_type_as_defined_in_the_schema,\n 'actual': the_actual_type_of_the_value\n}\n```\n\nHere's an example:\n\n\n```python\nfrom simple_schema_validator import schema_validator, types\n\n\nschema = {\n 'user': str,\n 'profile': {\n 'email': str,\n 'name': str,\n 'age': int\n },\n 'tokens': {\n 'jwt': str,\n 'refresh': str,\n 'firebase': str\n }\n}\n\ndata = {\n 'user': 'Some User',\n 'profile': {\n 'email': 'someuser@hacksoft.io',\n 'name': 'Some User',\n 'age': \"29\"\n },\n 'tokens': {\n 'jwt': 'some token value',\n 'refresh': 'some token value',\n 'firebase': 'some token value'\n }\n\n}\n\nresult = schema_validator(schema, data)\n\n\nassert bool(result) is False\nassert result.type_errors == [{'path': 'profile.age', 'expected': int, 'actual': str}]\n```\n\n### Optional types\n\nThe schema validator support optional types.\n\nYou can do the following:\n\n```python\nfrom simple_schema_validator import schema_validator, types\n\nschema = {\n 'a': types.Optional[int]\n}\n\ndata_1 = {\n 'a': None\n}\n\ndata_2 = {\n 'a': 1\n}\n\ndata_3 = {\n 'a': 'some_string'\n}\n\nassert bool(schema_validator(schema, data_1)) is True\nassert bool(schema_validator(schema, data_2)) is True\nassert bool(schema_validator(schema, data_3)) is False\n```\n\nAdditionally, you can define optional branches in the schema:\n\n```python\nfrom simple_schema_validator import schema_validator, types\n\nschema = {\n 'a': types.Optional[{\n 'b': int\n }]\n}\n\ndata_1 = {\n 'a': None\n}\n\ndata_2 = {\n 'a': 1\n}\n\ndata_3 = {\n 'a': {\n 'b': 1\n }\n}\n\ndata_4 = {\n 'a': {\n 'b': 'some_string'\n }\n}\n\nassert bool(schema_validator(schema, data_1)) is True\nassert bool(schema_validator(schema, data_2)) is False\nassert bool(schema_validator(schema, data_3)) is True\nassert bool(schema_validator(schema, data_4)) is False\n```\n\n## Examples\n\nFor examples, check the [examples](examples/) folder or the tests for the project.\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/HackSoftware/simple_schema_validator", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "simple-schema-validator", "package_url": "https://pypi.org/project/simple-schema-validator/", "platform": "", "project_url": "https://pypi.org/project/simple-schema-validator/", "project_urls": { "Homepage": "https://github.com/HackSoftware/simple_schema_validator" }, "release_url": "https://pypi.org/project/simple-schema-validator/0.0.8/", "requires_dist": null, "requires_python": ">=3.6.0", "summary": "A dead-simple utility that validates if object has a certain structure.", "version": "0.0.8" }, "last_serial": 4979448, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "e8d5387887e913f11f72b60ff9c9a076", "sha256": "56e528b0b4514eff3106a918d14cd56e3fe8e5c601276502ff5b9eb285a20ef8" }, "downloads": -1, "filename": "simple_schema_validator-0.0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "e8d5387887e913f11f72b60ff9c9a076", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.6.0", "size": 4760, "upload_time": "2019-02-11T12:38:31", "url": "https://files.pythonhosted.org/packages/26/e5/b3e94a7e77535f6c45812001778611fc9cf380dfd51842ebb1c19dff6fa5/simple_schema_validator-0.0.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "4b2123d2fbd307e9b92dc435fb1686b5", "sha256": "8527d3278bf51e78aab55110a11c367fa0b56aee9e907bab61048866768d1024" }, "downloads": -1, "filename": "simple_schema_validator-0.0.1.tar.gz", "has_sig": false, "md5_digest": "4b2123d2fbd307e9b92dc435fb1686b5", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.0", "size": 4071, "upload_time": "2019-02-11T12:38:33", "url": "https://files.pythonhosted.org/packages/83/a1/a509c41a0ebf2eb2d94b137ab8515ce90d0551d80a783fad63825b567911/simple_schema_validator-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "4f7cec2aa8c1b94406ddf669829b0d22", "sha256": "b42bc05c094437a98f77ac840c8f42bc1bb321aba9f6d494ba014fca4d8abd80" }, "downloads": -1, "filename": "simple_schema_validator-0.0.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "4f7cec2aa8c1b94406ddf669829b0d22", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.6.0", "size": 4896, "upload_time": "2019-02-11T12:50:23", "url": "https://files.pythonhosted.org/packages/26/e4/de3a6df5a78d7f696f52b8bed3309a8370fa293750785c8a69bf12d66ef3/simple_schema_validator-0.0.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "24b3dfe204ea8f7f242aa93f56085dd0", "sha256": "3820ac5debd96e477c3b510465e5b71cd2a451549e83bf02033fa13b13188940" }, "downloads": -1, "filename": "simple_schema_validator-0.0.2.tar.gz", "has_sig": false, "md5_digest": "24b3dfe204ea8f7f242aa93f56085dd0", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.0", "size": 4221, "upload_time": "2019-02-11T12:50:24", "url": "https://files.pythonhosted.org/packages/f4/be/3deebf051072db449bff4a8c4df20bef4e2a1aafde7005091e5a9f291ec3/simple_schema_validator-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "a0bea4fcc009bdc3c5dd077b5712d44d", "sha256": "7641a1250f18bff791f5f0e53b782b5c3a9dc0eb8af692b7955d266f43c7847e" }, "downloads": -1, "filename": "simple_schema_validator-0.0.3-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "a0bea4fcc009bdc3c5dd077b5712d44d", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.6.0", "size": 4897, "upload_time": "2019-02-14T08:54:21", "url": "https://files.pythonhosted.org/packages/57/be/825d041a04d987aa22f98b874b2b2faf4347a6ad71a6c882bb29b717dbd0/simple_schema_validator-0.0.3-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "42b81b0ff59148ce542564e546c71cc6", "sha256": "63815dfbf6eea8e7f2dc25d04f1a2107b1b769acd0f2b67021b1a2e60576c991" }, "downloads": -1, "filename": "simple_schema_validator-0.0.3.tar.gz", "has_sig": false, "md5_digest": "42b81b0ff59148ce542564e546c71cc6", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.0", "size": 4252, "upload_time": "2019-02-14T08:54:22", "url": "https://files.pythonhosted.org/packages/86/ad/7f125cbd593fc069453ab85710401e8424a5553dc82610f355e41787e978/simple_schema_validator-0.0.3.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "dcf30dfa5a78777503946adeb76b3d62", "sha256": "cb2bd5dbe591426566ce6e13fe9397ca04fb90f5c8bd589fab687a3bba2dc445" }, "downloads": -1, "filename": "simple_schema_validator-0.0.4-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "dcf30dfa5a78777503946adeb76b3d62", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.6.0", "size": 5055, "upload_time": "2019-02-26T15:46:47", "url": "https://files.pythonhosted.org/packages/a3/65/de1c18fbc487d79229bea7b725dc4398c8a8965c689a20c21185bbafea9b/simple_schema_validator-0.0.4-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "df31a894ca79688708745a902fe33a6a", "sha256": "7d15fdb664e50ee085b0e942d38049aec4ffcb3c3d87f263063ba641e519f971" }, "downloads": -1, "filename": "simple_schema_validator-0.0.4.tar.gz", "has_sig": false, "md5_digest": "df31a894ca79688708745a902fe33a6a", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.0", "size": 4381, "upload_time": "2019-02-26T15:46:50", "url": "https://files.pythonhosted.org/packages/d2/60/e15524b3e9344ca7fd82a5fbbccddd00fce1c9829faed523f0e37a85c204/simple_schema_validator-0.0.4.tar.gz" } ], "0.0.5": [ { "comment_text": "", "digests": { "md5": "a1d659e8f233ef37d36aafe6ea7289f4", "sha256": "9c5a9dea4af37f389b588ee395bec2daca401b99d178cf10f22d68210402ce36" }, "downloads": -1, "filename": "simple_schema_validator-0.0.5-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "a1d659e8f233ef37d36aafe6ea7289f4", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.6.0", "size": 6066, "upload_time": "2019-03-15T10:59:24", "url": "https://files.pythonhosted.org/packages/b5/03/c976c7f0a1dd1e378c1844bf655729051a6cfd14b39f306ef8e9ed62c2ac/simple_schema_validator-0.0.5-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "fdb87ca98ae347fd8872aa5291e88e99", "sha256": "696b4117d67ac05947b9c0c7d58394d46f192e149194a26c42c0013229ec24aa" }, "downloads": -1, "filename": "simple_schema_validator-0.0.5.tar.gz", "has_sig": false, "md5_digest": "fdb87ca98ae347fd8872aa5291e88e99", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.0", "size": 6026, "upload_time": "2019-03-15T10:59:25", "url": "https://files.pythonhosted.org/packages/af/70/11f9433d9c1cd9a6d2cc1fe0df6932745fb2506e307b49353e629c6ea7d2/simple_schema_validator-0.0.5.tar.gz" } ], "0.0.6": [ { "comment_text": "", "digests": { "md5": "7215f25e6d19b00ebcc542e6bc8c531c", "sha256": "19a5f475172a7add73dc38b2ea2861d462bde450eb61e1e42b9251f4e9359ffd" }, "downloads": -1, "filename": "simple_schema_validator-0.0.6-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "7215f25e6d19b00ebcc542e6bc8c531c", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.6.0", "size": 7200, "upload_time": "2019-03-15T15:37:33", "url": "https://files.pythonhosted.org/packages/a5/66/5a3e3d531982f18186f8dea956fd2e3cf8f026dfa8e28e45bd48bf8c50d8/simple_schema_validator-0.0.6-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "4cd273d25cac6275f14437954d6a51e2", "sha256": "ddb96b8f131d9e843af63898e5d58dbc90a4ed9f9cc91d2c4c360cfb7e08cb53" }, "downloads": -1, "filename": "simple_schema_validator-0.0.6.tar.gz", "has_sig": false, "md5_digest": "4cd273d25cac6275f14437954d6a51e2", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.0", "size": 8112, "upload_time": "2019-03-15T15:37:35", "url": "https://files.pythonhosted.org/packages/29/31/04950fa4645e176800f690a86c7bc4bbbbd1b4a092a24f3a646f0f87ffb8/simple_schema_validator-0.0.6.tar.gz" } ], "0.0.7": [ { "comment_text": "", "digests": { "md5": "415c7ec46b9cd87c9bfedd362ae9bfce", "sha256": "f75c2827e549dc7b6a0f118a06f0202ad6224dcedfa15842ddbdeafa13b87dc6" }, "downloads": -1, "filename": "simple_schema_validator-0.0.7-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "415c7ec46b9cd87c9bfedd362ae9bfce", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.6.0", "size": 7988, "upload_time": "2019-03-15T17:34:05", "url": "https://files.pythonhosted.org/packages/6f/5f/6dc937846baba4d7cd2416d5f2250138d64ae027736d3675b7dc72a5911d/simple_schema_validator-0.0.7-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d6ff74e0401bae415d4a0a3da1135a0a", "sha256": "22b73ecf76bea60ecd6f3e8b50ef7d6df310a48d13798b3d7bd5718ed423b178" }, "downloads": -1, "filename": "simple_schema_validator-0.0.7.tar.gz", "has_sig": false, "md5_digest": "d6ff74e0401bae415d4a0a3da1135a0a", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.0", "size": 5761, "upload_time": "2019-03-15T17:34:07", "url": "https://files.pythonhosted.org/packages/fe/ed/bbd719d3cc885bdaa62b6b9ce4e7e4dc97deed0122baaa5d0fecaed5f69e/simple_schema_validator-0.0.7.tar.gz" } ], "0.0.8": [ { "comment_text": "", "digests": { "md5": "f838271f1e7d8e65a60ef4750ee4734f", "sha256": "af180cf17452eb09990335f70ecb7f66d19923b7a2640aa513c45b764f4ef509" }, "downloads": -1, "filename": "simple_schema_validator-0.0.8-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "f838271f1e7d8e65a60ef4750ee4734f", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.6.0", "size": 8383, "upload_time": "2019-03-24T18:16:22", "url": "https://files.pythonhosted.org/packages/12/f3/fd6e0012d8e1b3f2a0dafd5080f4ff22111576846197845504a459ebe09d/simple_schema_validator-0.0.8-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d8f7cb06eaeb1df0b32508d2f807d182", "sha256": "baf6db4b9bc31b6543d817a594dd3ab2ad0d3583f758df42830baad6265494d7" }, "downloads": -1, "filename": "simple_schema_validator-0.0.8.tar.gz", "has_sig": false, "md5_digest": "d8f7cb06eaeb1df0b32508d2f807d182", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.0", "size": 6254, "upload_time": "2019-03-24T18:16:24", "url": "https://files.pythonhosted.org/packages/33/ea/d958e1b31804d2597ebf6f2311934491b9a6fadce1e68c02007ef43372a5/simple_schema_validator-0.0.8.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "f838271f1e7d8e65a60ef4750ee4734f", "sha256": "af180cf17452eb09990335f70ecb7f66d19923b7a2640aa513c45b764f4ef509" }, "downloads": -1, "filename": "simple_schema_validator-0.0.8-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "f838271f1e7d8e65a60ef4750ee4734f", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.6.0", "size": 8383, "upload_time": "2019-03-24T18:16:22", "url": "https://files.pythonhosted.org/packages/12/f3/fd6e0012d8e1b3f2a0dafd5080f4ff22111576846197845504a459ebe09d/simple_schema_validator-0.0.8-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d8f7cb06eaeb1df0b32508d2f807d182", "sha256": "baf6db4b9bc31b6543d817a594dd3ab2ad0d3583f758df42830baad6265494d7" }, "downloads": -1, "filename": "simple_schema_validator-0.0.8.tar.gz", "has_sig": false, "md5_digest": "d8f7cb06eaeb1df0b32508d2f807d182", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.0", "size": 6254, "upload_time": "2019-03-24T18:16:24", "url": "https://files.pythonhosted.org/packages/33/ea/d958e1b31804d2597ebf6f2311934491b9a6fadce1e68c02007ef43372a5/simple_schema_validator-0.0.8.tar.gz" } ] }