enum-properties


Nameenum-properties JSON
Version 1.7.0 PyPI version JSON
download
home_pagehttps://enum-properties.readthedocs.io
SummaryAdd properties and method specializations to Python enumeration values with a simple declarative syntax.
upload_time2023-10-02 19:14:46
maintainer
docs_urlNone
authorBrian Kohan
requires_python>=3.7,<4.0
licenseMIT
keywords enum properties defines field
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            |MIT license| |PyPI version fury.io| |PyPI pyversions| |PyPI status| |Documentation Status|
|Code Cov| |Test Status|

.. |MIT license| image:: https://img.shields.io/badge/License-MIT-blue.svg
   :target: https://lbesson.mit-license.org/

.. |PyPI version fury.io| image:: https://badge.fury.io/py/enum-properties.svg
   :target: https://pypi.python.org/pypi/enum-properties/

.. |PyPI pyversions| image:: https://img.shields.io/pypi/pyversions/enum-properties.svg
   :target: https://pypi.python.org/pypi/enum-properties/

.. |PyPI status| image:: https://img.shields.io/pypi/status/enum-properties.svg
   :target: https://pypi.python.org/pypi/enum-properties

.. |Documentation Status| image:: https://readthedocs.org/projects/enum-properties/badge/?version=latest
   :target: http://enum-properties.readthedocs.io/?badge=latest/

.. |Code Cov| image:: https://codecov.io/gh/bckohan/enum-properties/branch/main/graph/badge.svg?token=0IZOKN2DYL
   :target: https://codecov.io/gh/bckohan/enum-properties

.. |Test Status| image:: https://github.com/bckohan/enum-properties/workflows/test/badge.svg
   :target: https://github.com/bckohan/enum-properties/actions

Enum Properties
#######################

Add properties to Python enumeration values with a simple declarative syntax.
`Enum Properties <https://enum-properties.readthedocs.io/en/latest/>`_ is a
lightweight extension to
`Python's Enum class <https://docs.python.org/3/library/enum.html>`_. Example:

.. code:: python

    from enum_properties import EnumProperties, p
    from enum import auto

    class Color(EnumProperties, p('rgb'), p('hex')):

        # name   value      rgb       hex
        RED    = auto(), (1, 0, 0), 'ff0000'
        GREEN  = auto(), (0, 1, 0), '00ff00'
        BLUE   = auto(), (0, 0, 1), '0000ff'

    # the named p() values in the Enum's inheritance become properties on
    # each value, matching the order in which they are specified

    Color.RED.rgb   == (1, 0, 0)
    Color.GREEN.rgb == (0, 1, 0)
    Color.BLUE.rgb  == (0, 0, 1)

    Color.RED.hex   == 'ff0000'
    Color.GREEN.hex == '00ff00'
    Color.BLUE.hex  == '0000ff'

Properties may also be symmetrically mapped to enumeration values, using
s() values:

.. code:: python

    from enum_properties import EnumProperties, s
    from enum import auto

    class Color(EnumProperties, s('rgb'), s('hex', case_fold=True)):

        RED    = auto(), (1, 0, 0), 'ff0000'
        GREEN  = auto(), (0, 1, 0), '00ff00'
        BLUE   = auto(), (0, 0, 1), '0000ff'

    # any named s() values in the Enum's inheritance become properties on
    # each value, and the enumeration value may be instantiated from the
    # property's value

    Color((1, 0, 0)) == Color.RED
    Color((0, 1, 0)) == Color.GREEN
    Color((0, 0, 1)) == Color.BLUE

    Color('ff0000') == Color.RED
    Color('FF0000') == Color.RED  # case_fold makes mapping case insensitive
    Color('00ff00') == Color.GREEN
    Color('00FF00') == Color.GREEN
    Color('0000ff') == Color.BLUE
    Color('0000FF') == Color.BLUE

    Color.RED.hex == 'ff0000'


Member functions may also be specialized to each enumeration value, using the
@specialize decorator.

.. code:: python

    from enum_properties import EnumProperties, specialize

    class SpecializedEnum(EnumProperties):

        ONE   = 1
        TWO   = 2
        THREE = 3

        @specialize(ONE)
        def method(self):
            return 'method_one()'

        @specialize(TWO)
        def method(self):
            return 'method_two()'

        @specialize(THREE)
        def method(self):
            return 'method_three()'

    SpecializedEnum.ONE.method() == 'method_one()'
    SpecializedEnum.TWO.method() == 'method_two()'
    SpecializedEnum.THREE.method() == 'method_three()'

