Python 3.4 Enum Backport (enum34)

1.1.10 · maintenance · verified Thu Apr 09

`enum34` backports the `enum.Enum` class from Python 3.4 to older Python versions (2.4-3.3), enabling the use of enumerated types across diverse legacy environments. It also includes selected features from newer Python `enum` modules, such as `auto()` and `Flag` from Python 3.6. The library is currently at version 1.1.10, and due to its nature as a backport, active development has ceased, though it remains functional and stable for its intended purpose.

Warnings

Install

Imports

Quickstart

Defines a basic `Enum` using `auto()` for automatic value assignment and demonstrates accessing members by name, value, and iteration.

from enum34 import Enum, auto

class Color(Enum):
    RED = auto()
    GREEN = auto()
    BLUE = auto()

    def __str__(self):
        return self.name.lower()

print(f"First color: {Color.RED}")
print(f"Value of GREEN: {Color.GREEN.value}")
print(f"Access by value (1): {Color(1)}")
print(f"Iterating through colors:")
for color in Color:
    print(f"- {color.name}: {color.value}")

view raw JSON →