Remove duplicate code by using plpydbapi in plpython code