named-enum


Namenamed-enum JSON
Version 1.4.0 PyPI version JSON
download
home_pagehttps://github.com/zhiwei2017/named_enum
SummaryPython named enumeration, which extends the built-in Enum class with extra features.
upload_time2023-10-30 10:46:21
maintainer
docs_urlNone
authorZhiwei Zhang
requires_python>=3.8.1,<4.0.0
licenseMIT
keywords operating system :: os independent license :: osi approved :: mit license development status :: 5 - production/stable programming language :: python programming language :: python :: 3 programming language :: python :: 3.8 programming language :: python :: 3.9 programming language :: python :: 3.10 programming language :: python :: 3.11 programming language :: python :: 3.12 programming language :: python :: implementation topic :: utilities natural language :: english intended audience :: developers
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            named-enum
==========

.. license badge
.. image:: https://img.shields.io/pypi/l/named-enum.svg
    :target: https://pypi.python.org/pypi/named-enum/

.. readthedocs badge
.. image:: https://readthedocs.org/projects/named-enum/badge/?version=latest
    :target: https://named-enum.readthedocs.io/en/latest/?badge=latest
    :alt: Documentation Status

.. actions building badge
.. image:: https://github.com/zhiwei2017/named_enum/workflows/Unit%20Test%20&%20Build%20Test/badge.svg
    :target: https://github.com/zhiwei2017/named_enum/actions

.. pypi version badge
.. image:: https://img.shields.io/pypi/v/named-enum.svg
    :target: https://pypi.python.org/pypi/named-enum/

.. development status from pypi
.. image:: https://img.shields.io/pypi/status/named-enum.svg
    :target: https://pypi.python.org/pypi/named-enum/

.. python version badge from PyPI
.. image:: https://img.shields.io/pypi/pyversions/named-enum.svg
    :target: https://pypi.python.org/pypi/named-enum/
    :alt: Python 3.7 | Python 3.8 | Python3.9 | Python3.10 | Python3.11 | 3.12

.. pypi format
.. image:: https://img.shields.io/pypi/format/named-enum.svg
    :target: https://badge.fury.io/py/named-enum

.. codecov badge
.. image:: https://codecov.io/gh/zhiwei2017/named_enum/branch/master/graph/badge.svg
    :target: https://codecov.io/gh/zhiwei2017/named_enum

.. pyup badge
.. image:: https://pyup.io/repos/github/zhiwei2017/named_enum/shield.svg
    :target: https://pyup.io/repos/github/zhiwei2017/named_enum/
    :alt: Updates

.. download statistics badge
.. image:: https://pepy.tech/badge/named-enum
    :target: https://pepy.tech/project/named-enum

.. Quality Gate Status
.. image:: https://sonarcloud.io/api/project_badges/measure?project=KnightConan_named_enum&metric=alert_status
    :target: https://sonarcloud.io/dashboard?id=KnightConan_named_enum


Introduction
------------

This 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.

Installation
------------

Stable release
``````````````

To install Named Enum, run this command in your terminal:

.. code-block:: console

    $ pip install named_enum

or

.. code-block:: console

    $ poetry self add named_enum

This is the preferred method to install Named Enum, as it will always install the most recent stable release.


From sources
````````````

The sources for Named Enum can be downloaded from the `Github repo <https://github.com/zhiwei2017/named_enum>`_.

You can either clone the public repository:

.. code-block:: console

    $ git clone https://github.com/zhiwei2017/named_enum.git

Once you have a copy of the source, you can install it with:

.. code-block:: console

    $ pip install .

or

.. code-block:: console

    $ poetry install

Quick Start
-----------

Enumeration Creation
````````````````````

There are two ways to create an enumeration.

