[IPython-dev] What's the easiest way to render an .ipynb file as html?

Jacob Vanderplas jakevdp at cs.washington.edu
Wed Aug 27 12:54:11 EDT 2014

Here's an example of a possible approach:

from IPython.nbformat import current as nbformat
from IPython.nbconvert.exporters import HTMLExporter

input_file = 'notebook.ipynb'
output_file = 'notebook.html'

with open(input_file) as f:
    notebook_content = f.read()

exporter = HTMLExporter(template_file='full')
nb_json = nbformat.reads_json(notebook_content)
(body, resources) = exporter.from_notebook_node(nb_json)

with open(output_file, 'w') as f:

Hope that helps!

 Jake VanderPlas
 Director of Research – Physical Sciences
 eScience Institute, University of Washington

On Wed, Aug 27, 2014 at 9:24 AM, Doug Blank <doug.blank at gmail.com> wrote:

> Short of calling nbviewer, what is the easiest way to render a local
> .ipynb file as html, just like nbviewer does? Would prefer to use the
> IPython libraries directly rather than externally calling ipython, but that
> would work too.
> -Doug
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20140827/967d4539/attachment.html>

More information about the IPython-dev mailing list