Skip to main content

Enum library for python.

Project description

richenum

Build Status Latest PyPI Version Python versions Pypi Downloads

About

A enum library for Python.

enum

A simple enum implementation that maps a “variable” to a constant.

RichEnum

An enum implementation that offers more functionality than a basic enum, hence the name: RichEnum. Provided functionality include specifying a canonical name and a display name. The canonical name should be used if you need to do a lookup or reference in your code. The display name should be used if you need to display text to a user.

OrderedRichEnum

Exactly like RichEnum but also has an index specified for each enum value. Also, iteration over an OrderedRichEnum will be sorted (ascending) by the enum value’s index.

Installation

$ pip install richenum

Example Usage

enum

>>> from richenum import enum
>>> MY_ENUM = enum(FOO=1, BAR=2)
>>> MY_ENUM.FOO
1
>>> MY_ENUM.BAR
2

RichEnum

>>> from richenum import RichEnum, RichEnumValue
>>> class MyRichEnum(RichEnum):
...    FOO = RichEnumValue(canonical_name="foo", display_name="Foo")
...    BAR = RichEnumValue(canonical_name="bar", display_name="Bar")
...
>>> MyRichEnum.FOO
RichEnumValue - canonical_name: 'foo'  display_name: 'Foo'
>>> MyRichEnum.from_canonical("foo")
RichEnumValue - canonical_name: 'foo'  display_name: 'Foo'

OrderedRichEnum

>>> from richenum import OrderedRichEnum, OrderedRichEnumValue
>>> class MyOrderedRichEnum(OrderedRichEnum):
...    FOO = OrderedRichEnumValue(index=1, canonical_name="foo", display_name="Foo")
...    BAR = OrderedRichEnumValue(index=2, canonical_name="bar", display_name="Bar")
...
>>> MyOrderedRichEnum.FOO
OrderedRichEnumValue - idx: 1  canonical_name: 'foo'  display_name: 'Foo'
>>> MyOrderedRichEnum.from_canonical("foo")
OrderedRichEnumValue - idx: 1  canonical_name: 'foo'  display_name: 'Foo'
>>> MyOrderedRichEnum.from_index(1)
OrderedRichEnumValue - idx: 1  canonical_name: 'foo'  display_name: 'Foo'

Contributing

  1. Fork the repo from GitHub.

  2. Make your changes.

  3. Add unittests for your changes.

  4. Run pep8, pyflakes, and pylint to make sure your changes follow the Python style guide and doesn’t have any errors.

  5. Add yourself to the AUTHORS file (in alphabetical order).

  6. Send a pull request from your fork to the main repo.

Changelog

2.0.2 (2024-10-01)

  • Remove unavailable link for blog post from README.rst

2.0.1 (2024-06-06)

  • Fix README.rst

2.0.0 (2024-06-04)

  • Remove six

  • Remove python 3.7 support

  • Add python 3.9 and 3.10 support

  • Remove tox.ini

1.2.1 (2016-09-16)

  • EnumLookupError class now inherits from built-in LookupError.

1.2.0 (2016-04-15)

  • added simple LookupError members that are thrown when RichEnum.lookup is called for a nonexistent attr/val pair. Users can choose to catch either the specific LookupError or continue to catch EnumLookupError.

1.1.0 (2014-04-17)

  • support for Python 3 and PyPy

1.0.4 (2013-12-03)

  • Better unicode handling in __str__, __unicode__, and __repr__ magic methods.

1.0.3 (2013-12-03)

  • Stop throwing warnings.

1.0.2 (2013-11-05)

  • Suppress warnings from mismatched type comparisons when generated in RichEnum.lookup.

1.0.1 (2013-09-20)

  • Raise warnings when comparing enum values to other types, but not when checking membership or comparing to None.

1.0.0 (2013-08-16)

  • Initial public release.

Developed and maintained by Hearsay Social, Inc..

Contributors

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

richenum-2.0.2.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

richenum-2.0.2-py2.py3-none-any.whl (8.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file richenum-2.0.2.tar.gz.

File metadata

  • Download URL: richenum-2.0.2.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.18

File hashes

Hashes for richenum-2.0.2.tar.gz
Algorithm Hash digest
SHA256 286b83be8779b6eac6c3586d904241321eb2f7b9b5c98a1e91bf42e8b3a28b85
MD5 7de8751ada0a04ff68f7b4dc902833ce
BLAKE2b-256 4e6c89e7e2afd05754dd2ed695a4da97ab033e642d17e04449623f74de07ab24

See more details on using hashes here.

File details

Details for the file richenum-2.0.2-py2.py3-none-any.whl.

File metadata

  • Download URL: richenum-2.0.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.18

File hashes

Hashes for richenum-2.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 60802c5d35713dc6bb767c62bb27bc4df09ac094c5b812e2cf9955041156eccf
MD5 50ebc76bc8e7d6286b3dee7bc30f7ff3
BLAKE2b-256 f355b50e4b2b673476135cc2098edc37c36cc40eb7a2858de0a97a159571da2a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page