- Use the provided enumeration classes ``ExtendedEnum``, ``LabeledEnum``, ``PairEnum`` to declare your enumeration.

  .. code-block:: python

     from named_enum import ExtendedEnum, LabeledEnum, PairEnum

     class TVCouple(ExtendedEnum):
         GALLAGHERS = ("FRANK", "MONICA")
         MIKE_AND_MOLLY = ("Mike", "Molly")

     class NBALegendary(LabeledEnum):
         JOHNSON = ("Johnson", "Magic Johnson")
         JORDAN = ("Jordan", "Air Jordan")

     class Pair(PairEnum):
         TOM_AND_JERRY = ("Tom", "Jerry")
         BULLS = ("Micheal", "Pippen")

- Customise your own enumeration class and use it to define the enumeration.

  1. Create a new enumeration class

    + Inherit from class ``NamedEnum``

      .. code-block:: python

         from named_enum import NamedEnum

         class TripleEnum(NamedEnum):
             """using a sequence of strings to define the field names"""
             _field_names_ = ("first", "second", "third")

    + Use function ``namedenum``

      .. code-block:: python

        from named_enum import namedenum

        # using a sequence of strings to define the field names
        TripleEnum = namedenum("TripleEnum", ("first", "second", "third"))

        # using a comma/space separated string to define the field names
        TripleEnum = namedenum("LabelEnum", "key, label")

  2. Create enumeration using the customized enumeration class in last step.

      .. code-block:: python

         class AnimationFamily(TripleEnum):
             SIMPSONS = ("Homer", "Bart", "Marge")
             DUCKS = ("Huey", "Dewey", "Louie")

Usages
``````
+ ``names(as_tuple=True)``
    ``as_tuple=True``: returns the names of all enumeration items as a tuple.

    .. code-block:: python

      >>> AnimationFamily.names()
      ('SIMPSONS', 'DUCKS')

    ``as_tuple=False``: returns a generator of the names of all enumeration items.

    .. code-block:: python

      >>> from types import GeneratorType
      >>> isinstance(AnimationFamily.names(as_tuple=False), GeneratorType)
      True

+ ``values(as_tuple=True)``
    ``as_tuple=True``: returns the values of all enumeration items as a tuple.

    .. code-block:: python

      # TripleEnum
      >>> AnimationFamily.values()
      (NamedTuple(first='Homer', second='Bart', third='Marge'), NamedTuple(first='Huey', second='Dewey', third='Louie'))

      # ExtendedEnum
      >>> TVCouple.values()
      (('FRANK', 'MONICA'), ('Mike', 'Molly'))

    ``as_tuple=False``: returns a generator of the values of all enumeration items.

    .. code-block:: python

      >>> import types
      >>> isinstance(AnimationFamily.values(as_tuple=False), GeneratorType)
      True

+ ``describe()``
    displays the enumeration as a table.

    .. code-block:: python

      # TripleEnum
      >>> AnimationFamily.describe()
      Class: AnimationFamily
          Name | First | Second | Third
      ---------------------------------
      SIMPSONS | Homer |   Bart | Marge
         DUCKS |  Huey |  Dewey | Louie
      <BLANKLINE>

      # ExtendedEnum
      >>> TVCouple.describe()
      Class: TVCouple
                Name |               Value
      ------------------------------------
          GALLAGHERS | ('FRANK', 'MONICA')
      MIKE_AND_MOLLY |   ('Mike', 'Molly')
      <BLANKLINE>

+ ``gen(name_value_pair=True)``
    ``name_value_pair=True``: returns a generator comprised of name-value pair of each enumeration item

    .. code-block:: python

      # TripleEnum
      >>> tuple(AnimationFamily.gen())
      (('SIMPSONS', NamedTuple(first='Homer', second='Bart', third='Marge')), ('DUCKS', NamedTuple(first='Huey', second='Dewey', third='Louie')))

      # ExtendedEnum
      >>> tuple(TVCouple.gen())
      (('GALLAGHERS', ('FRANK', 'MONICA')), ('MIKE_AND_MOLLY', ('Mike', 'Molly')))

    ``name_value_pair=False``: returns a generator of enumeration items

    .. code-block:: python

      # TripleEnum
      >>> tuple(AnimationFamily.gen(name_value_pair=False))
      (<AnimationFamily.SIMPSONS: NamedTuple(first='Homer', second='Bart', third='Marge')>, <AnimationFamily.DUCKS: NamedTuple(first='Huey', second='Dewey', third='Louie')>)

      # ExtendedEnum
      >>> tuple(TVCouple.gen(name_value_pair=False))
      (<TVCouple.GALLAGHERS: ('FRANK', 'MONICA')>, <TVCouple.MIKE_AND_MOLLY: ('Mike', 'Molly')>)

