title: Does SQLAlchemy have an equivalent of Django's get_or_create?
body: <p>I want to get an object from the database if it already exists (based on provided parameters) or create it if it does not.</p>
  
  <p>Django's <a href="https://docs.djangoproject.com/en/1.10/ref/models/querysets/#get-or-create" rel="noreferrer"><code>get_or_create</code></a> (or <a href="https://github.com/django/django/blob/master/django/db/models/query.py#L462" rel="noreferrer">source</a>) does this.  Is there an equivalent shortcut in SQLAlchemy?</p>
  
  <p>I'm currently writing it out explicitly like this:</p>
  
  <pre><code>def get_or_create_instrument(session, serial_number):
      instrument = session.query(Instrument).filter_by(serial_number=serial_number).first()
      if instrument:
          return instrument
      else:
          instrument = Instrument(serial_number)
          session.add(instrument)
          return instrument
  </code></pre>