Skip to content

Enum Types

PyGo provides native support for enumerated types (enum) with compile-time validation. Enums are defined in the .pgo DSL and are mechanically transpiled to idiomatic Go and Python code.

enum Status:
active
inactive
pending
enum Role:
admin=1
author=2
reader=3
type Status string
const (
StatusActive Status = "active"
StatusInactive Status = "inactive"
StatusPending Status = "pending"
)
type Role int
const (
RoleAdmin Role = 1
RoleAuthor Role = 2
RoleReader Role = 3
)
import enum
class Status(str, enum.Enum):
ACTIVE = "active"
INACTIVE = "inactive"
PENDING = "pending"
class Role(int, enum.Enum):
ADMIN = 1
AUTHOR = 2
READER = 3
enum Status:
active
inactive
model User:
id: UUID
name: String
status: Status
role: Role

Enums are validated at compile time:

model Post:
title: String
status: Status
# Valid
post = Post(title="Hello", status=Status.published)
# Invalid — compile-time error (not a valid Status value)
# post = Post(title="Hello", status="published")

By default, PyGo stores enums as their string value in the database:

CREATE TABLE user (
id UUID PRIMARY KEY,
name TEXT NOT NULL,
status TEXT NOT NULL, -- stores "active", "inactive", "pending"
role INTEGER -- stores 1, 2, 3 (for numeric enums)
);
  • Use string-backed enums for human-readable values
  • Use numeric enums for storage efficiency when values don’t need to be human-readable
  • Always use the enum constant, never raw strings