{
"info": {
"author": "Zhiwei Zhang",
"author_email": "zhiwei2017@gmail.com",
"bugtrack_url": null,
"classifiers": [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: Implementation",
"Topic :: Utilities"
],
"description": "==========\nnamed-enum\n==========\n\n.. license badge\n.. image:: https://img.shields.io/pypi/l/named-enum.svg\n :target: https://pypi.python.org/pypi/named-enum/\n\n.. readthedocs badge\n.. image:: https://readthedocs.org/projects/named-enum/badge/?version=latest\n :target: https://named-enum.readthedocs.io/en/latest/?badge=latest\n :alt: Documentation Status\n\n.. travis building badge\n.. image:: https://travis-ci.com/KnightConan/named_enum.svg?branch=master\n :target: https://travis-ci.com/KnightConan/named_enum\n\n.. appveyor building badge\n.. image:: https://ci.appveyor.com/api/projects/status/fi9ayfyo1w4oi2w8/branch/master?svg=true\n :target: https://ci.appveyor.com/project/KnightConan/named-enum\n\n.. pypi version badge\n.. image:: https://img.shields.io/pypi/v/named-enum.svg\n :target: https://pypi.python.org/pypi/named-enum/\n\n.. development status from pypi\n.. image:: https://img.shields.io/pypi/status/named-enum.svg\n :target: https://pypi.python.org/pypi/named-enum/\n\n.. python version badge from PyPI\n.. image:: https://img.shields.io/pypi/pyversions/named-enum.svg\n :target: https://pypi.python.org/pypi/named-enum/\n :alt: Python 3.6 | Python 3.7\n\n.. pypi format\n.. image:: https://img.shields.io/pypi/format/named-enum.svg\n :target: https://badge.fury.io/py/named-enum\n\n.. codecov badge\n.. image:: https://codecov.io/gh/KnightConan/named_enum/branch/master/graph/badge.svg\n :target: https://codecov.io/gh/KnightConan/named_enum\n\n.. pyup badge\n.. image:: https://pyup.io/repos/github/KnightConan/named_enum/shield.svg\n :target: https://pyup.io/repos/github/KnightConan/named_enum/\n :alt: Updates\n\n.. download statistics badge\n.. image:: https://pepy.tech/badge/named-enum\n :target: https://pepy.tech/project/named-enum\n\n.. send message to the author\n.. image:: https://img.shields.io/badge/saythanks.io-\u263c-1EAEDB.svg\n :target: https://saythanks.io/to/KnightConan\n\nIntroduction\n------------\n\nThis package provides several enumeration classes, which extends the default **Enum** class with various functionalities. For each enumeration class, its enumeration item's value is a customised tuple type generated by **namedtuple** from **collections** package.\n\nThe idea of this package was inspired by `Cristian Alfonso Gonz\u00e1lez Mora `_.\n\nIf you like it, please |start|_ it in |github|_.\n\n.. |start| image:: https://img.icons8.com/material-rounded/26/000000/star.png\n :alt: star\n\n.. |github| image:: https://img.icons8.com/small/26/000000/github.png\n :alt: github\n\n.. _github: https://github.com/KnightConan/named_enum\n\n.. _start: https://github.com/KnightConan/named_enum\n\nInstallation\n------------\n\n .. code-block:: console\n\n pip install named-enum\n\nrunning test\n````````````\n\n .. code-block:: console\n\n python setup.py test\n\nQuick Start\n-----------\n\nEnumeration Creation\n````````````````````\n\nThere are two ways to create an enumeration.\n\n- Use the provided enumeration classes ``ExtendedEnum``, ``LabeledEnum``, ``PairEnum`` to declare your enumeration.\n\n .. code-block:: python\n\n from named_enum import ExtendedEnum, LabeledEnum, PairEnum\n\n class TVCouple(ExtendedEnum):\n GALLAGHERS = (\"FRANK\", \"MONICA\")\n MIKE_AND_MOLLY = (\"Mike\", \"Molly\")\n\n class NBALegendary(LabeledEnum):\n JOHNSON = (\"Johnson\", \"Magic Johnson\")\n JORDAN = (\"Jordan\", \"Air Jordan\")\n\n class Pair(PairEnum):\n TOM_AND_JERRY = (\"Tom\", \"Jerry\")\n BULLS = (\"Micheal\", \"Pippen\")\n\n- customise your own enumeration class and use it to define the enumeration.\n\n 1. create a new enumeration class\n\n + inherit from class ``NamedEnum``\n\n .. code-block:: python\n\n from named_enum import NamedEnum\n\n class TripleEnum(NamedEnum):\n \"\"\"using a sequence of strings to define the field names\"\"\"\n _field_names_ = (\"first\", \"second\", \"third\")\n\n + use function ``namedenum``\n\n .. code-block:: python\n\n from named_enum import namedenum\n\n # using a sequence of strings to define the field names\n TripleEnum = namedenum(\"TripleEnum\", (\"first\", \"second\", \"third\"))\n\n # using a comma/space separated string to define the field names\n TripleEnum = namedenum(\"LabelEnum\", \"key, label\")\n\n 2. create enumeration using the customized enumeration class in last step.\n\n .. code-block:: python\n\n class AnimationFamily(TripleEnum):\n SIMPSONS = (\"Homer\", \"Bart\", \"Marge\")\n DUCKS = (\"Huey\", \"Dewey\", \"Louie\")\n\nUsages\n``````\n+ ``names(as_tuple=True)``\n ``as_tuple=True``: returns the names of all enumeration items as a tuple.\n\n .. code-block:: python\n\n >>> AnimationFamily.names()\n ('SIMPSONS', 'DUCKS')\n\n ``as_tuple=False``: returns a generator of the names of all enumeration items.\n\n .. code-block:: python\n\n >>> from types import GeneratorType\n >>> isinstance(AnimationFamily.names(as_tuple=False), GeneratorType)\n True\n\n+ ``values(as_tuple=True)``\n ``as_tuple=True``: returns the values of all enumeration items as a tuple.\n\n .. code-block:: python\n\n # TripleEnum\n >>> AnimationFamily.values()\n (NamedTuple(first='Homer', second='Bart', third='Marge'), NamedTuple(first='Huey', second='Dewey', third='Louie'))\n\n # ExtendedEnum\n >>> TVCouple.values()\n (('FRANK', 'MONICA'), ('Mike', 'Molly'))\n\n ``as_tuple=False``: returns a generator of the values of all enumeration items.\n\n .. code-block:: python\n\n >>> import types\n >>> isinstance(AnimationFamily.values(as_tuple=False), GeneratorType)\n True\n\n+ ``describe()``\n displays the enumeration as a table.\n\n .. code-block:: python\n\n # TripleEnum\n >>> AnimationFamily.describe()\n Class: AnimationFamily\n Name | First | Second | Third\n ---------------------------------\n SIMPSONS | Homer | Bart | Marge\n DUCKS | Huey | Dewey | Louie\n \n\n # ExtendedEnum\n >>> TVCouple.describe()\n Class: TVCouple\n Name | Value\n ------------------------------------\n GALLAGHERS | ('FRANK', 'MONICA')\n MIKE_AND_MOLLY | ('Mike', 'Molly')\n \n\n+ ``gen(name_value_pair=True)``\n ``name_value_pair=True``: returns a generator comprised of name-value pair of each enumeration item\n\n .. code-block:: python\n\n # TripleEnum\n >>> tuple(AnimationFamily.gen())\n (('SIMPSONS', NamedTuple(first='Homer', second='Bart', third='Marge')), ('DUCKS', NamedTuple(first='Huey', second='Dewey', third='Louie')))\n\n # ExtendedEnum\n >>> tuple(TVCouple.gen())\n (('GALLAGHERS', ('FRANK', 'MONICA')), ('MIKE_AND_MOLLY', ('Mike', 'Molly')))\n\n ``name_value_pair=False``: returns a generator of enumeration items\n\n .. code-block:: python\n\n # TripleEnum\n >>> tuple(AnimationFamily.gen(name_value_pair=False))\n (, )\n\n # ExtendedEnum\n >>> tuple(TVCouple.gen(name_value_pair=False))\n (, )\n\n+ ``as_dict()``\n returns a dictionary, in which the key is the enumeration item's name and the value is the item's value\n\n .. code-block:: python\n\n # TripleEnum\n >>> AnimationFamily.as_dict()\n {'SIMPSONS': NamedTuple(first='Homer', second='Bart', third='Marge'), 'DUCKS': NamedTuple(first='Huey', second='Dewey', third='Louie')}\n\n # ExtendedEnum\n >>> TVCouple.as_dict()\n {'GALLAGHERS': ('FRANK', 'MONICA'), 'MIKE_AND_MOLLY': ('Mike', 'Molly')}\n\n+ ``as_set()``\n returns a set of tuples containing the enumeration item's name and value\n\n .. code-block:: python\n\n # TripleEnum\n >>> AnimationFamily.as_set()\n {('SIMPSONS', NamedTuple(first='Homer', second='Bart', third='Marge')), ('DUCKS', NamedTuple(first='Huey', second='Dewey', third='Louie'))}\n\n # ExtendedEnum\n >>> TVCouple.as_set()\n {('GALLAGHERS', ('FRANK', 'MONICA')), ('MIKE_AND_MOLLY', ('Mike', 'Molly'))}\n\n+ ``as_tuple()``\n returns a tuple of tuples containing the enumeration item's name and value\n\n .. code-block:: python\n\n # TripleEnum\n >>> AnimationFamily.as_tuple()\n (('SIMPSONS', NamedTuple(first='Homer', second='Bart', third='Marge')), ('DUCKS', NamedTuple(first='Huey', second='Dewey', third='Louie')))\n\n # ExtendedEnum\n >>> TVCouple.as_tuple()\n (('GALLAGHERS', ('FRANK', 'MONICA')), ('MIKE_AND_MOLLY', ('Mike', 'Molly')))\n\n+ ``as_list()``\n returns a list of tuples containing the enumeration item's name and value\n\n .. code-block:: python\n\n # TripleEnum\n >>> AnimationFamily.as_list()\n [('SIMPSONS', NamedTuple(first='Homer', second='Bart', third='Marge')), ('DUCKS', NamedTuple(first='Huey', second='Dewey', third='Louie'))]\n\n # ExtendedEnum\n >>> TVCouple.as_list()\n [('GALLAGHERS', ('FRANK', 'MONICA')), ('MIKE_AND_MOLLY', ('Mike', 'Molly'))]\n\n+ ``as_ordereddict()``\n returns an ordered dict, in which the key is the enumeration item's name and the value is the item's value\n\n .. code-block:: python\n\n # TripleEnum\n >>> AnimationFamily.as_ordereddict()\n OrderedDict([('SIMPSONS', NamedTuple(first='Homer', second='Bart', third='Marge')), ('DUCKS', NamedTuple(first='Huey', second='Dewey', third='Louie'))])\n\n # ExtendedEnum\n >>> TVCouple.as_ordereddict()\n OrderedDict([('GALLAGHERS', ('FRANK', 'MONICA')), ('MIKE_AND_MOLLY', ('Mike', 'Molly'))])\n\nIf you define the enumeration class with ``_field_names_`` variable, then for each field name in it 3 corresponding functions are generated and assigned to the enumeration class:\n\n - ``s(as_tuple=True)``\n ``as_tuple=True``: returns a tuple containing all corresponding values of the field in enumeration items\n\n .. code-block:: python\n\n # TripleEnum\n >>> AnimationFamily.firsts()\n ('Homer', 'Huey')\n >>> AnimationFamily.seconds()\n ('Bart', 'Dewey')\n >>> AnimationFamily.thirds()\n ('Marge', 'Louie')\n\n # LabeledEnum\n >>> NBALegendary.keys()\n ('Johnson', 'Jordan')\n >>> NBALegendary.labels()\n ('Magic Johnson', 'Air Jordan')\n\n ``as_tuple=False``: returns a generator of all corresponding values of the field in enumeration items\n\n .. code-block:: python\n\n # TripleEnum\n >>> isinstance(AnimationFamily.firsts(as_tuple=False), GeneratorType)\n True\n\n - ``from_(field_value, as_tuple=True)``\n ``as_tuple=True``: returns a tuple containing **all enumeration items** which has the given ``field_value`` in corresponding field\n\n .. code-block:: python\n\n # TripleEnum\n >>> AnimationFamily.from_first('Homer')\n (,)\n\n >>> AnimationFamily.from_second('Dewey')\n (,)\n\n >>> AnimationFamily.from_third('Marge')\n (,)\n\n # LabeledEnum\n >>> NBALegendary.from_key('Johnson')\n (,)\n\n >>> NBALegendary.from_label('Air Jordan')\n (,)\n\n ``as_tuple=False``: returns a generator of **all enumeration items** which has the given ``field_value`` in corresponding field\n\n .. code-block:: python\n\n # TripleEnum\n >>> isinstance(AnimationFamily.from_first('Homer', as_tuple=False), GeneratorType)\n True\n\n - ``has_(field_value)``\n returns a boolean value to indicate whether there is at least one enumeration item has the given ``field_value`` in corresponding field\n\n .. code-block:: python\n\n # TripleEnum\n >>> AnimationFamily.has_first('Homer')\n True\n >>> AnimationFamily.has_first('Holmes')\n False\n\n >>> AnimationFamily.has_second('Dewey')\n True\n >>> AnimationFamily.has_second('David')\n False\n\n >>> AnimationFamily.has_third('Louie')\n True\n >>> AnimationFamily.has_third('Louis')\n False\n\n # LabeledEnum\n >>> NBALegendary.has_key('Johnson')\n True\n >>> NBALegendary.has_key('John')\n False\n\n >>> NBALegendary.has_label('Air Jordan')\n True\n >>> NBALegendary.has_label('The Black Mamba')\n False\n\nDocumentation\n-------------\nThe documentation about this project is available in\n`Read the Docs `_.\n\n",
"description_content_type": "text/x-rst",
"docs_url": null,
"download_url": "",
"downloads": {
"last_day": -1,
"last_month": -1,
"last_week": -1
},
"home_page": "https://github.com/KnightConan/named_enum",
"keywords": "",
"license": "MIT License",
"maintainer": "",
"maintainer_email": "",
"name": "named-enum",
"package_url": "https://pypi.org/project/named-enum/",
"platform": "",
"project_url": "https://pypi.org/project/named-enum/",
"project_urls": {
"Homepage": "https://github.com/KnightConan/named_enum"
},
"release_url": "https://pypi.org/project/named-enum/1.0.0/",
"requires_dist": null,
"requires_python": "",
"summary": "Named Enumeration",
"version": "1.0.0"
},
"last_serial": 4969546,
"releases": {
"0.1.0": [
{
"comment_text": "",
"digests": {
"md5": "ce898b10b1991b93fa6ffdaef88e0948",
"sha256": "5dc84e27efa7f640ef28a259edbd06f1d0d51fa219b396b1913c3fd9f849c4c6"
},
"downloads": -1,
"filename": "named_enum-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ce898b10b1991b93fa6ffdaef88e0948",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 10416,
"upload_time": "2018-12-05T15:12:09",
"url": "https://files.pythonhosted.org/packages/cf/12/0852db2c610c0d9074256f8ad1f2db341d6d1171e9d2321d84212aced033/named_enum-0.1.0-py3-none-any.whl"
},
{
"comment_text": "",
"digests": {
"md5": "2aa2631bf6596336010a874c8bbc96a0",
"sha256": "b0638b3178115d9d8228d447e7f3824be26f2ec434ff2ba716ccd0011d8cdb8f"
},
"downloads": -1,
"filename": "named_enum-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "2aa2631bf6596336010a874c8bbc96a0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 10851,
"upload_time": "2018-12-05T15:12:11",
"url": "https://files.pythonhosted.org/packages/e8/df/f432935655a1ab1f2629616846c9e4a11db12bdc615c17dc8c3be64ea5db/named_enum-0.1.0.tar.gz"
}
],
"1.0.0": [
{
"comment_text": "",
"digests": {
"md5": "df0fc1cf79015d5a44c65529728ebe52",
"sha256": "1c793943c788cf2fdf6c00f6d19d99f8eb11f573acad954382646b9d16ff9d90"
},
"downloads": -1,
"filename": "named_enum-1.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "df0fc1cf79015d5a44c65529728ebe52",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 12932,
"upload_time": "2019-03-21T19:07:42",
"url": "https://files.pythonhosted.org/packages/a6/02/5d1623d205b6983498b14213c52453f971a7fbb6b44201ae2e83d5c2ee8c/named_enum-1.0.0-py3-none-any.whl"
},
{
"comment_text": "",
"digests": {
"md5": "a87976e3852cb571f004186a2245a081",
"sha256": "2f3073e518837cf20e8b5c68917f19a92d9a1cf5db8d9f488b69fa0ff3ebba1b"
},
"downloads": -1,
"filename": "named_enum-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "a87976e3852cb571f004186a2245a081",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 15584,
"upload_time": "2019-03-21T19:07:44",
"url": "https://files.pythonhosted.org/packages/54/37/f43a1043c7631e23c91b2872be0bca116153f41f673451daad907a161f15/named_enum-1.0.0.tar.gz"
}
]
},
"urls": [
{
"comment_text": "",
"digests": {
"md5": "df0fc1cf79015d5a44c65529728ebe52",
"sha256": "1c793943c788cf2fdf6c00f6d19d99f8eb11f573acad954382646b9d16ff9d90"
},
"downloads": -1,
"filename": "named_enum-1.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "df0fc1cf79015d5a44c65529728ebe52",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 12932,
"upload_time": "2019-03-21T19:07:42",
"url": "https://files.pythonhosted.org/packages/a6/02/5d1623d205b6983498b14213c52453f971a7fbb6b44201ae2e83d5c2ee8c/named_enum-1.0.0-py3-none-any.whl"
},
{
"comment_text": "",
"digests": {
"md5": "a87976e3852cb571f004186a2245a081",
"sha256": "2f3073e518837cf20e8b5c68917f19a92d9a1cf5db8d9f488b69fa0ff3ebba1b"
},
"downloads": -1,
"filename": "named_enum-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "a87976e3852cb571f004186a2245a081",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 15584,
"upload_time": "2019-03-21T19:07:44",
"url": "https://files.pythonhosted.org/packages/54/37/f43a1043c7631e23c91b2872be0bca116153f41f673451daad907a161f15/named_enum-1.0.0.tar.gz"
}
]
}