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

Doug Blank doug.blank at gmail.com
Wed Aug 27 13:25:45 EDT 2014


Great, thanks! That gets me very close to being complete... need to make
sure I get the css to load. (I'm adding a method to dynamically create a
static version of a live, shared notebook in the new multiuser server [1]).

-Doug

[1] - https://github.com/jupyter/jupyterhub


On Wed, Aug 27, 2014 at 12:54 PM, Jacob Vanderplas <
jakevdp at cs.washington.edu> wrote:

> 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:
>     f.write(body)
>
> Hope that helps!
>    Jake
>
>  Jake VanderPlas
>  Director of Research – Physical Sciences
>  eScience Institute, University of Washington
>  http://www.vanderplas.com
>
>
> 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
>>
>>
>
> _______________________________________________
> 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/45684f81/attachment.html>


More information about the IPython-dev mailing list