python route function optimized