Port cask script to Python