convert most sql methods to python