skillfed

ordered-enum

A small library for adding total orderings to enums

ordered-enum v0.0.10 152.1K downloads/30d#10,911 on PyPI31
License unclear Active released

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-enum

uv

uv add ordered-enum

poetry

poetry add ordered-enum

Installing 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

enum comparison operatorssortable enumsordered enumenum total orderingcomparable enum members
enum-utilitiesordering

More Software Development packages