{ "info": { "author": "sobolevn", "author_email": "mail@sobolevn.me", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Utilities" ], "description": "# classes\n\n[](https://github.com/dry-python/classes)\n\n-----\n\n[](https://travis-ci.org/dry-python/classes)\n[](https://codecov.io/gh/dry-python/classes)\n[](https://classes.readthedocs.io/en/latest/?badge=latest)\n[](https://pypi.org/project/classes/)\n[](https://github.com/wemake-services/wemake-python-styleguide)\n[](https://t.me/drypython)\n\n-----\n\nSmart, pythonic, ad-hoc, typed polymorphism for Python.\n\n\n## Features\n\n- Provides a bunch of primitives to write declarative business logic\n- Enforces better architecture\n- Fully typed with annotations and checked with `mypy`, [PEP561 compatible](https://www.python.org/dev/peps/pep-0561/)\n- Allows to write a lot of simple code without inheritance or interfaces\n- Pythonic and pleasant to write and to read (!)\n- Easy to start: has lots of docs, tests, and tutorials\n\n\n## Installation\n\n```bash\npip install classes\n```\n\nYou also need to [configure](https://classes.readthedocs.io/en/latest/pages/container.html#type-safety)\n`mypy` correctly and install our plugin:\n\n```ini\n# In setup.cfg or mypy.ini:\n[mypy]\nplugins =\n classes.contrib.mypy.classes_plugin\n```\n\n**Without this step**, your project will report type-violations here and there.\n\nWe also recommend to use the same `mypy` settings [we use](https://github.com/wemake-services/wemake-python-styleguide/blob/master/styles/mypy.toml).\n\nMake sure you know how to get started, [check out our docs](https://classes.readthedocs.io/en/latest/)!\n\n\n## Example\n\nImagine, that you want to bound implementation to some particular type.\nLike, strings behave like this, numbers behave like that, and so on.\n\nThe good realworld example is `djangorestframework`.\nIt is build around the idea that different\ndata types should be converted differently to and from `json` format.\n\nWhat is the \"traditional\" (or outdated if you will!) approach?\nTo create tons of classes for different data types and use them.\n\nThat's how we end up with classes like so:\n\n```python\nclass IntField(Field):\n def from_json(self, value):\n return value\n\n def to_json(self, value):\n return value\n```\n\nIt literally has a lot of problems:\n\n- It is hard to type this code. How can I be sure that my `json` is parseable by the given schema?\n- It produces a lot of boilerplate\n- It has complex API: there are usually several methods to override, some fields to adjust. Moreover, we use a class, not a simple function\n- It is hard to extend the default library for new custom types you will have in your own project\n- It is hard to override\n\nThere should be a better way of solving this problem!\nAnd typeclasses are a better way!\n\nHow would new API look like with this concept?\n\n```python\n>>> from typing import Union\n>>> from classes import typeclass\n\n>>> @typeclass\n... def to_json(instance) -> str:\n... \"\"\"This is a typeclass definition to convert things to json.\"\"\"\n\n>>> @to_json.instance(int)\n... @to_json.instance(float)\n... def _to_json_int(instance: Union[int, float]) -> str:\n... return str(instance)\n\n>>> @to_json.instance(bool)\n... def _to_json_bool(instance: bool) -> str:\n... return 'true' if instance else 'false'\n\n>>> @to_json.instance(list)\n... def _to_json_list(instance: list) -> str:\n... return '[{0}]'.format(\n... ', '.join(to_json(list_item) for list_item in instance),\n... )\n\n```\n\nSee how easy it is to works with types and implementation?\n\nTypeclass is represented as a regular function, so you can use it like one:\n\n```python\n>>> to_json(True)\n'true'\n>>> to_json(1)\n'1'\n>>> to_json([False, 1, 2.5])\n'[false, 1, 2.5]'\n\n```\n\nAnd it easy to extend this typeclass with your own classes as well:\n\n```python\n# Pretending to import the existing library from somewhere:\n# from to_json import to_json\n\n>>> import datetime as dt\n\n>>> @to_json.instance(dt.datetime)\n... def _to_json_datetime(instance: dt.datetime) -> str:\n... return instance.isoformat()\n\n>>> to_json(dt.datetime(2019, 10, 31, 12, 28, 00))\n'2019-10-31T12:28:00'\n\n```\n\nThat's how simple, safe, and powerful typeclasses are!\nMake sure to [check out our full docs](https://github.com/dry-python/classes) to learn more.\n\n\n## More!\n\nWant more? [Go to the docs!](https://classes.readthedocs.io) Or read these articles:\n- [Typeclasses in Python](https://sobolevn.me/2021/06/typeclasses-in-python)\n\n\n
— \u2b50\ufe0f —
\nDrylabs maintains dry-python and helps those who want to use it inside their organizations.
\nRead more at drylabs.io
\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://classes.readthedocs.io", "keywords": "functional programming,fp,type class,typeclass,typeclasses,ad-hoc,composition,type-safety,mypy,stubs", "license": "BSD-2-Clause", "maintainer": "", "maintainer_email": "", "name": "classes", "package_url": "https://pypi.org/project/classes/", "platform": null, "project_url": "https://pypi.org/project/classes/", "project_urls": { "Homepage": "https://classes.readthedocs.io", "Repository": "https://github.com/dry-python/classes" }, "release_url": "https://pypi.org/project/classes/0.4.1/", "requires_dist": [ "typing_extensions (>=3.10,<5.0)" ], "requires_python": ">=3.7,<4.0", "summary": "Smart, pythonic, ad-hoc, typed polymorphism for Python", "version": "0.4.1", "yanked": false, "yanked_reason": null }, "last_serial": 13479185, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "54843b586010ae5df70e926ace8fd653", "sha256": "7929e650d4c4b04b0307fca1edac5dde4f0a07ceaf985f88ef942a2edb6466df" }, "downloads": -1, "filename": "classes-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "54843b586010ae5df70e926ace8fd653", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 3355, "upload_time": "2019-10-25T19:44:25", "upload_time_iso_8601": "2019-10-25T19:44:25.239630Z", "url": "https://files.pythonhosted.org/packages/53/13/e14702cb869f9fea25568a86893d6769bfcb62bee46ade1a49148d00de5d/classes-0.0.1-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "06d77cfccc45610aba26121c7d83bdd5", "sha256": "a5b7dd0a2fa64c89ac65c6309f011d27d3929ee227e8a8241a182a6a7869d207" }, "downloads": -1, "filename": "classes-0.0.1.tar.gz", "has_sig": false, "md5_digest": "06d77cfccc45610aba26121c7d83bdd5", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 3025, "upload_time": "2019-10-25T19:44:27", "upload_time_iso_8601": "2019-10-25T19:44:27.918872Z", "url": "https://files.pythonhosted.org/packages/15/a7/082d067a5b42a0549b634096a235d6b98425f40a4c925f2a5240185b3cd4/classes-0.0.1.tar.gz", "yanked": false, "yanked_reason": null } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "f13a9feb8a1dafbe6a599f96cac659e5", "sha256": "aecf45bb816be9fc68f5ad5a8788e3ac9d5ca3c7d266d20ed1b48f0854e81a6f" }, "downloads": -1, "filename": "classes-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "f13a9feb8a1dafbe6a599f96cac659e5", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 9474, "upload_time": "2019-10-31T09:51:31", "upload_time_iso_8601": "2019-10-31T09:51:31.220985Z", "url": "https://files.pythonhosted.org/packages/4d/cd/b997f89a687634f150f0ca1070aa2b9789bb02277676de0209cfc8de1a09/classes-0.1.0-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "8c8233434e904cf1e41120f82cde0a19", "sha256": "0cac8e05f7b825ac3de0566a0bf65acc59a3298e751d5da18faad1f3d3f0bc1a" }, "downloads": -1, "filename": "classes-0.1.0.tar.gz", "has_sig": false, "md5_digest": "8c8233434e904cf1e41120f82cde0a19", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 10712, "upload_time": "2019-10-31T09:51:33", "upload_time_iso_8601": "2019-10-31T09:51:33.099026Z", "url": "https://files.pythonhosted.org/packages/e0/65/f28e1db714b3fc64bc9e0f0746b654fc1c5448c211504011ac4b5d89be83/classes-0.1.0.tar.gz", "yanked": false, "yanked_reason": null } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "708129257ad7ae56fa3495b46eb076db", "sha256": "39fcc9378a83ecb038e98f6efa3a91dfd018be13365387af30037120e12bf94b" }, "downloads": -1, "filename": "classes-0.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "708129257ad7ae56fa3495b46eb076db", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 9447, "upload_time": "2021-02-16T21:27:32", "upload_time_iso_8601": "2021-02-16T21:27:32.962434Z", "url": "https://files.pythonhosted.org/packages/ec/b2/f54381bba1d4ebae913e02b965782acbd5943177bc16d8a2d34098f55027/classes-0.2.0-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "292981214bdf4ebc8ba8b17ce48a5fa2", "sha256": "a94278976870aa8d248a65b53f079e91a4ba1244e489aabd10f6027d2b1ffdd2" }, "downloads": -1, "filename": "classes-0.2.0.tar.gz", "has_sig": false, "md5_digest": "292981214bdf4ebc8ba8b17ce48a5fa2", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 10759, "upload_time": "2021-02-16T21:27:34", "upload_time_iso_8601": "2021-02-16T21:27:34.942610Z", "url": "https://files.pythonhosted.org/packages/b3/84/e5d1250b8f38c030c607f39bdd9f92ad27ab3e2906b3f5f08766a7f35675/classes-0.2.0.tar.gz", "yanked": false, "yanked_reason": null } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "206d4c8a074f2025aa6c494a1282c4ef", "sha256": "7b7706de19e2fd2381b5b518e3cbcebf783912afef7caba3d050edc97489d7b8" }, "downloads": -1, "filename": "classes-0.3.0-py3-none-any.whl", "has_sig": false, "md5_digest": "206d4c8a074f2025aa6c494a1282c4ef", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7,<4.0", "size": 28488, "upload_time": "2021-06-20T08:12:05", "upload_time_iso_8601": "2021-06-20T08:12:05.256523Z", "url": "https://files.pythonhosted.org/packages/19/9a/5d83ec6fd9b58b55d49f3201555b13a699ae409ad4bc098a784ef4b5ed8c/classes-0.3.0-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "916b529b3eb773b75fcc32bfc7044796", "sha256": "c7bad585ca957dd2cf1418df1978375bd33bf7d905213528e41ba1cdba261f70" }, "downloads": -1, "filename": "classes-0.3.0.tar.gz", "has_sig": false, "md5_digest": "916b529b3eb773b75fcc32bfc7044796", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7,<4.0", "size": 23756, "upload_time": "2021-06-20T08:12:07", "upload_time_iso_8601": "2021-06-20T08:12:07.499073Z", "url": "https://files.pythonhosted.org/packages/5a/fb/d9f7c1da87ab91b06141a0d2726450b80a6451c5cac9093937f4d6b6cf86/classes-0.3.0.tar.gz", "yanked": false, "yanked_reason": null } ], "0.4.0": [ { "comment_text": "", "digests": { "md5": "b818b2f92c35322ccd2f422a2f0fde4f", "sha256": "b73394c070a80e0f8b9fe44eac8eee8703a3d35302248fcab194db78d37690bd" }, "downloads": -1, "filename": "classes-0.4.0-py3-none-any.whl", "has_sig": false, "md5_digest": "b818b2f92c35322ccd2f422a2f0fde4f", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7,<4.0", "size": 37037, "upload_time": "2021-08-17T11:24:15", "upload_time_iso_8601": "2021-08-17T11:24:15.665749Z", "url": "https://files.pythonhosted.org/packages/9b/5c/9595f433609c2901a88b39855e328bae60052bb94335bb759cdf894ee004/classes-0.4.0-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "8eef826d8aff8f76934a1f19de05210e", "sha256": "32d96f78a9dff5830f24dfbf3f5f018bb169b8aa6325a8f88423290ccd35d030" }, "downloads": -1, "filename": "classes-0.4.0.tar.gz", "has_sig": false, "md5_digest": "8eef826d8aff8f76934a1f19de05210e", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7,<4.0", "size": 28814, "upload_time": "2021-08-17T11:24:17", "upload_time_iso_8601": "2021-08-17T11:24:17.494373Z", "url": "https://files.pythonhosted.org/packages/fe/f6/b342ceb811cb0757c84f05d3758c4e9bdc92d96f026099e0423d6c164d92/classes-0.4.0.tar.gz", "yanked": false, "yanked_reason": null } ], "0.4.1": [ { "comment_text": "", "digests": { "md5": "f52d83f16e99ab0464d1075f5e41afda", "sha256": "934a19eb23d2fe0c0430af6eae6d81a4d4fcc53519cf737f69c3bba3994d54e9" }, "downloads": -1, "filename": "classes-0.4.1-py3-none-any.whl", "has_sig": false, "md5_digest": "f52d83f16e99ab0464d1075f5e41afda", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7,<4.0", "size": 36947, "upload_time": "2022-04-11T15:21:53", "upload_time_iso_8601": "2022-04-11T15:21:53.678873Z", "url": "https://files.pythonhosted.org/packages/7d/b4/56b2f3a02120013daef821373ac02f31e7451b1fb5301007b89806e19426/classes-0.4.1-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "821fa17425c2a0ecba57d90f48296869", "sha256": "4de4fdd6c5c38607bbd8ad76703d7cc4dbe007cfa78e8ef1f62fc6ac55303e23" }, "downloads": -1, "filename": "classes-0.4.1.tar.gz", "has_sig": false, "md5_digest": "821fa17425c2a0ecba57d90f48296869", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7,<4.0", "size": 28771, "upload_time": "2022-04-11T15:21:55", "upload_time_iso_8601": "2022-04-11T15:21:55.877078Z", "url": "https://files.pythonhosted.org/packages/42/6c/543dc06fcd4d076d1399978971ebedfb90a7bd4315a9d4357f080e73fcae/classes-0.4.1.tar.gz", "yanked": false, "yanked_reason": null } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "f52d83f16e99ab0464d1075f5e41afda", "sha256": "934a19eb23d2fe0c0430af6eae6d81a4d4fcc53519cf737f69c3bba3994d54e9" }, "downloads": -1, "filename": "classes-0.4.1-py3-none-any.whl", "has_sig": false, "md5_digest": "f52d83f16e99ab0464d1075f5e41afda", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7,<4.0", "size": 36947, "upload_time": "2022-04-11T15:21:53", "upload_time_iso_8601": "2022-04-11T15:21:53.678873Z", "url": "https://files.pythonhosted.org/packages/7d/b4/56b2f3a02120013daef821373ac02f31e7451b1fb5301007b89806e19426/classes-0.4.1-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "821fa17425c2a0ecba57d90f48296869", "sha256": "4de4fdd6c5c38607bbd8ad76703d7cc4dbe007cfa78e8ef1f62fc6ac55303e23" }, "downloads": -1, "filename": "classes-0.4.1.tar.gz", "has_sig": false, "md5_digest": "821fa17425c2a0ecba57d90f48296869", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7,<4.0", "size": 28771, "upload_time": "2022-04-11T15:21:55", "upload_time_iso_8601": "2022-04-11T15:21:55.877078Z", "url": "https://files.pythonhosted.org/packages/42/6c/543dc06fcd4d076d1399978971ebedfb90a7bd4315a9d4357f080e73fcae/classes-0.4.1.tar.gz", "yanked": false, "yanked_reason": null } ], "vulnerabilities": [] }