enumb
raw JSON → 0.1.5 verified Fri May 01 auth: no python
A lightweight, Pythonic enum library that provides concise enum definitions with advanced features like bitwise operations, aliases, and iteration helpers. Current version: 0.1.5. Release cadence: sporadic.
pip install enumb Common errors
error TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases ↓
cause Trying to inherit from both enumb.Enum and another class that has a different metaclass (e.g., standard library enum.Enum).
fix
Ensure all base classes use the same metaclass. Either avoid mixing Enum types or define a custom metaclass that inherits from both metaclasses.
error AttributeError: 'Color' object has no attribute '_name_' ↓
cause Using enumb's Enum but accessing attributes like _name_ which are internal to the standard library's EnumMeta. enumb uses different internal attributes.
fix
Use the public API: .name (without underscores) to get the member name.
Warnings
gotcha Do not import Enum from the standard library 'enum' when intending to use enumb. The standard library Enum has different behavior (e.g., no automatic value assignment, different member iteration). ↓
fix Use 'from enumb import Enum' explicitly.
gotcha enumb's Enum does not support inheritance from multiple Enum classes by default. Mixing enumb Enum with other classes may cause metaclass conflicts. ↓
fix If you need multiple inheritance, consider using enumb's EnumMeta carefully or use composition.
Imports
- Enum wrong
from enum import Enumcorrectfrom enumb import Enum
Quickstart
from enumb import Enum
class Color(Enum):
RED = 1
GREEN = 2
BLUE = 3
print(Color.RED)
print(Color.RED.name)
print(Color.RED.value)
# Output:
# Color.RED
# RED
# 1