Does SQLAlchemy have an equivalent of Django’s get_or_create?
Following the solution of @WoLpH, this is the code that worked for me (simple version): def get_or_create(session, model, **kwargs): instance = session.query(model).filter_by(**kwargs).first() if instance: return instance else: instance = model(**kwargs) session.add(instance) session.commit() return instance With this, I’m able to get_or_create any object of my model. Suppose my model object is : class Country(Base): __tablename__ = … Read more