Python
Enum
Programming
Python Tips
Code Examples

How to get all values from python enum class?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

If you want all values from a Python Enum, the usual pattern is to iterate over the enum members and extract .value. This preserves declaration order and works cleanly for validation, serialization, dropdown options, and other code that needs the enum’s underlying payloads rather than the enum objects themselves.

The standard pattern

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)

This is the normal answer and is usually all you need.

Names versus values

Each enum member has both 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 when you want the symbolic identifiers. Use .value when you want the actual underlying values stored in the enum.

Getting the members themselves

Sometimes you do not want raw values yet. You want the enum members so later code can inspect either side.

python
members = list(Status)
print(members)

That is useful when you want both .name and .value or want to pass members around as typed enum values.

Using __members__

Enums also expose an ordered mapping of names to members through __members__.

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

This is especially useful when you need both the names and the underlying enum objects in one place.

A common API-friendly structure

For UI or schema generation, a list of dictionaries is often convenient.

That lets downstream code treat the enum as structured metadata instead of having to separately join names and values later in the pipeline.

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

That structure is often easier to serialize or send to frontend code than raw enum members.

Why iteration order matters

Python enum iteration preserves declaration order. That means the values list follows the order in which members were defined in the class.

That is helpful when the enum definition is also intended to define display order or validation order in the rest of the application.

For many applications, that is useful because the enum definition itself becomes the source of ordering truth.

Special note on duplicate values

Python enums can have aliases if multiple names share the same value.

That means “all values” can be ambiguous unless you decide whether alias members should count separately or whether you only care about the unique iteration result.

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

Iterating over Example skips aliases in the default iteration behavior, so this can affect what “all values” means in your code. If aliases matter, inspect __members__ more carefully.

Common Pitfalls

A common mistake is confusing enum names with enum values.

That confusion often leaks into API design, where one part of the system expects symbolic names while another expects the stored payload values.

Another mistake is expecting iteration to include every alias when duplicate values exist.

A third mistake is converting to values too early when later code actually needs enum members themselves.

Summary

  • Use [member.value for member in MyEnum] to get all enum values.
  • Use .name when you need symbolic identifiers instead.
  • Use list(MyEnum) when you want the enum members themselves.
  • Use __members__ when you need the ordered name-to-member mapping.
  • Be aware that enum aliases can affect iteration behavior.
  • Decide whether you want values, names, or members before converting.
  • Use iteration for the simplest and most idiomatic enum value extraction.

Course illustration
Course illustration

All Rights Reserved.