Setting nbconvert template in native python?

Hi Community,

I’ve been converting notebooks to html output in native Python, but I couldn’t figure out how to set template.

Is there a way to do so, without having to do an OS call os.system('jupyter nbconvert --execute --to html notebook.ipynb')?

Skeleton code:

import nbformat
from nbconvert.preprocessors import ExecutePreprocessor
from nbconvert import HTMLExporter

# read source notebook
with open('report.ipynb') as f:
    nb = nbformat.read(f, as_version=4)

# execute notebook
ep = ExecutePreprocessor(timeout=-1, kernel_name='python3')
ep.preprocess(nb)

# export to html
html_exporter = HTMLExporter()
html_exporter.exclude_input = True
html_data, resources = html_exporter.from_notebook_node(nb)

# write to output file
with open("notebook.html", "w") as f:
    f.write(html_data)