def get_primary_key(model):
 mapper = model._sa_class_manager.mapper
 pks = [mapper.get_property_by_column(c).key for c in mapper.primary_key]
 if (len(pks) == 1):
  return pks[0]
 elif (len(pks) > 1):
  return tuple(pks)
 else:
  return None

def get_primary_key ( model ) : mapper = model . _sa_class_manager . mapper pks = [ mapper . get_property_by_column ( c ) . key for c in mapper . primary_key ] if ( len ( pks ) == 1 ) : return pks [ 0 ] elif ( len ( pks ) > 1 ) : return tuple ( pks ) else : return None
return primary key name from a model .