moving database actions to python