I have reused the code enough to make a package out of it. The python package is deposited at Github. with an example in Jupyter notebook. ⚠️ this gist is out-of-date, please see the diffexpr package for a maintained version of the code