def get_or_create(session, model, defaults=None, **kwargs):
    instance = session.query(model).filter_by(**kwargs).first()
if instance:
    return instance
else:
    params = dict((k, v) for k, v in kwargs.items() if not isinstance(v,
        ClauseElement))
if defaults:
    pass
SQLAlchemy ON DUPLICATE KEY UPDATE