title: Is sqlalchemy sessionmaker thread safe?
body: <p>Instead of:</p>
  <pre><code>from sqlalchemy import create_engine
  from sqlalchemy.orm import Session
  
  # an Engine, which the Session will use for connection
  # resources
  engine = create_engine('sqlite:///...')
  
  # create session and add objects
  with Session(engine) as session:
      session.add(some_object)
      session.add(some_other_object)
      session.commit()
  </code></pre>
  <p>I create a sessionmaker (according to example in documentation, see bellow):</p>
  <pre><code>from sqlalchemy import create_engine
  from sqlalchemy.orm import sessionmaker
  
  # an Engine, which the Session will use for connection
  # resources, typically in module scope
  engine = create_engine('postgresql://scott:tiger@localhost/')
  
  # a sessionmaker(), also in the same scope as the engine
  Session = sessionmaker(engine)
  
  # we can now construct a Session() without needing to pass the
  # engine each time
  with Session() as session:
      session.add(some_object)
      session.add(some_other_object)
      session.commit()
  </code></pre>
  <p>Can I use the sessions from session maker in different threads (spawning multiple sessions at the same time)? In other words, is session maker thread safe object? If yes, can multiple sessions exists and read/write into same tables at the same time?</p>
  <p>Furthermore, what is the advantage of of using 'scoped_session' - is it realated to problem of multiple sessions (one per thread)?:</p>
  <pre><code># set up a scoped_session
  from sqlalchemy.orm import scoped_session
  from sqlalchemy.orm import sessionmaker
  
  session_factory = sessionmaker(bind=some_engine)
  Session = scoped_session(session_factory)
  
  # now all calls to Session() will create a thread-local session
  some_session = Session()
  
  # you can now use some_session to run multiple queries, etc.
  # remember to close it when you're finished!
  Session.remove()
  </code></pre>