+ ``as_dict()``
    returns a dictionary, in which the key is the enumeration item's name and the value is the item's value

    .. code-block:: python

      # TripleEnum
      >>> AnimationFamily.as_dict()
      {'SIMPSONS': NamedTuple(first='Homer', second='Bart', third='Marge'), 'DUCKS': NamedTuple(first='Huey', second='Dewey', third='Louie')}

      # ExtendedEnum
      >>> TVCouple.as_dict()
      {'GALLAGHERS': ('FRANK', 'MONICA'), 'MIKE_AND_MOLLY': ('Mike', 'Molly')}

+ ``as_set()``
    returns a set of tuples containing the enumeration item's name and value

    .. code-block:: python

      # TripleEnum
      >>> AnimationFamily.as_set()
      {('SIMPSONS', NamedTuple(first='Homer', second='Bart', third='Marge')), ('DUCKS', NamedTuple(first='Huey', second='Dewey', third='Louie'))}

      # ExtendedEnum
      >>> TVCouple.as_set()
      {('GALLAGHERS', ('FRANK', 'MONICA')), ('MIKE_AND_MOLLY', ('Mike', 'Molly'))}

+ ``as_tuple()``
    returns a tuple of tuples containing the enumeration item's name and value

    .. code-block:: python

      # TripleEnum
      >>> AnimationFamily.as_tuple()
      (('SIMPSONS', NamedTuple(first='Homer', second='Bart', third='Marge')), ('DUCKS', NamedTuple(first='Huey', second='Dewey', third='Louie')))

      # ExtendedEnum
      >>> TVCouple.as_tuple()
      (('GALLAGHERS', ('FRANK', 'MONICA')), ('MIKE_AND_MOLLY', ('Mike', 'Molly')))

+ ``as_list()``
    returns a list of tuples containing the enumeration item's name and value

    .. code-block:: python

      # TripleEnum
      >>> AnimationFamily.as_list()
      [('SIMPSONS', NamedTuple(first='Homer', second='Bart', third='Marge')), ('DUCKS', NamedTuple(first='Huey', second='Dewey', third='Louie'))]

      # ExtendedEnum
      >>> TVCouple.as_list()
      [('GALLAGHERS', ('FRANK', 'MONICA')), ('MIKE_AND_MOLLY', ('Mike', 'Molly'))]

+ ``as_ordereddict()``
    returns an ordered dict, in which the key is the enumeration item's name and the value is the item's value

    .. code-block:: python

      # TripleEnum
      >>> AnimationFamily.as_ordereddict()
      OrderedDict([('SIMPSONS', NamedTuple(first='Homer', second='Bart', third='Marge')), ('DUCKS', NamedTuple(first='Huey', second='Dewey', third='Louie'))])

      # ExtendedEnum
      >>> TVCouple.as_ordereddict()
      OrderedDict([('GALLAGHERS', ('FRANK', 'MONICA')), ('MIKE_AND_MOLLY', ('Mike', 'Molly'))])

If 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:

