Jupiter nbconvert API in Python script

30 views Asked by At

I have some function. It's very simple and it works. But I would like to manage a result and having one not "as is". May be somebody knows parameters to get html without Python's code, just outputs and markups.

def export_to_html(notebook_file) :
    output_format = 'html'
    # Read the notebook file
    with open(notebook_file, encoding='utf-8') as f:
        notebook = nbformat.read(f, as_version=4)
    converted = nbconvert.exporters.export(nbconvert.exporters.HTMLExporter, notebook)
    res_file = 'html/' + notebook_file.replace('.ipynb','.' + output_format)
    # Save the converted output to a file
    with open(res_file, 'w', encoding='utf-8') as f:
        f.write(converted[0])

The most part of information I found is regarding command line and very poor about API.

The question looks like useless - but last several upgrades of Jupyter versions caused an error for conversion to html from command line, at least at my two computers. It is solved by downgrading of some components of Jupyter - that is bad solution in my opinion. The better solution for me is to avoid any mismatches in versions of components and use API.

0

There are 0 answers