python api code