- ``<field_name>s(as_tuple=True)``
    ``as_tuple=True``: returns a tuple containing all corresponding values of the field in enumeration items

    .. code-block:: python

      # TripleEnum
      >>> AnimationFamily.firsts()
      ('Homer', 'Huey')
      >>> AnimationFamily.seconds()
      ('Bart', 'Dewey')
      >>> AnimationFamily.thirds()
      ('Marge', 'Louie')

      # LabeledEnum
      >>> NBALegendary.keys()
      ('Johnson', 'Jordan')
      >>> NBALegendary.labels()
      ('Magic Johnson', 'Air Jordan')

    ``as_tuple=False``: returns a generator of all corresponding values of the field in enumeration items

    .. code-block:: python

      # TripleEnum
      >>> isinstance(AnimationFamily.firsts(as_tuple=False), GeneratorType)
      True

- ``from_<field_name>(field_value, as_tuple=True)``
    ``as_tuple=True``: returns a tuple containing **all enumeration items** which has the given ``field_value`` in corresponding field

    .. code-block:: python

      # TripleEnum
      >>> AnimationFamily.from_first('Homer')
      (<AnimationFamily.SIMPSONS: NamedTuple(first='Homer', second='Bart', third='Marge')>,)

      >>> AnimationFamily.from_second('Dewey')
      (<AnimationFamily.DUCKS: NamedTuple(first='Huey', second='Dewey', third='Louie')>,)

      >>> AnimationFamily.from_third('Marge')
      (<AnimationFamily.SIMPSONS: NamedTuple(first='Homer', second='Bart', third='Marge')>,)

      # LabeledEnum
      >>> NBALegendary.from_key('Johnson')
      (<NBALegendary.JOHNSON: NamedTuple(key='Johnson', label='Magic Johnson')>,)

      >>> NBALegendary.from_label('Air Jordan')
      (<NBALegendary.Jordan: NamedTuple(key='Jordan', label='Air Jordan')>,)

    ``as_tuple=False``: returns a generator of **all enumeration items** which has the given ``field_value`` in corresponding field

    .. code-block:: python

      # TripleEnum
      >>> isinstance(AnimationFamily.from_first('Homer', as_tuple=False), GeneratorType)
      True

- ``has_<field_name>(field_value)``
    returns a boolean value to indicate whether there is at least one enumeration item has the given ``field_value`` in corresponding field

    .. code-block:: python

      # TripleEnum
      >>> AnimationFamily.has_first('Homer')
      True
      >>> AnimationFamily.has_first('Holmes')
      False

      >>> AnimationFamily.has_second('Dewey')
      True
      >>> AnimationFamily.has_second('David')
      False

      >>> AnimationFamily.has_third('Louie')
      True
      >>> AnimationFamily.has_third('Louis')
      False

      # LabeledEnum
      >>> NBALegendary.has_key('Johnson')
      True
      >>> NBALegendary.has_key('John')
      False

      >>> NBALegendary.has_label('Air Jordan')
      True
      >>> NBALegendary.has_label('The Black Mamba')
      False

Documentation
-------------
The documentation about this project is available in
`Read the Docs <https://named-enum.readthedocs.io/en/latest/>`_.

Acknowledgement
---------------
- `Cristian Alfonso González Mora <https://github.com/cagonza6/>`_ for the inspiration of this project.

Author
------

* `Zhiwei Zhang <https://github.com/zhiwei2017>`_ - *Maintainer* - `zhiwei2017@gmail.com <mailto:zhiwei2017@gmail.com?subject=[GitHub]Named%20Enum>`_
* `Jianlan Shao <https://github.com/Lan314>`_ - *Developer* - `jianlan.shao@gmail.com <mailto:jianlan.shao@gmail.com?subject=[GitHub]Named%20Enum>`_

