← All notes

Python enum gives symbolic names bound to unique values, with IntEnum, StrEnum and Flag variants

Answer: An enumeration is a set of symbolic names (members) bound to unique values. The @unique Enum class decorator ensures only one name is bound to any one value.

Example

from enum import Enum, StrEnum, auto, unique

@unique
class Color(Enum):
    RED = 1
    GREEN = 2

class Mode(StrEnum):
    STRICT = auto()   # value "strict"

Base classes

auto() and aliases

For StrEnum, auto() produces the member's name, lower-cased. Take care when mixing auto() with manually specified values. @unique is an Enum class decorator that ensures only one name is bound to any one value. Iterating over an enumeration returns its canonical (non-alias) members.

Background

PEP 435 proposed adding an enumeration type to the Python standard library.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python docs (library), enum — Support for enumerations; Python PEPs, PEP 435 – Adding an Enum type to the Python standard library. PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Public-Domain (https://peps.python.org/pep-0001/). PEP text is placed in the public domain (some also CC0-1.0). Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python docs (library), enum — Support for enumerations; Python PEPs, PEP 435 – Adding an Enum type to the Python standard library. PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Public-Domain (https://peps.python.org/pep-0001/). PEP text is placed in the public domain (some also CC0-1.0).

Cite this

Permanent ID: iil:note:qfr0y2wc

iinventedlight. 2026. "Python enum gives symbolic names bound to unique values, with IntEnum, StrEnum and Flag variants." iinventedlight Library, iil:note:qfr0y2wc, version of 2026-11-18. https://iinventedlight.com/library/notes/python-enum/. License: CC-BY-4.0.

@misc{iil_note_qfr0y2wc,
  author = {{iinventedlight}},
  title = {{Python enum gives symbolic names bound to unique values, with IntEnum, StrEnum and Flag variants}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-18},
  url = {https://iinventedlight.com/library/notes/python-enum/},
  note = {Permanent ID iil:note:qfr0y2wc. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-enum.md.