ported partially topogen to python