import nbformat as nbf nb = nbf.v4.new_notebook() # Text Cell --------------------------------- text = """\ # My first automatic Jupyter Notebook This is an auto-generated notebook.""" # Code Cell --------------------------------- code = """\ %pylab inline hist(normal(size=2000), bins=50);""" # Create & Save the Notebook ---------------- nb['cells'] = [nbf.v4.new_markdown_cell(text), nbf.v4.new_code_cell(code) ] nbf.write(nb, 'test.ipynb') # You can run this notebook from the command line (if you want): jupyter nbconvert --execute --inplace test.ipynb