Using flask-sqlalchemy, how to specify user-defined data type in database table column

Solution
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from sqlalchemy.types import TypeDecorator, CHAR

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://test:test@localhost/test?charset=utf8mb4' 
db = SQLAlchemy(app)
Migrate(app, db, compare_type=True)

class CustEnum(TypeDecorator):
    impl = CHAR(4)
    def process_bind_param(self, value, dialect):
        valid_values = ('val1', 'val2', 'val3')
        if value not in valid_values:
            raise TypeError(f"mismatch {value} not in {valid_values} ")
            
        return value

class Blobby(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    type_col = db.Column(CustEnum())
@app.cli.command("testit")
def testit():
    newblob = Blobby(type_col = 'val2')
    db.session.add( newblob )
    db.session.commit()
    
    for row in db.session.execute('select * from blobby'):
        print(row)
    
    input('press enter to continue to failure test')
    # value not allowed should fail
    newblob = Blobby(type_col = 'fail')
    db.session.add( newblob )
    db.session.commit()
sa.Column('type_col', app.CustEnum(length=4), nullable=True),
NameError: name 'app' is not defined
sqlalchemy.exc.StatementError: (builtins.TypeError) mismatch fail not in ('val1', 'val2', 'val3')
[SQL: INSERT INTO blobby (type_col) VALUES (%(type_col)s)]
[parameters: [{'type_col': 'fail'}]]