dimensionMap = dict(connection.session.query(Dimension.businessKey,
    Dimension.primarySyntheticKey))
buf = []
for row in sheet.allrows():
    dimensionId = dimensionMap[row[0]]
metric = row[1]
buf.append({'dimensionId': dimensionId, 'metric': metric})
if len(buf == 20000):
    connection.session.execute(Fact.__table__.insert(), params=buf)
buf[:] = []
connection.session.execute(Fact.__table__.insert(), params=buf)
sys.stdout.write('All Done')
Very poor weakref performance in Python/SQL Alchemy