Enum library for python.
Project description
richenum
About
An 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, including a canonical name and a display name.OrderedRichEnum: LikeRichEnum, but each enum value also has an index and iteration is sorted by index.
Links
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'
Related Packages
django-richenum: MakesRichEnumandOrderedRichEnumavailable as model and form fields in Django. GitHub, PyPIenum: Starting with Python 3.4, there is a standard library for enumerations. This package has a similar API but is not directly compatible.
Contributing
- Fork the repo from GitHub.
- Make your changes.
- Add unittests for your changes.
- Run pep8, pyflakes, and pylint to make sure your changes follow the Python style guide and do not have any errors.
- Add yourself to the AUTHORS file (in alphabetical order).
- Send a pull request from your fork to the main repo.
Changelog
2.1.0 (2026-16-03)
- Add Python 3.14 support and migrate to Poetry
2.0.2 (2024-10-01)
- Remove unavailable link for blog post from
README.md.
2.0.1 (2024-06-06)
- Fix
README.md.
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)
EnumLookupErrornow inherits from built-inLookupError.
1.2.0 (2016-04-15)
- Add simple
LookupErrormembers that are thrown whenRichEnum.lookupis called for a nonexistent attr/val pair. - Users can choose to catch either the specific
LookupErroror continue to catchEnumLookupError.
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__.
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file richenum-2.1.0.tar.gz.
File metadata
- Download URL: richenum-2.1.0.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78cd3e69c05ad269fc1c87a971a85d4d026f787facaeb738656b5cddc7e39e9e
|
|
| MD5 |
ca0527de5d7441fd857de7012a5e64fe
|
|
| BLAKE2b-256 |
fa43446c6b18b481a68a2b02d606ed1fb99afb85cfae53721eeb6814c376c0f7
|
Provenance
The following attestation bundles were made for richenum-2.1.0.tar.gz:
Publisher:
publish.yml on hearsaycorp/richenum
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
richenum-2.1.0.tar.gz -
Subject digest:
78cd3e69c05ad269fc1c87a971a85d4d026f787facaeb738656b5cddc7e39e9e - Sigstore transparency entry: 1110827348
- Sigstore integration time:
-
Permalink:
hearsaycorp/richenum@744979600db7d4691678950ed6ac8ff794f6cc25 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/hearsaycorp
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@744979600db7d4691678950ed6ac8ff794f6cc25 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file richenum-2.1.0-py3-none-any.whl.
File metadata
- Download URL: richenum-2.1.0-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60ab6bcd58d989007976b461ab94cc555d440e7158bd45ceb1a6c31e990f8000
|
|
| MD5 |
4c12083405555b5f89e4805e73416006
|
|
| BLAKE2b-256 |
6cb04e242507a6415d05b831fc08333a63eda3ea7f6756ba4b8bda0c38e6f1a7
|
Provenance
The following attestation bundles were made for richenum-2.1.0-py3-none-any.whl:
Publisher:
publish.yml on hearsaycorp/richenum
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
richenum-2.1.0-py3-none-any.whl -
Subject digest:
60ab6bcd58d989007976b461ab94cc555d440e7158bd45ceb1a6c31e990f8000 - Sigstore transparency entry: 1110827352
- Sigstore integration time:
-
Permalink:
hearsaycorp/richenum@744979600db7d4691678950ed6ac8ff794f6cc25 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/hearsaycorp
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@744979600db7d4691678950ed6ac8ff794f6cc25 -
Trigger Event:
workflow_dispatch
-
Statement type: