You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This package provides a SQLAlchemy type to store values of standard
enum.Enum (which became a part of standard library since Python 3.4).
Its internal representation is equivalent to SQLAlchemy's built-in
sqlalchemy.types.Enum, but its Python representation is not
a str but enum.Enum.
Note that this works on Python 2.6 as well as 3.4, the latest version of
Python, through enum34 package.
The following example shows how enum-typed columns can be declared:
import enum
from sqlalchemy import Column, Integer
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy_enum34 import EnumType
Base = declarative_base()
class Color(enum.Enum):
black = 'black'
white = 'white'
navy = 'navy'
red = 'red'
class Size(enum.Enum):
small = 'S'
medium = 'M'
large = 'L'
xlarge = 'XL'
class Shirt(Base):
id = Column(Integer, primary_key=True)
color = Column(EnumType(Color), nullable=False)
size = Column(EnumType(Size, name='shirt_size'), nullable=False)
And the following REPL session shows how these columns work: