Conversion of common_sql to python