Skip to content

Instantly share code, notes, and snippets.

@matthew-brett
Created February 20, 2020 17:45
Show Gist options
  • Save matthew-brett/e72736d6d27563db42fb0b20d00d1021 to your computer and use it in GitHub Desktop.
Save matthew-brett/e72736d6d27563db42fb0b20d00d1021 to your computer and use it in GitHub Desktop.
""" Recipe for nbconvert using library
Sets custom output directory, and output prefix.
"""
import nbformat
from traitlets.config import Config
from nbconvert import MarkdownExporter
from nbconvert.writers import FilesWriter
nb = nbformat.read('data_frame_intro.ipynb', 4)
c = Config()
c.FilesWriter.build_directory = "bar"
c.Application.log_level = 'CRITICAL'
exporter = MarkdownExporter(config=c)
out_prefix = 'my_output_base'
resources = {'unique_key': out_prefix}
body, resources = exporter.from_notebook_node(nb, resources=resources)
fw = FilesWriter(config=c)
fw.write(body, resources, notebook_name=out_prefix)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment