{ "info": { "author": "Drachenfels ", "author_email": "drachenfels@protonmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 1 - Planning", "Intended Audience :: Developers", "Programming Language :: Python :: 3 :: Only", "Programming Language :: Python :: 3.7", "Topic :: Software Development" ], "description": "# python-schema\n\n---\n## Why would I use it?\n\nIf it happens that you are working on an API, RPC or simply work with functions\nthat accept complex data structures (trees and alike) common task is to have a\ntool that verifies that all required fields are present, types are of expected\ncolour and finally there is consistent way to handle errors. Sometimes output\nis complex and same is expected. Sometimes we just need to establish contract\nhow different libraries/modules/functions will communicate with each other.\n\nInitially it was achieved usually by hand crafting validators on the fly as\nprojects were developed, then someone figured out that we can call them forms\nand use for html/gui rendering as well, finally we all settled with schema's (\nthere is plenty of them). Where the most sane approach was taken to decouple\nissue of normalisation and validation from anything else (to name a few: orm,\ngui, leaking implementation to outside world).\n\nThis library belongs to the 3rd generation and by no means is revolutionary. It\njust attempt to have the same but with no over-engineered parts. Code has to be\nsimple, easy to understand, but configurable just enough. Whenever developer\nneeds something extra, he can easily override or extend what was given to him.\n\n---\n## How to use it?\n\nThe python-schema consist of many fields like: IntField, StrField, BoolField,\nFloatField, CollectionField, SchemaField, BaseField and etc.\n\nEach field has two primary functions to load data (where normalisation and\nvalidation happens) and to dump data (where conversion to either native python\nor json-compatible format happens).\n\n---\n## Examples\n\n> \u201cTalk is cheap. Show me the code.\u201d - Linus Torvald\n\nOne of the principles of python-schema is TDD, each case study will be\nfunctional test copy-pasted from the test suite (that being said there is many\nmore tests than shown below).\n\n### Case 1 - Simple Schema\nsee [Case #1] (https://www.example.com/)\n\n\n class User(field.SchemaField):\n fields = [\n field.StrField('name'),\n field.StrField('last_name'),\n field.IntField('age'),\n ]\n\n user = User()\n\n # payload has fulfilled expectation of User, no errors expected\n user.loads({\n 'name': 'John',\n 'last_name': 'Doe',\n 'age': '50',\n })\n\n assert user['name'] == 'John'\n assert user['last_name'] == 'Doe'\n\n # notice normalization of '50' into 50\n assert user['age'] == 50\n\n # we can also compare user to dictionary\n assert user == {\n 'name': 'John',\n 'last_name': 'Doe',\n # again '50' was normalised\n 'age': 50,\n }\n\n # last thing we can do is convert user to normalised output\n\n # as either native python objects (in this case DateField would change into\n # datetime object)\n dct = user.as_python()\n\n assert dct['name'] == 'John'\n assert dct['last_name'] == 'Doe'\n assert dct['age'] == 50\n\n # or as json-compatible format that can be safely json.dumps any time later\n\n json_dct = user.as_json()\n\n assert json_dct['name'] == 'John'\n assert json_dct['last_name'] == 'Doe'\n assert json_dct['age'] == 50\n\n import json\n\n assert json.dumps(json_dct) == \\\n '{\"name\": \"John\", \"last_name\": \"Doe\", \"age\": 50}'\n\n # there is third method of dumping normalised data `.dumps()` however it's\n # purpose is only to maintain symmetry between loads and dumps as json\n # module does\n\n dumps_dct = user.dumps()\n\n assert dumps_dct == json_dct\n\n---\n## Premise of python-schema\n\nOnly essentials are part of library:\n\n* from super simple to super complex schema\n* required fields with support of inheritance and complex structures\n* rudimentary validation but easy to expand\n* minimum 3rd-party depdencies (currently none)\n* accept json-like dictionary or python primitives on input (exclusively\n everything that could show up after json.dumps)\n* output is either json-like dictionary or python native code (former\n guarantees json.dumps later oes not)\n* if in doubt or need custom, code is simple, subclass python-schema and override/extend\n\nWhat you do not have in library:\n\n* ORM integration\n* decorators\n* meta classes\n* modules of badly formatted 1k+ lines of code with references flying all over the place\n* magic\n* methods that do some complex stuff\n* integration with anything (unless working with json strings we call integration)\n* bloat\n\n---\n## Flow of python schema\n\n1. Each schema is a Field that may or may not have more fields\n2. Each field loads content, that is:\n\n a. normalise\n\n b. validate\n\n3. Each field dumps content, that is:\n\n a. return python-native (imaginary numbers, datetime objects)\n\n **or**\n\n a. return json compatible content (everything unknown to json.dumps converted to string)\n\n4. Each field understands context, ie. when working with datetime, dumping will\n return date according to current user(s) timezone\n\n---\n## Don't like it, do you know anything better?\n\nOf course! There is plenty that I used as inspiration (what to do) and warning\n(what not to do):\n\n* [JSON Schema (https://json-schema.org/)] (https://json-schema.org/)\n* [Marshmallow (https://marshmallow.readthedocs.io/en/3.0/)] (https://marshmallow.readthedocs.io/en/3.0/)\n* [WTForms (https://wtforms.readthedocs.io/en/stable/)] (https://wtforms.readthedocs.io/en/stable/)\n* [Schema (https://pypi.org/project/schema/)] (https://pypi.org/project/schema/)\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/Drachenfels/python-schema", "keywords": "schema", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "python-schema", "package_url": "https://pypi.org/project/python-schema/", "platform": "", "project_url": "https://pypi.org/project/python-schema/", "project_urls": { "Homepage": "https://github.com/Drachenfels/python-schema" }, "release_url": "https://pypi.org/project/python-schema/0.4.1/", "requires_dist": null, "requires_python": ">=3.7", "summary": "Simple but not simplistic schema for data-validation", "version": "0.4.1", "yanked": false, "yanked_reason": null }, "last_serial": 6051802, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "9c56e50b7301bd4eeaf786374aafcb38", "sha256": "f19e41c087c23c524d93ee4d156372b29161e71a3baa6c645e0f508724f1b17f" }, "downloads": -1, "filename": "python_schema-0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "9c56e50b7301bd4eeaf786374aafcb38", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7", "size": 11911, "upload_time": "2018-12-03T00:15:55", "upload_time_iso_8601": "2018-12-03T00:15:55.372834Z", "url": "https://files.pythonhosted.org/packages/a1/34/10cee9e28649bec663642820ba5e9df0b45840ac2740f3dc7c4791538329/python_schema-0.1-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "3f6eb5aa5cf1dfeab4555703efa44678", "sha256": "38e1c3e783a457ceb43231673abf4659a376e2f83a2bdfb24e8cc536f775ffe1" }, "downloads": -1, "filename": "python_schema-0.1.tar.gz", "has_sig": false, "md5_digest": "3f6eb5aa5cf1dfeab4555703efa44678", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7", "size": 9919, "upload_time": "2018-12-03T00:15:57", "upload_time_iso_8601": "2018-12-03T00:15:57.408380Z", "url": "https://files.pythonhosted.org/packages/82/68/6f5170bd6f722332d252e9acb34d9d119d943deb16939a38500a730b28f1/python_schema-0.1.tar.gz", "yanked": false, "yanked_reason": null } ], "0.2": [ { "comment_text": "", "digests": { "md5": "69db15ec21f897acdad2b3795f14ed81", "sha256": "383cf2134a3003a2dd49d87230b82e2d21fe7c49269700f8a2aedc25ba25bd0e" }, "downloads": -1, "filename": "python_schema-0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "69db15ec21f897acdad2b3795f14ed81", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7", "size": 12443, "upload_time": "2018-12-05T19:31:27", "upload_time_iso_8601": "2018-12-05T19:31:27.237393Z", "url": "https://files.pythonhosted.org/packages/2a/11/2a16940bc5ce17aa537666da179c90c06bcfe061b5ff1eadc54b8a140b9f/python_schema-0.2-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "b55533e4dafd87d1d9d6718a3949b6e7", "sha256": "556379dfb80eeec1b56ed31257cba7b7dcf24b3bd2c3f1e5cf8b49bdf7cb336a" }, "downloads": -1, "filename": "python_schema-0.2.tar.gz", "has_sig": false, "md5_digest": "b55533e4dafd87d1d9d6718a3949b6e7", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7", "size": 10129, "upload_time": "2018-12-05T19:31:28", "upload_time_iso_8601": "2018-12-05T19:31:28.506147Z", "url": "https://files.pythonhosted.org/packages/42/97/3548905aa7ce162c6cfb4c582b4fc3e66a8274ff8979df39dcd30b676f70/python_schema-0.2.tar.gz", "yanked": false, "yanked_reason": null } ], "0.3": [ { "comment_text": "", "digests": { "md5": "574f7231bbd5f9674f8582c790c7efeb", "sha256": "ea0ff89dfda746895f0c7d880e484401a58d1ef5136879ca21711a2544cddb22" }, "downloads": -1, "filename": "python_schema-0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "574f7231bbd5f9674f8582c790c7efeb", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7", "size": 8658, "upload_time": "2018-12-30T20:30:43", "upload_time_iso_8601": "2018-12-30T20:30:43.009243Z", "url": "https://files.pythonhosted.org/packages/73/64/c991550abd0085efd5135580cbb38dd6e22580c7aead2575325ca37c6951/python_schema-0.3-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "26e3cd3d018e5d75978f935f83504a66", "sha256": "926d385b308aa2b44bfb2fef3f854e145f0507b462ec64e1689dd79635e6e2ad" }, "downloads": -1, "filename": "python_schema-0.3.tar.gz", "has_sig": false, "md5_digest": "26e3cd3d018e5d75978f935f83504a66", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7", "size": 6219, "upload_time": "2018-12-30T20:30:44", "upload_time_iso_8601": "2018-12-30T20:30:44.772502Z", "url": "https://files.pythonhosted.org/packages/87/ff/3142199f811afd2e74fe29bbbfccb44bf18317549c04392cc23f353502aa/python_schema-0.3.tar.gz", "yanked": false, "yanked_reason": null } ], "0.4": [ { "comment_text": "", "digests": { "md5": "0a1e02874f32c013be4e829420257962", "sha256": "3bce465a37f8c16db26e559256f34d4bcd122f2ef2d83bae6b06836299b5de3c" }, "downloads": -1, "filename": "python_schema-0.4-py3-none-any.whl", "has_sig": false, "md5_digest": "0a1e02874f32c013be4e829420257962", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7", "size": 12452, "upload_time": "2019-10-29T17:38:26", "upload_time_iso_8601": "2019-10-29T17:38:26.350058Z", "url": "https://files.pythonhosted.org/packages/31/ac/ff511cf3926c259e63e752a2d3df2d54e26c85c3e79df00e2590737a22c4/python_schema-0.4-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "07714deab59363451efbbb72c9895579", "sha256": "f5e9af6d36fbfd821ebce9a1be8e058bec6cdb4b019467a6092da83fe0759ed6" }, "downloads": -1, "filename": "python_schema-0.4.tar.gz", "has_sig": false, "md5_digest": "07714deab59363451efbbb72c9895579", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7", "size": 11821, "upload_time": "2019-10-29T17:38:28", "upload_time_iso_8601": "2019-10-29T17:38:28.430092Z", "url": "https://files.pythonhosted.org/packages/45/72/a0c626eb67e5fa0777e867e94e8f3c0fd2b4ced3813405387c32d3fab991/python_schema-0.4.tar.gz", "yanked": false, "yanked_reason": null } ], "0.4.1": [ { "comment_text": "", "digests": { "md5": "b18fecbe8eaa6f0a52b4f9ae7759dd2e", "sha256": "4e0eb26b50e542532671cd1cf7ec44d51b18af8afcfe168b83c83fe29f3af588" }, "downloads": -1, "filename": "python_schema-0.4.1-py3-none-any.whl", "has_sig": false, "md5_digest": "b18fecbe8eaa6f0a52b4f9ae7759dd2e", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7", "size": 12456, "upload_time": "2019-10-30T10:09:24", "upload_time_iso_8601": "2019-10-30T10:09:24.272771Z", "url": "https://files.pythonhosted.org/packages/d1/e0/dec57f63e260445683c9c68ddbd55d0c77a2d79182776eae5c10001d4b07/python_schema-0.4.1-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "06f90fbd2e4e7587af565477c615ff70", "sha256": "e15181ea1a8476d78212168848853b4232fd494cf5df7e80aac1695d9618eaef" }, "downloads": -1, "filename": "python_schema-0.4.1.tar.gz", "has_sig": false, "md5_digest": "06f90fbd2e4e7587af565477c615ff70", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7", "size": 11795, "upload_time": "2019-10-30T10:09:25", "upload_time_iso_8601": "2019-10-30T10:09:25.724799Z", "url": "https://files.pythonhosted.org/packages/e9/c3/325e40c91140196c39aa6806fceac5131b7a14b235024068fcb3546db19d/python_schema-0.4.1.tar.gz", "yanked": false, "yanked_reason": null } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "b18fecbe8eaa6f0a52b4f9ae7759dd2e", "sha256": "4e0eb26b50e542532671cd1cf7ec44d51b18af8afcfe168b83c83fe29f3af588" }, "downloads": -1, "filename": "python_schema-0.4.1-py3-none-any.whl", "has_sig": false, "md5_digest": "b18fecbe8eaa6f0a52b4f9ae7759dd2e", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7", "size": 12456, "upload_time": "2019-10-30T10:09:24", "upload_time_iso_8601": "2019-10-30T10:09:24.272771Z", "url": "https://files.pythonhosted.org/packages/d1/e0/dec57f63e260445683c9c68ddbd55d0c77a2d79182776eae5c10001d4b07/python_schema-0.4.1-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "06f90fbd2e4e7587af565477c615ff70", "sha256": "e15181ea1a8476d78212168848853b4232fd494cf5df7e80aac1695d9618eaef" }, "downloads": -1, "filename": "python_schema-0.4.1.tar.gz", "has_sig": false, "md5_digest": "06f90fbd2e4e7587af565477c615ff70", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7", "size": 11795, "upload_time": "2019-10-30T10:09:25", "upload_time_iso_8601": "2019-10-30T10:09:25.724799Z", "url": "https://files.pythonhosted.org/packages/e9/c3/325e40c91140196c39aa6806fceac5131b7a14b235024068fcb3546db19d/python_schema-0.4.1.tar.gz", "yanked": false, "yanked_reason": null } ], "vulnerabilities": [] }