**[ ~ Dependencies scanned by** `PyUp.io <https://pyup.io>`_ **~ ]**
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/zhiwei2017/named_enum",
    "name": "named-enum",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8.1,<4.0.0",
    "maintainer_email": "",
    "keywords": "Operating System :: OS Independent,License :: OSI Approved :: MIT License,Development Status :: 5 - Production/Stable,Programming Language :: Python,Programming Language :: Python :: 3,Programming Language :: Python :: 3.8,Programming Language :: Python :: 3.9,Programming Language :: Python :: 3.10,Programming Language :: Python :: 3.11,Programming Language :: Python :: 3.12,Programming Language :: Python :: Implementation,Topic :: Utilities,Natural Language :: English,Intended Audience :: Developers",
    "author": "Zhiwei Zhang",
    "author_email": "zhiwei2017@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/69/76/a2a9abb8283fc25e578eecbc8adeb5f8c052b53d6556475ad8f5d6c71ac7/named_enum-1.4.0.tar.gz",
    "platform": null,
    "description": "named-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.. actions building badge\n.. image:: https://github.com/zhiwei2017/named_enum/workflows/Unit%20Test%20&%20Build%20Test/badge.svg\n    :target: https://github.com/zhiwei2017/named_enum/actions\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.7 | Python 3.8 | Python3.9 | Python3.10 | Python3.11 | 3.12\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/zhiwei2017/named_enum/branch/master/graph/badge.svg\n    :target: https://codecov.io/gh/zhiwei2017/named_enum\n\n.. pyup badge\n.. image:: https://pyup.io/repos/github/zhiwei2017/named_enum/shield.svg\n    :target: https://pyup.io/repos/github/zhiwei2017/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.. Quality Gate Status\n.. image:: https://sonarcloud.io/api/project_badges/measure?project=KnightConan_named_enum&metric=alert_status\n    :target: https://sonarcloud.io/dashboard?id=KnightConan_named_enum\n\n\nIntroduction\n------------\n\nThis package provides several enumeration classes, which extends the default\n**Enum** class with various functionalities. For each enumeration class, its\nenumeration item's value is a customised tuple type generated by\n**namedtuple** from **collections** package.\n\nInstallation\n------------\n\nStable release\n``````````````\n\nTo install Named Enum, run this command in your terminal:\n\n.. code-block:: console\n\n    $ pip install named_enum\n\nor\n\n.. code-block:: console\n\n    $ poetry self add named_enum\n\nThis is the preferred method to install Named Enum, as it will always install the most recent stable release.\n\n\nFrom sources\n````````````\n\nThe sources for Named Enum can be downloaded from the `Github repo <https://github.com/zhiwei2017/named_enum>`_.\n\nYou can either clone the public repository:\n\n.. code-block:: console\n\n    $ git clone https://github.com/zhiwei2017/named_enum.git\n\nOnce you have a copy of the source, you can install it with:\n\n.. code-block:: console\n\n    $ pip install .\n\nor\n\n.. code-block:: console\n\n    $ poetry install\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      <BLANKLINE>\n\n      # ExtendedEnum\n      >>> TVCouple.describe()\n      Class: TVCouple\n                Name |               Value\n      ------------------------------------\n          GALLAGHERS | ('FRANK', 'MONICA')\n      MIKE_AND_MOLLY |   ('Mike', 'Molly')\n      <BLANKLINE>\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      (<AnimationFamily.SIMPSONS: NamedTuple(first='Homer', second='Bart', third='Marge')>, <AnimationFamily.DUCKS: NamedTuple(first='Huey', second='Dewey', third='Louie')>)\n\n      # ExtendedEnum\n      >>> tuple(TVCouple.gen(name_value_pair=False))\n      (<TVCouple.GALLAGHERS: ('FRANK', 'MONICA')>, <TVCouple.MIKE_AND_MOLLY: ('Mike', 'Molly')>)\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- ``<field_name>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_name>(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      (<AnimationFamily.SIMPSONS: NamedTuple(first='Homer', second='Bart', third='Marge')>,)\n\n      >>> AnimationFamily.from_second('Dewey')\n      (<AnimationFamily.DUCKS: NamedTuple(first='Huey', second='Dewey', third='Louie')>,)\n\n      >>> AnimationFamily.from_third('Marge')\n      (<AnimationFamily.SIMPSONS: NamedTuple(first='Homer', second='Bart', third='Marge')>,)\n\n      # LabeledEnum\n      >>> NBALegendary.from_key('Johnson')\n      (<NBALegendary.JOHNSON: NamedTuple(key='Johnson', label='Magic Johnson')>,)\n\n      >>> NBALegendary.from_label('Air Jordan')\n      (<NBALegendary.Jordan: NamedTuple(key='Jordan', label='Air Jordan')>,)\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_name>(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 <https://named-enum.readthedocs.io/en/latest/>`_.\n\nAcknowledgement\n---------------\n- `Cristian Alfonso Gonz\u00e1lez Mora <https://github.com/cagonza6/>`_ for the inspiration of this project.\n\nAuthor\n------\n\n* `Zhiwei Zhang <https://github.com/zhiwei2017>`_ - *Maintainer* - `zhiwei2017@gmail.com <mailto:zhiwei2017@gmail.com?subject=[GitHub]Named%20Enum>`_\n* `Jianlan Shao <https://github.com/Lan314>`_ - *Developer* - `jianlan.shao@gmail.com <mailto:jianlan.shao@gmail.com?subject=[GitHub]Named%20Enum>`_\n\n**[ ~ Dependencies scanned by** `PyUp.io <https://pyup.io>`_ **~ ]**",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Python named enumeration, which extends the built-in Enum class with extra features.",
    "version": "1.4.0",
    "project_urls": {
        "Documentation": "https://zhiwei2017.github.io/named_enum/",
        "Homepage": "https://github.com/zhiwei2017/named_enum",
        "Repository": "https://github.com/zhiwei2017/named_enum"
    },
    "split_keywords": [
        "operating system :: os independent",
        "license :: osi approved :: mit license",
        "development status :: 5 - production/stable",
        "programming language :: python",
        "programming language :: python :: 3",
        "programming language :: python :: 3.8",
        "programming language :: python :: 3.9",
        "programming language :: python :: 3.10",
        "programming language :: python :: 3.11",
        "programming language :: python :: 3.12",
        "programming language :: python :: implementation",
        "topic :: utilities",
        "natural language :: english",
        "intended audience :: developers"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "366c61d8424df1af3f12808bcbf98f8e4cb7982096e95be3cd2195e564aa3b11",
                "md5": "167600766e595ec6e48370fd1cc97107",
                "sha256": "cc28cd2d789d3167e31c1cf0ad83a7fcf0fa7912d7800eb8351179bee7d4f8b2"
            },
            "downloads": -1,
            "filename": "named_enum-1.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "167600766e595ec6e48370fd1cc97107",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8.1,<4.0.0",
            "size": 14671,
            "upload_time": "2023-10-30T10:46:20",
            "upload_time_iso_8601": "2023-10-30T10:46:20.510102Z",
            "url": "https://files.pythonhosted.org/packages/36/6c/61d8424df1af3f12808bcbf98f8e4cb7982096e95be3cd2195e564aa3b11/named_enum-1.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6976a2a9abb8283fc25e578eecbc8adeb5f8c052b53d6556475ad8f5d6c71ac7",
                "md5": "e42451bc9bd64948b776e9d0e8a5a4e0",
                "sha256": "ac7ef5afd9d83d4137c669f72975d299477cbfc7dc6d199adb8738eac702bda8"
            },
            "downloads": -1,
            "filename": "named_enum-1.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "e42451bc9bd64948b776e9d0e8a5a4e0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8.1,<4.0.0",
            "size": 15841,
            "upload_time": "2023-10-30T10:46:21",
            "upload_time_iso_8601": "2023-10-30T10:46:21.902664Z",
            "url": "https://files.pythonhosted.org/packages/69/76/a2a9abb8283fc25e578eecbc8adeb5f8c052b53d6556475ad8f5d6c71ac7/named_enum-1.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-30 10:46:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "zhiwei2017",
    "github_project": "named_enum",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "named-enum"
}
        
Elapsed time: 0.19690s