Python
Enum
Programming
Python Tips
Code Examples

Python enum: get a list of all values

Codemia Knowledge Hub ·

To get all values from a Python Enum, iterate over its members and take .value. The result keeps declaration order and works for validation, serialization, dropdown options and anything else that needs the underlying values rather than the enum objects.

List all values

python
1from enum import Enum
2
3class Status(Enum):
4    PENDING = "pending"
5    RUNNING = "running"
6    DONE = "done"
7
8values = [member.value for member in Status]
9print(values)

Names vs values

Each member has a .name and a .value:

python
1names = [member.name for member in Status]
2values = [member.value for member in Status]
3
4print(names)
5print(values)

Use .name for the symbolic identifiers and .value for the stored values. Mixing the two up often leaks into API design, where one part of the system expects names and another expects values.

Getting the members themselves

If later code needs both sides, keep the members instead of converting to values too early:

python
members = list(Status)
print(members)

Name-to-member mapping with __members__

__members__ is an ordered mapping of names to members:

python
1member_map = Status.__members__
2print(member_map)
3print(list(member_map.keys()))
4print([member.value for member in member_map.values()])

It is useful when you need the names and the enum objects in one place.

Names and values together for an API

For UI or schema generation, a list of dictionaries saves downstream code from joining names and values later, and is easy to serialize or send to frontend code:

python
items = [{"name": m.name, "value": m.value} for m in Status]
print(items)

Iteration follows declaration order

Enum iteration preserves the order in which members were defined, so the enum definition can also serve as the source of display or validation order for the rest of the application.

Duplicate values and aliases

If several names share a value, the extra names are aliases:

python
1from enum import Enum
2
3class Example(Enum):
4    A = 1
5    B = 1
6    C = 2

Default iteration over Example skips aliases, so "all values" depends on whether alias members should count. If they matter, inspect __members__ instead.

Mistakes when extracting enum values

  • Confusing names with values. Decide up front whether the consumer needs .name, .value or the member itself.
  • Expecting aliases in the iteration. When duplicate values exist, iterating the enum does not return every alias.
  • Converting to values too early. If later code needs the members (for type checks or to read .name), pass list(MyEnum) and extract values at the last moment.

Quick reference:

  • [member.value for member in MyEnum] gives all values.
  • [member.name for member in MyEnum] gives the symbolic names.
  • list(MyEnum) gives the members.
  • MyEnum.__members__ gives the ordered name-to-member mapping, including aliases.

Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No course covers this one yet

Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.

Build my course
Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms