Skip to content

ClassEnumDeclaration

Create a Python enum using the class-based syntax.

This generates enums using the class Name(Enum): syntax with member definitions inside the class body. Supports various member value styles including auto-generated values, explicit values, and custom base types.

import { ClassEnumDeclaration } from "@alloy-js/python";
<ClassEnumDeclaration
baseType={"Enum" | "IntEnum" | "StrEnum" | "Flag" | "IntFlag"}
doc={Children}
doc={Children}
members={Array<{
name: string;
value?: Children;
jsValue?: string | number;
doc?: string;
}>}
name="string"
refkey={Refkey | Refkey[]}
style={"classic" | "auto" | "functional"}
/>
baseTypeoptional”Enum” | “IntEnum” | “StrEnum” | “Flag” | “IntFlag”

The base type of the enum. One of: ‘Enum’, ‘IntEnum’, ‘StrEnum’, ‘Flag’, ‘IntFlag’. Defaults to ‘Enum’.

childrenoptionalChildren
docoptionalChildren

Optional docstring for the enum.

docoptionalChildren

Documentation for this declaration

membersoptionalArray<{ name: string; value?: Children; jsValue?: string | number; doc?: string; }>

Members of the enum as an array of objects.

namestring

The base name of this declaration. May change depending on naming policy and any conflicts.

refkeyoptionalRefkey | Refkey[]

The refkey or array of refkeys for this declaration.

styleoptional”classic” | “auto” | “functional”

The enum style: ‘classic’ (default), ‘auto’, or ‘functional’.

<ClassEnumDeclaration
name="Direction"
members={[
{ name: "NORTH" },
{ name: "SOUTH" },
{ name: "EAST" },
{ name: "WEST" }
]}
/>

renders to:

class Direction(Enum):
NORTH = "NORTH"
SOUTH = "SOUTH"
EAST = "EAST"
WEST = "WEST"

With explicit values:

<ClassEnumDeclaration
name="Status"
members={[
{ name: "PENDING", value: 1 },
{ name: "ACTIVE", value: 2 },
{ name: "INACTIVE", value: 3 }
]}
/>

renders to:

class Status(Enum):
PENDING = 1
ACTIVE = 2
INACTIVE = 3

With auto() values:

<ClassEnumDeclaration
name="Color"
style="auto"
members={[
{ name: "RED" },
{ name: "GREEN" },
{ name: "BLUE" }
]}
/>

renders to:

class Color(Enum):
RED = auto()
GREEN = auto()
BLUE = auto()