How To Write Query In Python