update the python script and refactor API