How to generate a static .html with python

MLguy picture MLguy · Jan 2, 2018 · Viewed 10.7k times · Source

I'm looking for a python solution to create a static .html that can be sent out via email, either attached or embedded in the email (ignore this latter option if it requires a lot more work). I do not have requirements for what regards the layout of the .html. The focus here is in identifying the less painful solution for to generate an offline .html.

A potential solution could be along the lines of the following pseudo-code.

from some_unknown_pkg import StaticHTML

# Initialise instance
newsletter = StaticHTML()

# Append charts, tables and text to blank newsletter.
newsletter.append(text_here)
newsletter.append(interactive_chart_generated_with_plotly)
newsletter.append(more_text_here)
newsletter.append(a_png_file_loaded_from_local_pc)



# Save newsletter to .html, ready to be sent out.
newsletter.save_to_html('newsletter.html')

Where 'newsletter.html' can be opened in a whatever browser. Just to provide a bit more context, this .html is supposed to be sent out to a few selected people inside my company and contains sensible data. I'm using plotly to generate interactive charts to be inserted in the .html.

Answer

Michael picture Michael · Jan 2, 2018

Possible solution here

Seems package in that answer is exactly you want. Docs: http://www.yattag.org/

Another pretty nice package here.