Rewrite search command in python