def get_bind(obj):
 if hasattr(obj, 'bind'):
  conn = obj.bind
 else:
  try:
   conn = object_session(obj).bind
  except UnmappedInstanceError:
   conn = obj
 if (not hasattr(conn, 'execute')):
  raise TypeError('This method accepts only Session, Engine, Connection and declarative model objects.')
 return conn

def get_bind ( obj ) : if hasattr ( obj , 'bind' ) : conn = obj . bind else : try : conn = object_session ( obj ) . bind except UnmappedInstanceError : conn = obj if ( not hasattr ( conn , 'execute' ) ) : raise TypeError ( 'This method accepts only Session, Engine, Connection and declarative model objects.' ) return conn
return the bind for given sqlalchemy engine / connection / declarative model object .