ordered_enum
ordered_enum is a small library for adding (total) orderings to enum.Enums.
It provides two ordering behaviors:
ordered_enum.OrderedEnum: total ordering by definitionordered_enum.ValueOrderedEnum: "total" ordering by member values
Installation
ordered_enum requires Python 3.9 or newer.
pip3 install ordered_enum
Usage
To use ordered_enum, just use OrderedEnum or ValueOrderedEnum as your parent class:
from ordered_enum import OrderedEnum
class State(OrderedEnum):
Disabled = 4
Loaded = 3
Waiting = 2
Running = 1
Dead = 0
assert(State.Disabled < State.Loaded)
assert(sorted([State.Dead, State.Waiting]) == [State.Waiting, State.Dead])
OrderedEnum doesn't require @enum.unique (or unique values at all); it uses the order of
definition to impose an ordering between members.
If you'd like to impose an ordering based on member values, you can use ValueOrderedEnum instead:
import enum
from ordered_enum import ValueOrderedEnum
@enum.unique
class State(ValueOrderedEnum):
Disabled = 4
Loaded = 3
Waiting = 2
Running = 1
Dead = 0
assert(State.Disabled > State.Loaded)
assert(sorted([State.Waiting, State.Dead]) == [State.Dead, State.Waiting])
ValueOrderedEnum does require unique values, which can be enforced via @enum.unique.
Failing to make a ValueOrderedEnum's values unique will result in a silently broken ordering.
Caveats
As mentioned above, ordered_enum.OrderedEnum provides an ordering of enum values based on their order
of definition in the class. This means that:
- Enum values doesn't have to be unique for ordered_enum to work
- Enum values can be heterogeneously typed
- Moving enum values around changes their ordering
Therefore, you should either not depend on a specific ordering or ensure that your order of definition is the order you'd like.
Metadata
Release files for ordered-enum 0.0.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ordered_enum-0.0.10.tar.gz | 2.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ordered_enum-0.0.10-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.3 kB
Release files / ordered_enum-0.0.10.tar.gz
| Download URL | ordered_enum-0.0.10.tar.gz |
|---|---|
| Size | 2.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6979a367a7f252353eef4d5cd4c3c00c2178a421b52cc5f7cb2ee0d412d7f05b
|
|
BLAKE2b-256 checksum How to use checksums |
34208d165f16c2ef9d5bc945571898a0c99d3755bc401a1c57517318ba43a58f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 23, 2025.
Transparency logRelease files / ordered_enum-0.0.10-py3-none-any.whl
| Download URL | ordered_enum-0.0.10-py3-none-any.whl |
|---|---|
| Size | 3.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f398723003f43bc19ef0e308f687149814a9889e7b81dd1947c556daa94d547e
|
|
BLAKE2b-256 checksum How to use checksums |
6c3155f391e6039353ccb97072ab990f21bde06676d1df295310cca51141d510
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 23, 2025.
Transparency log