To get the values from a Python enum, iterate over the enum class and read each member's .value attribute, or build a list with a comprehension: [member.value for member in MyEnum]. If you only need the raw values as a plain list, that single line is the standard answer. The rest of this guide covers the variations you will actually hit: aliases, integer enums, string enums, and the mistakes that make the list come out wrong.

What You'll Need

  • Python 3.4 or newer (the enum module is in the standard library from 3.4 onward; no install needed).
  • A code editor or an interactive Python shell.
  • An enum class already defined, or a few lines to define one for testing.

Step-by-Step

  1. Import the enum module and define your enum. The Enum base class is what you subclass. A minimal example:
    from enum import Enum
    
    class Color(Enum):
        RED = 1
        GREEN = 2
        BLUE = 3
    The names on the left are the members; the values on the right are what you want to extract.
  2. Iterate over the enum class directly. Enum classes are iterable and yield their members in definition order:
    for color in Color:
        print(color.name, color.value)
    This prints RED 1, GREEN 2, BLUE 3. Iterating the class is the canonical way to walk members; it skips aliases automatically (see Common Mistakes).
  3. Collect just the values into a list. Use a list comprehension on the member objects:
    values = [color.value for color in Color]
    print(values)  # [1, 2, 3]
    This is the line most people are looking for. It works for any enum, including IntEnum and StrEnum.
  4. Get the names too, if you need them. The same pattern with .name gives you the string labels:
    names = [color.name for color in Color]
    print(names)  # ['RED', 'GREEN', 'BLUE']
    Pair them with zip if you want a name-to-value mapping: dict(zip(names, values)).
  5. Look up a single member by value. Call the enum class with the value: Color(2) returns Color.GREEN. If the value does not exist, Python raises ValueError, so wrap it in a try/except when the input comes from a user or a file.
  6. Handle integer and string enums. If you defined class Status(IntEnum) or class Role(StrEnum), the same iteration and comprehension work. The only difference is that each member is also an int or str, so Status.ACTIVE == 1 is true and you can pass members directly to functions that expect the primitive type.
  7. Convert to a plain list of primitives when passing to JSON or a database. A list of enum members is not JSON-serialisable; a list of their .value attributes is. Use the comprehension from step 3 before calling json.dumps.
  8. Check your result. Print the list and confirm the length matches the number of members you defined. If it is shorter, you have aliases; if it is longer, you have accidentally included a member from a mixin or a subclass.

Common Mistakes

  • Using Color.__members__ and expecting only unique values. __members__ is a mapping that includes aliases, so two names can point to the same value. Iterating the class itself (for c in Color) skips aliases; iterating Color.__members__.values() does not.
  • Calling .value on the class instead of a member. Color.value raises AttributeError because value is an instance attribute. You need Color.RED.value or a loop variable.
  • Assuming enum values are strings. By default they are whatever you assigned. If you need string values, either assign strings explicitly or use StrEnum (Python 3.11+); do not rely on str(member), which returns something like Color.RED, not RED.
  • Forgetting that duplicate values become aliases. If two names share a value, only the first is a canonical member; the second is an alias and will not appear when you iterate the class. Use @unique from the enum module to catch this at definition time.
  • Trying to mutate the enum after definition. Enum members are fixed at class creation; you cannot add or remove members at runtime. Build a new enum or use a plain dictionary if the set of values is dynamic.

Tips

  • Use list(Color) to get the member objects, then map .value only when you need primitives. Keeping members around preserves type safety.
  • For a dictionary of name to value, {c.name: c.value for c in Color} is clearer than Color.__members__ and excludes aliases.
  • If you are on Python 3.11 or newer, StrEnum makes string-valued enums behave like strings in comparisons and formatting, which avoids a lot of .value noise.
  • Name your enum class in singular form (Color, not Colors) so the plural list variable reads naturally.
  • Keep enums at module level, not inside functions, so they can be imported and compared across files.

Troubleshooting

  • You get TypeError: 'Color' object is not iterable. This happens if you iterate an instance rather than the class. Use for c in Color, not for c in Color.RED.
  • Your list is missing members. Check for duplicate values (aliases). Run Color.__members__ and compare its length with len(list(Color)); a difference means aliases exist.
  • ValueError when looking up by value. The value you passed is not defined. Confirm the exact type: Color('1') fails if the enum stores integers, because '1' is a string. Convert the input first.
  • JSON serialisation fails. You are passing enum members, not values. Convert with the comprehension from step 3 before serialising.
  • AttributeError: value. You called .value on the class or on a plain string. Confirm you are working with a member object.

Frequently Asked Questions

How do I get all values from an enum as a list?

Use [member.value for member in MyEnum]. Iterating the class yields members in definition order and skips aliases.

What is the difference between __members__ and iterating the class?

__members__ is a mapping of every name, including aliases, to its member. Iterating the class yields only canonical members, so aliases are excluded.

Can I get the value by name?

Yes: MyEnum['RED'].value looks up a member by name and returns its value. Use MyEnum.RED.value when the name is known at write time.

Do enums work with IntEnum and StrEnum?

Yes. The same iteration and .value access apply. The difference is that members also behave as int or str in comparisons and formatting.

Why does my enum have fewer members than I defined?

Duplicate values create aliases. Only the first name with a given value is a canonical member; the rest are aliases and are skipped during iteration. Use @unique to catch duplicates early.

Can I change an enum's values at runtime?

No. Enum members are fixed when the class is created. If your set of values changes at runtime, use a dictionary or build a new enum class instead.