conversion of common_sql to python