This is a cheap, hacky, shell wrapper around Brendan Gregg's flame graph generator.
New versions will be updated to PyPI pretty regularly so it should be as easy as:
pip install pyflamegraph
from pyflamegraph import generate
svg = generate(input_source)