with session.begin():
    pk = 123
bike = session.query(Bike).filter_by(bike_id=pk).first()
if not bike:
    new_bike = Bike(pk, 'shiny', 'bike')
session.add(new_bike)
Dealing with duplicate primary keys on insert in SQLAlchemy (declarative style)