SQLAlchemy-Enum34
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:
>>> shirt = session.query(Shirt).filter(Shirt.color == Color.navy).first() >>> shirt.color <Color.navy: 'navy'> >>> shirt.size <Size.large: 'large'>
Written by Hong Minhee at Spoqa, and distributed under MIT license.
Changelog
2.0.0
Released on April 14, 2021.
Update for SQLAlchemy 1.3+ and modern Python versions. [#6 by Joongi Kim]
1.0.1
Released on August 7, 2015.
Fixed that sqlalchemy_enum34.Enum didn’t allow nullability. [#1 by Andrés Moya]
1.0.0
First version. Released on July 30, 2015.
Release files for SQLAlchemy-Enum34 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| SQLAlchemy-Enum34-2.0.0.tar.gz | 3.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| SQLAlchemy_Enum34-2.0.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 8.0 kB
Release files / SQLAlchemy-Enum34-2.0.0.tar.gz
| Download URL | SQLAlchemy-Enum34-2.0.0.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4d7d241cfc1f7032f897a97f53670e62fa33fd2a3bdc8501dbbb46685cf006ae
|
|
BLAKE2b-256 checksum How to use checksums |
f612184e6c30c888b8a3dd031c8443542a2f3e6b724647d3dd4b0715bf7580a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/54.2.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.3
|
Release files / SQLAlchemy_Enum34-2.0.0-py2.py3-none-any.whl
| Download URL | SQLAlchemy_Enum34-2.0.0-py2.py3-none-any.whl |
|---|---|
| Size | 4.3 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
6937191cfcb47ecee0f4111046626f143445962a94935fe50989b6560e6bc5c3
|
|
BLAKE2b-256 checksum How to use checksums |
927b33f113ee53c91dbae47c112a00a1abc30e6f903f9c518b566d72ea3a463b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/54.2.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.3
|