Refactor Python API to improve structure.