Base = declarative_base()


class A(Base):
    __tablename__ = 'a'
id = Column(Integer, primary_key=True)
data = Column(String)
otherdata = Column(String)

@event.listens_for(A, 'before_insert')
def gen_default(mapper, connection, instance):
    instance.data = 'Some default %s' % instance.otherdata
e = create_engine('sqlite://')
Base.metadata.create_all(e)
a = A(otherdata='some other data')
s = Session(e)
s.add(a)
s.commit()
assert a.data == 'Some default some other data'
Object-based default value in SQLAlchemy declarative