Please report bugs and discuss features on the
`issues page <https://github.com/bckohan/enum-properties/issues>`_.

`Contributions <https://github.com/bckohan/enum-properties/blob/main/CONTRIBUTING.rst>`_ are
encouraged!

`Full documentation at read the docs. <https://enum-properties.readthedocs.io/en/latest/>`_

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

1. Clone enum-properties from GitHub_ or install a release off PyPI_ :

.. code:: bash

       pip install enum-properties


.. _GitHub: http://github.com/bckohan/enum-properties
.. _PyPI: http://pypi.python.org/pypi/enum-properties

            

Raw data

            {
    "_id": null,
    "home_page": "https://enum-properties.readthedocs.io",
    "name": "enum-properties",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7,<4.0",
    "maintainer_email": "",
    "keywords": "enum,properties,defines,field",
    "author": "Brian Kohan",
    "author_email": "bckohan@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/12/70/2c11f13e00ceb1a421ce217b455727398552dc25a154f5bd16aac1beb379/enum_properties-1.7.0.tar.gz",
    "platform": null,
    "description": "|MIT license| |PyPI version fury.io| |PyPI pyversions| |PyPI status| |Documentation Status|\n|Code Cov| |Test Status|\n\n.. |MIT license| image:: https://img.shields.io/badge/License-MIT-blue.svg\n   :target: https://lbesson.mit-license.org/\n\n.. |PyPI version fury.io| image:: https://badge.fury.io/py/enum-properties.svg\n   :target: https://pypi.python.org/pypi/enum-properties/\n\n.. |PyPI pyversions| image:: https://img.shields.io/pypi/pyversions/enum-properties.svg\n   :target: https://pypi.python.org/pypi/enum-properties/\n\n.. |PyPI status| image:: https://img.shields.io/pypi/status/enum-properties.svg\n   :target: https://pypi.python.org/pypi/enum-properties\n\n.. |Documentation Status| image:: https://readthedocs.org/projects/enum-properties/badge/?version=latest\n   :target: http://enum-properties.readthedocs.io/?badge=latest/\n\n.. |Code Cov| image:: https://codecov.io/gh/bckohan/enum-properties/branch/main/graph/badge.svg?token=0IZOKN2DYL\n   :target: https://codecov.io/gh/bckohan/enum-properties\n\n.. |Test Status| image:: https://github.com/bckohan/enum-properties/workflows/test/badge.svg\n   :target: https://github.com/bckohan/enum-properties/actions\n\nEnum Properties\n#######################\n\nAdd properties to Python enumeration values with a simple declarative syntax.\n`Enum Properties <https://enum-properties.readthedocs.io/en/latest/>`_ is a\nlightweight extension to\n`Python's Enum class <https://docs.python.org/3/library/enum.html>`_. Example:\n\n.. code:: python\n\n    from enum_properties import EnumProperties, p\n    from enum import auto\n\n    class Color(EnumProperties, p('rgb'), p('hex')):\n\n        # name   value      rgb       hex\n        RED    = auto(), (1, 0, 0), 'ff0000'\n        GREEN  = auto(), (0, 1, 0), '00ff00'\n        BLUE   = auto(), (0, 0, 1), '0000ff'\n\n    # the named p() values in the Enum's inheritance become properties on\n    # each value, matching the order in which they are specified\n\n    Color.RED.rgb   == (1, 0, 0)\n    Color.GREEN.rgb == (0, 1, 0)\n    Color.BLUE.rgb  == (0, 0, 1)\n\n    Color.RED.hex   == 'ff0000'\n    Color.GREEN.hex == '00ff00'\n    Color.BLUE.hex  == '0000ff'\n\nProperties may also be symmetrically mapped to enumeration values, using\ns() values:\n\n.. code:: python\n\n    from enum_properties import EnumProperties, s\n    from enum import auto\n\n    class Color(EnumProperties, s('rgb'), s('hex', case_fold=True)):\n\n        RED    = auto(), (1, 0, 0), 'ff0000'\n        GREEN  = auto(), (0, 1, 0), '00ff00'\n        BLUE   = auto(), (0, 0, 1), '0000ff'\n\n    # any named s() values in the Enum's inheritance become properties on\n    # each value, and the enumeration value may be instantiated from the\n    # property's value\n\n    Color((1, 0, 0)) == Color.RED\n    Color((0, 1, 0)) == Color.GREEN\n    Color((0, 0, 1)) == Color.BLUE\n\n    Color('ff0000') == Color.RED\n    Color('FF0000') == Color.RED  # case_fold makes mapping case insensitive\n    Color('00ff00') == Color.GREEN\n    Color('00FF00') == Color.GREEN\n    Color('0000ff') == Color.BLUE\n    Color('0000FF') == Color.BLUE\n\n    Color.RED.hex == 'ff0000'\n\n\nMember functions may also be specialized to each enumeration value, using the\n@specialize decorator.\n\n.. code:: python\n\n    from enum_properties import EnumProperties, specialize\n\n    class SpecializedEnum(EnumProperties):\n\n        ONE   = 1\n        TWO   = 2\n        THREE = 3\n\n        @specialize(ONE)\n        def method(self):\n            return 'method_one()'\n\n        @specialize(TWO)\n        def method(self):\n            return 'method_two()'\n\n        @specialize(THREE)\n        def method(self):\n            return 'method_three()'\n\n    SpecializedEnum.ONE.method() == 'method_one()'\n    SpecializedEnum.TWO.method() == 'method_two()'\n    SpecializedEnum.THREE.method() == 'method_three()'\n\nPlease report bugs and discuss features on the\n`issues page <https://github.com/bckohan/enum-properties/issues>`_.\n\n`Contributions <https://github.com/bckohan/enum-properties/blob/main/CONTRIBUTING.rst>`_ are\nencouraged!\n\n`Full documentation at read the docs. <https://enum-properties.readthedocs.io/en/latest/>`_\n\nInstallation\n------------\n\n1. Clone enum-properties from GitHub_ or install a release off PyPI_ :\n\n.. code:: bash\n\n       pip install enum-properties\n\n\n.. _GitHub: http://github.com/bckohan/enum-properties\n.. _PyPI: http://pypi.python.org/pypi/enum-properties\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Add properties and method specializations to Python enumeration values with a simple declarative syntax.",
    "version": "1.7.0",
    "project_urls": {
        "Homepage": "https://enum-properties.readthedocs.io",
        "Repository": "https://github.com/bckohan/enum-properties"
    },
    "split_keywords": [
        "enum",
        "properties",
        "defines",
        "field"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e3ed85781f75a0b1a8b2743743da391941d1075fb68bb956e36600e7431a6f3c",
                "md5": "3d9304b6fb9387d010158915f9c11f64",
                "sha256": "b4d6e3261e56a2bff5b43f0abb2e34757443382ac06b11757d37da1c50f138f7"
            },
            "downloads": -1,
            "filename": "enum_properties-1.7.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3d9304b6fb9387d010158915f9c11f64",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7,<4.0",
            "size": 9691,
            "upload_time": "2023-10-02T19:14:44",
            "upload_time_iso_8601": "2023-10-02T19:14:44.847054Z",
            "url": "https://files.pythonhosted.org/packages/e3/ed/85781f75a0b1a8b2743743da391941d1075fb68bb956e36600e7431a6f3c/enum_properties-1.7.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "12702c11f13e00ceb1a421ce217b455727398552dc25a154f5bd16aac1beb379",
                "md5": "70554d2278242b74c52b47aa4045cced",
                "sha256": "776010db64bfd080f506b24d5c878fc158a346e4a59e31015c2a4dd7b5658bb0"
            },
            "downloads": -1,
            "filename": "enum_properties-1.7.0.tar.gz",
            "has_sig": false,
            "md5_digest": "70554d2278242b74c52b47aa4045cced",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7,<4.0",
            "size": 10471,
            "upload_time": "2023-10-02T19:14:46",
            "upload_time_iso_8601": "2023-10-02T19:14:46.476090Z",
            "url": "https://files.pythonhosted.org/packages/12/70/2c11f13e00ceb1a421ce217b455727398552dc25a154f5bd16aac1beb379/enum_properties-1.7.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-02 19:14:46",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "bckohan",
    "github_project": "enum-properties",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "enum-properties"
}
        
Elapsed time: 0.11681s