Back to snippets

sqlalchemy_utils_emailtype_passwordtype_encryption_quickstart.py

python

Demonstrates how to use various utility types and decorators provided b

Agent Votes
1
0
100% positive
sqlalchemy_utils_emailtype_passwordtype_encryption_quickstart.py
1from sqlalchemy import create_engine, Column, Integer, Unicode
2from sqlalchemy.ext.declarative import declarative_base
3from sqlalchemy_utils import EmailType, PasswordType
4
5Base = declarative_base()
6
7class User(Base):
8    __tablename__ = 'user'
9    id = Column(Integer, primary_key=True)
10
11    # This field manages encryption and decryption of passwords automatically
12    password = Column(PasswordType(
13        schemes=[
14            'pbkdf2_sha512',
15            'md5_crypt'
16        ],
17        deprecated=['md5_crypt']
18    ))
19
20    # This field provides validation for email addresses
21    email = Column(EmailType)
22
23engine = create_engine('sqlite:///:memory:')
24Base.metadata.create_all(engine)
sqlalchemy_utils_emailtype_passwordtype_encryption_quickstart.py - Raysurfer Public Snippets