ordered-enum
A small library for adding total orderings to enums
What it is and what it does
ordered_enum is a minimal library that makes Python enum members comparable and sortable by implementing total ordering. It provides two base classes: OrderedEnum, which orders members by their definition sequence in the class body, and ValueOrderedEnum, which orders members by their assigned values. The library requires Python 3.9 or newer and has no external dependencies, making it a lightweight addition to projects that need to sort or compare enum states.
The typical use case is state machines or priority systems where you want to compare enum members directly (e.g., State.Running < State.Waiting) or sort collections of them. OrderedEnum is more flexible since it doesn't require unique values; ValueOrderedEnum enforces uniqueness but orders by the numeric or comparable value you assign to each member.
Use it for:
- Implement state machines where you need to check if one state is 'before' or 'after' another in a defined sequence.
- Sort priority or severity enums (e.g., log levels) by their numeric values without manual conversion.
- Build workflow systems that compare enum states to determine valid transitions or precedence.
- Create ordered status enums for database records or API responses that need to be ranked or filtered.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Adds comparison operators to Python enums so they can be sorted and compared using standard ordering syntax, with two strategies: ordering by definition sequence or by member values.
Yes, if you need enum comparison. The package is lightweight, actively maintained, has no dependencies, and solves a real gap in Python's standard enum module. The only caveat is the unclear license status—verify that it's compatible with your project's requirements before committing to it.
Install
ordered-enum on PyPI
pip
pip install ordered-enumuv
uv add ordered-enumpoetry
poetry add ordered-enumInstalling ordered-enum
Before you install
Low friction: pure Python wheel with no runtime dependencies. Actively maintained with a recent release (417 days ago) and a live repository.
Quickstart
from ordered_enum import OrderedEnum
class State(OrderedEnum):
Disabled = 4
Loaded = 3
Waiting = 2
Running = 1
Dead = 0
print(State.Disabled > State.Loaded) # True
print(sorted([State.Dead, State.Waiting])) # [State.Waiting, State.Dead]
Requires Python 3.9 or newer.
Verify before relying
- Whether the package is suitable for production use given the unclear license status and lack of explicit license declaration.
Package facts
| License | not declared (unclear) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 417 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 152,094/month — #10,911 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: ordered_enum-0.0.10-py3-none-any.whl
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
orderingsProvides an Ordering enumeration and Compare…
permissive · top 15,000 on PyPI
matrix-enumExtends Python's built-in Enum to support…
permissive · top 15,000 on PyPI
aenumaenum provides advanced enumeration types…
permissive · top 1,000 on PyPI
enum-toolsProvides utilities to enhance Python's enum…
copyleft · top 5,000 on PyPI
infinityProvides an Infinity class that can be compared…
permissive · top 15,000 on PyPI
django-choices-fieldProvides Django model fields that store and…
permissive · top 15,000 on PyPI
django-enumProvides a Django model field type that stores…
permissive · top 15,000 on PyPI
StrEnumStrEnum is a string-based enum class that…
permissive · top 1,000 on PyPI
django-enumfieldsProvides Django model fields that store Python…
permissive · top 15,000 on PyPI
enum34Provides enumeration support for older Python…
permissive · top 5,000 on PyPI